11 messages in com.mysql.lists.bugsMemory leak in client-library's mysql...
FromSent OnAttachments
Mikko Noromaa09 May 2002 10:54 
Sinisa Milivojevic10 May 2002 05:16 
Mikko Noromaa10 May 2002 07:22 
Sinisa Milivojevic10 May 2002 09:08 
Mikko Noromaa10 May 2002 09:51 
Sinisa Milivojevic10 May 2002 09:57 
Sinisa Milivojevic10 May 2002 10:08 
Venu10 May 2002 15:11 
Mikko Noromaa11 May 2002 08:06 
Michael Widenius15 May 2002 01:11 
Michael Widenius15 May 2002 01:45 
Subject:Memory leak in client-library's mysql_init() and mysql_real_connect()
From:Mikko Noromaa (mik@nm-sol.com)
Date:05/09/2002 10:54:35 AM
List:com.mysql.lists.bugs

Description:

I have created the simplest possible Mysql client in C with the Mysql C API. The program connects to a local Mysql server and immediately disconnects from it. This sequence causes a small memory leak, as reported by Microsoft debug CRT's _CrtDumpMemoryLeaks() function.

The test program is built with Microsoft Visual C++ as a debug version (using "Debug Multithreaded" run-time library). The test program is included at the end of this description.

_CrtDumpMemoryLeaks() checks which objects allocated during the lifetime of a program are not freed at the time _CrtDumpMemoryLeaks() is called. It outputs the following:

374: Detected memory leaks! 374: Dumping objects -> 374: {50} normal block at 0x008F0100, 64 bytes long. 374: Data: <...................> CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 374: {39} normal block at 0x008F02E0, 60 bytes long. 374: Data: <...................> 02 00 00 00 00 00 00 00 5C 00 00 00 B0 7D FA 77 374: Object dump complete.

The first block (50) is allocated by the mysql_init() call and the second block (39) is allocated by the mysql_real_connect() function. I assume they should be freed by the clean-up function mysql_close(), but they aren't.

I know this is marginal problem as the leaks probably occur only once during the lifetime of a program. However, I have some leak-detection code included in my program, and the leaks by Mysql C API cause the detection code to trigger an alarm every time.

The test program follows:

#include <windows.h> #include <stdio.h> #include <mysql.h>

int main() { MYSQL *myData;

if (!(myData = mysql_init((MYSQL*) 0))) { printf ("mysql_init() failed.\n"); }

if (!mysql_real_connect( myData, NULL, NULL, NULL, NULL, MYSQL_PORT, NULL, 0 ) ) { printf( "Can't connect to the mysql server.\n"); }

mysql_close (myData);

_CrtDumpMemoryLeaks();

return (0); }

How-To-Repeat: See above.

Fix:

Exectutable: mysqld-nt Environment: Pentium 400 MHz, 384 MB RAM, 1 GB free HD System: NT Compiler: VC++ 6.0 Architecture: i