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

Martin J. Evans martin at easysoft.com
Fri Sep 10 11:27:30 BST 2004

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.

Martin J. Evans
Easysoft Ltd, UK

More information about the unixODBC-dev mailing list