| Bug #3073 | mysql_stmt_close leaks memory if called after mysql_close | ||
|---|---|---|---|
| Submitted: | 5 Mar 2004 3:58 | Modified: | 17 Mar 2004 8:30 | 
| Reporter: | Konstantin Osipov (OCA) | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server | Severity: | S2 (Serious) | 
| Version: | 4.1 | OS: | Any (all) | 
| Assigned to: | Konstantin Osipov | CPU Architecture: | Any | 
   [17 Mar 2004 8:30]
   Konstantin Osipov        
  Fixed in latest 4.1.2 tree: bk commit - 4.1 tree (konstantin:1.1781)

Description: In case mysql_stmt_close was called after mysql_close works this branch of mysql_stmt_close: if (!(mysql= stmt->mysql)) { if (!skip_free) my_free((gptr) stmt, MYF(MY_WME)); DBUG_RETURN(0); } which just frees memory of the statement itself, and does not free stmt->mem_root and stmt->query. How to repeat: Write any testcase with mysql_close before mysql_stmt_close and run it under valgrind. Suggested fix: - remove skip_free from mysql_stmt_close. - from mysql_close() just walk through all open statements and set stmt->mysql= 0 We don't need to call server to close statement entity on server side, because it's done automatically when connection is closed. - rewrite branch with simple_command() in mysql_stmt_close() to work only if stmt->mysql is not zero. - make sure all cleanups are done whether connection is alive or not.