Bug #29247 | Double free in libmysqlclient_r when mysqld restarted | ||
---|---|---|---|
Submitted: | 20 Jun 2007 17:46 | Modified: | 11 Jul 2007 22:37 |
Reporter: | Andrew Agno | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S3 (Non-critical) |
Version: | 5.0.37, 5.0.41, 5.0.46-BK | OS: | Linux (Ubuntu 7.04 64 bit) |
Assigned to: | Alexey Botchkov | CPU Architecture: | Any |
Tags: | FREE, my_no_flags_free, mysql_real_connect, reconnect, segfault, segv |
[20 Jun 2007 17:46]
Andrew Agno
[20 Jun 2007 19:42]
Andrew Agno
This bug also occurs with 5.0.41
[21 Jun 2007 18:38]
Valeriy Kravchuk
Thank you for a bug report. Verified just as described with latest 5.0.46-debug on SuSE Linux 9.3. I've got, eventually, while running your test code and continuosly restarting myslqd: .................... openxs@linux:~/dbs/5.0> *** glibc detected *** double free or corruption (top): 0x08061510 ***
[25 Jun 2007 12:42]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/29500 ChangeSet@1.2496, 2007-06-25 16:40:29+05:00, holyfoot@mysql.com +1 -0 Bug #29247 Double free in libmysqlclient_r when mysql restarted. If one sets MYSQL_READ_DEFAULTS_FILE and MYSQL_READ_DEFAULT_GROUP options after mysql_real_connect() called with that MYSQL instance, these options will affect next mysql_reconnect then. As we use a copy of the original MYSQL object inside mysql_reconnect, and mysql_real_connect frees options.my_cnf_file and _group strings, we will free these twice when we execute mysql_reconnect with the same MYSQL for the second time. I don't think we should ever read defaults files handling mysql_reconnect. So i just set them to 0 for the temporary MYSQL object there/
[25 Jun 2007 12:50]
Alexey Botchkov
I should note that manual says we should call mysql_options() before the mysql_real_connect(). http://dev.mysql.com/doc/refman/5.1/en/mysql-options.html And the reported problem appears as Andrew does it in opposite order in his example.
[25 Jun 2007 17:54]
Andrew Agno
Yes, moving around the order of calls also fixes this. We had the order reversed because it didn't work for some older version of mysqlclient (see: http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html) and the comment stating: ' Even though the documentation says that you should call mysql_options before mysql_real_connect, when setting MYSQL_OPT_RECONNECT you MUST do so after the connection has been successfully established. This is true as late as 5.0.16. '
[1 Jul 2007 19:57]
Bugs System
Pushed into 5.1.21-beta
[1 Jul 2007 20:02]
Bugs System
Pushed into 5.0.46
[11 Jul 2007 22:37]
Paul DuBois
Noted in 5.0.46, 5.1.21 changelogs. Calling mysql_options() after mysql_real_connect() could cause clients to crash. Also updated the mysql_options() pages to mention the problem of mysql_real_connect() resetting auto-reconnect behavior prior to MySQL 5.0.19/5.1.6.