Bug #3302 MyODBC memory leak when mysql_real_connect fails
Submitted: 26 Mar 2004 6:37 Modified: 30 Jul 2004 19:56
Reporter: marcello soffritti Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:3.51.06 OS:HP/UX (HPUX 11.11)
Assigned to: Timothy Smith CPU Architecture:Any

[26 Mar 2004 6:37] marcello soffritti
Description:
I have seen that the file MyODBC-3.51.06/driver/connect.c
suffered of a memory leak when the connection to RDBMS
failed.
With more details, I tried to modify my_SQLDriverConnect in this way:

----------------------------
  if (!mysql_real_connect(&dbc->mysql,KEY_SERVER,
                          KEY_USER,
                          KEY_PASSWORD[0] ? KEY_PASSWORD : NullS,
                          KEY_DB,
                          dbc->port,
                          KEY_SOCKET[0] ? KEY_SOCKET : NullS,
                          (uint) client_flag))
  {
    DBUG_RETURN(set_conn_error(hdbc,MYERR_S1000,
                               mysql_error(&dbc->mysql),
                               mysql_errno(&dbc->mysql)));
  }
----------------------------
changed with:
----------------------------
  if (!mysql_real_connect(&dbc->mysql,KEY_SERVER,
                          KEY_USER,
                          KEY_PASSWORD[0] ? KEY_PASSWORD : NullS,
                          KEY_DB,
                          dbc->port,
                          KEY_SOCKET[0] ? KEY_SOCKET : NullS,
                          (uint) client_flag))
  {
    x_free(KEY_DSN);
    x_free(KEY_DB);
    x_free(KEY_SERVER);
    x_free(KEY_USER);
    x_free(KEY_PASSWORD);
    x_free(KEY_PORT);
    x_free(KEY_SOCKET);
    x_free(KEY_OPTION);
    x_free(KEY_STMT);
    x_free(connstrin);
  
    DBUG_RETURN(set_conn_error(hdbc,MYERR_S1000,
                               mysql_error(&dbc->mysql),
                               mysql_errno(&dbc->mysql)));
  }

...

How to repeat:
See above.
[29 Jun 2004 17:41] Timothy Smith
This is a duplicate of bug #2987:

http://bugs.mysql.com/bug.php?id=2987
[30 Jul 2004 18:06] Timothy Smith
Sorry - now that 2987 is closed, this bug is clearly not the same.  I am opening it back up, and will try to get a clear test case for it.

With apologies,

Timothy
[30 Jul 2004 19:56] Timothy Smith
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

This is now fixed in the latest source code, and will be part of the 3.51.9 release.

Note that this bug was in a non-windows portion of the code, so it does not affect windows platforms.