Description:
Currently, in order to free up all allocations done by libmysqlclient, you'll have to manually call mysql_library_end(), but if libmysqlclient is for some reason unloaded, the memory never gets freed.
In the Windows-version I've noticed that DllMain has been used to actually enforce a call to my_end() when the library is finally unloaded. The same could be done for at least Linux when compiled with gcc. (Looks like this has been removed from MySQL 5.5?)
The place where I found the "hack" useful is when using libpam-mysql with an application. Should libpam-mysql call mysql_library_end() when it is unloaded? The host application doesn't know whether using PAM will eventually use MySQL, nor does the library know if the application used MySQL. If libpam-mysql calls mysql_library_end() on unload, it potentially frees up resources necessary for the application, but if it doesn't and the application did not use MySQL, a memory leak occurs because PAM will load and unload libpam-mysql each time PAM is used.
How to repeat:
Load and unload a module which uses MySQL, but doesn't call mysql_library_end
Suggested fix:
Add something like to a unix.c or similar under libmysql
#if defined(__GNUC__) && !defined(WINDOWS) && !defined(__WIN__)
__attribute__((destructor)) void libmysql_free(void)
{
my_end(0);
}
#endif
Description: Currently, in order to free up all allocations done by libmysqlclient, you'll have to manually call mysql_library_end(), but if libmysqlclient is for some reason unloaded, the memory never gets freed. In the Windows-version I've noticed that DllMain has been used to actually enforce a call to my_end() when the library is finally unloaded. The same could be done for at least Linux when compiled with gcc. (Looks like this has been removed from MySQL 5.5?) The place where I found the "hack" useful is when using libpam-mysql with an application. Should libpam-mysql call mysql_library_end() when it is unloaded? The host application doesn't know whether using PAM will eventually use MySQL, nor does the library know if the application used MySQL. If libpam-mysql calls mysql_library_end() on unload, it potentially frees up resources necessary for the application, but if it doesn't and the application did not use MySQL, a memory leak occurs because PAM will load and unload libpam-mysql each time PAM is used. How to repeat: Load and unload a module which uses MySQL, but doesn't call mysql_library_end Suggested fix: Add something like to a unix.c or similar under libmysql #if defined(__GNUC__) && !defined(WINDOWS) && !defined(__WIN__) __attribute__((destructor)) void libmysql_free(void) { my_end(0); } #endif