atexit(mysql_library_end) is never called
Discovered through a compile warning that says:
static bool isc::db::MySqlHolder::<lambda()>::_FUN()’ will never be NULL
for this line:
bool MySqlHolder::atexit_ = []{atexit([]{mysql_library_end();});return true;};
What it's saying is that the address of the lambda is always different than zero. Which gets casted to a true when assigned to atexit_
. That's not the concerning part. To the best of my understanding, the lambda never gets called here. And so atexit()
is never called. And so mysql_library_end()
never gets called. Quote from the MySQL docs:
To avoid memory leaks after the application is done using the library (for example, after closing the connection to the server), be sure to call mysql_library_end() explicitly. This enables memory managment to be performed to clean up and free resources used by the library.
So this could be a socket leak? If I remember, unclosed sockets outlive the process.
Compiler is g++11, but I remember getting it in previous versions also. Flags are -Wall -Wextra
, but they might not be required.