[CONC-117] Memory leak while reconnecting to server Created: 2014-12-20 Updated: 2016-02-29 Resolved: 2014-12-21 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 2.0.0 |
| Fix Version/s: | 2.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Tianhong | Assignee: | Georg Richter |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Linux 32/64 bit |
||
| Attachments: |
|
| Description |
|
Hi, 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 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,..... ) And it seems to work well without memory leak any more. Thanks and best wish |
| Comments |
| Comment by Georg Richter [ 2014-12-20 ] |
|
Thanks for your bug report. Verified - the leak also exists in servers (GPL licensed) client library. |
| Comment by Tianhong [ 2014-12-21 ] |
|
Hi Georg, Thanks for your reply. As you said, I've tried the same test code with the c client library from MySQL-5.6.20 and didn't find any leak. The memory usage looks quite normal. |
| Comment by Georg Richter [ 2014-12-21 ] |
|
Fixed in rev. 185 |
| Comment by Tianhong [ 2014-12-21 ] |
|
Hi Georg, thanks for your work and support. Today I reviewed the code and thought that there are also a few bugs in function "mysql_reconnect" I wrote the patch with some comment. static my_bool mysql_reconnect(MYSQL *mysql) if (!mysql->reconnect || mysql_init(&tmp_mysql); /* don't reread options from configuration files */ /* make sure that we reconnect with the same character set */ tmp_mysql.reconnect= mysql->reconnect; /* reset the connection in all active statements if (stmt->state != MYSQL_STMT_INITTED) { stmt->mysql= NULL; stmt->state= MYSQL_STMT_INITTED; SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); } else //------------- |