memory-leak is detected when the server is off and the client keeps reconnecting to it. Here is test code with steps how you can repeat the bug:
Step 1. Build the test code
Step 2. Start MySQL/Mariadb server
Step 3. Execute the test binary (in terminal or valgrind), and it would keep printing "Query OK"..
Step 4. Shut down MySQL/Mariadb server. And the client would keep printing "Query error..."
Step 5. Watch the memory usage of the test binary, and it would keep raising.
After debugging for a while, I thought the bug locates in function "mysql_reconnect" in file "libmariadb.c" around line 1992.
The original logic is to let a tmp_client to rebuild a new connection which has to allocate some structures such as hash_table for keeping the mysql_options. But when it fails to reconnect, the destructor "mysql_close" should be called in order to free the allocated memory. And it seems someone has fogot this point.
So after line 1992: my_set_error(mysql,..... )
I added this line as a test patch:
And it seems to work well without memory leak any more.
But I'm not 100% sure of it and looking forward for your response.
Thanks and best wish