lt_dlerror may cause potential issue in multi-thread environment
xiaonan <[email protected]> Fri, 12 Apr 2013 09:40:09 +0800 (CST)
| Newsgroups | gmane.comp.db.unixodbc.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, Nick:
Because lt_dlerror() function is not thread-safe, in the following code:
if ( !(connection -> dl_handle = odbc_dlopen( driver_lib )))
{
char txt[ 2048 ];
sprintf( txt, "Can't open lib '%s' : %s",
driver_lib, lt_dlerror());
......
return 0;
}
In multi-thread environment, the lt_dlerror() may return other thread's error, or even NULL.
In your latest modification:
if ( !(connection -> dl_handle = odbc_dlopen( driver_lib )))
{
char txt[ 2048 ];
const char *err;
err = lt_dlerror();
sprintf( txt, "Can't open lib '%s' : %s",
driver_lib, err ? err : "NULL ERROR RETURN" );
......
return 0;
}
This issue still exits.
Personally, I think the function of odbc_dlopen() can be modified as this:
static void *odbc_dlopen( char *libname, char *err );
{
......
hand = lt_dlopen( libname );
if (hand)
{
}
else
{
sprintf(err, "%s", lt_dlerror());
}
}
So if there is a error, the error can be returned correctly:
char txt[ 2048 ];
char err[2048]
if ( !(connection -> dl_handle = odbc_dlopen( driver_lib, err)))
{
sprintf( txt, "Can't open lib '%s' : %s",
driver_lib, err);
......
return 0;
}
Could you help to check it? Thanks very much!
Best Regards
Nan Xiao
_______________________________________________
unixODBC-dev mailing list
[email protected]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev