Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL C API: Init, connect and close memory leak

Status
Not open for further replies.

Sen7inel

IS-IT--Management
Feb 14, 2001
90
FI
MySQL 4.0.17, Visual C++ .NET & compiling against mysqlclient.lib

Quick n dirty:

MYSQL sql;
mysql_init(&sql);
mysql_real_connect(&sql, ..);
mysql_close(&sql);

This causes a memory leak (with or without mysql_thread_end).. Any ideas, workarounds or fixes?

Also see which is pretty much the same.
 
You need to check the return from the init.
If the value passed to connect is NULL, then it will fail.

11.1.3.31 mysql_init()

MYSQL *mysql_init(MYSQL *mysql)

Description
Allocates or initializes a MYSQL object suitable for mysql_real_connect(). If mysql is a NULL pointer, the function allocates, initializes, and returns a new object. Otherwise, the object is initialized and the address of the object is returned. If mysql_init() allocates a new object, it will be freed when mysql_close() is called to close the connection.

Return Values
An initialized MYSQL* handle. NULL if there was insufficient memory to allocate a new object.

Errors
In case of insufficient memory, NULL is returned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top