[unixODBC-dev] Right way to read odbc.ini file.

Martin J. Evans martin at easysoft.com
Fri Sep 10 13:55:45 BST 2004

On 10-Sep-2004 ZIGLIO, Frediano, VF-IT wrote:
>> On 10-Sep-2004 ZIGLIO, Frediano, VF-IT wrote:
>> > In our driver (FreeTDS ODBC driver) in SQLConnect we read 
>> odbc.ini using
>> > SQLGetPrivateProfileString from libodbcinst.so. However I noted that
>> > this lead to some leaks due to ini cache. SQLGetPrivateProfileString
>> > it's also compiled in libodbc.so but it's not exported. 
>> This lead to two
>> > different caches (but I don't think it's a problem). The 
>> real issue it's
>> > that when our driver get unloaded (unixODBC calls lt_dlclose)
>> > libodbcinst.so get unloaded but cache it's not freed... Perhaps you
>> > should use atexit to free the cache at so unload ??
>> Just a quick one - atexit won't help. Memory is freed 
>> automatically on program
>> termination since the process dies. atexit won't help in a scenario
>> SQLConnect/SQLDiconnect SQLConnect/SQLDisconnect. Anyway, the 
>> cache is a cache
>> of the ini file and has nothing to do with the driver but as 
>> you say if FreeTDS
>> loads libodbcinst, calls SQLGetPrivateProfileString and then 
>> unloads libodbcinst
>> its possible a ptr to the cache is lost and hence leaking.
>> Some platforms support __init and __fini functions in shared 
>> objects precisely
>> for doing this sort of thing but unfortunately, they all tend 
>> to be a little
>> different and in any case it is only a few platforms.
> I did a test in Linux and using atexit in dynamic library call my
> function when I call dlclose. 

I didn't know that and the documentation I have does not suggest atexit works
with dlclose(3).

> dlopen(3) under Linux tell that you can
> use __attribute__((destructor)) to get a function called when you call
> dlclose. However I don't think it's a so portable behaviour

Its not.

> ... either
> _fini, __attribute__((destructor)) or atexit... I think a configure test
> it's required.

I could be wrong and Nick might remember but I think DontDLClose attribute was
invented because of some drivers use of atexit or _fini - Nick?
<snipped test code>

Your test code:

1. does not compile with my gcc (use of void *so declaration in the middle of

2. does not produce the same result as you got:

calling alloc
calling free
close so
# notice no free_waste here

3. segfaults in 

Program received signal SIGSEGV, Segmentation fault.
free_waste () at so.c:7
7       {

2 & 3 don't surprise me.

Martin J. Evans
Easysoft Ltd, UK

More information about the unixODBC-dev mailing list