Bug #47655 Memory free error when connecting to 4.1 server from 5.1+ client
Submitted: 25 Sep 2009 23:17 Modified: 12 Mar 2010 17:20
Reporter: Paul DuBois Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.x and higher OS:Any
Assigned to: Tatiana Azundris Nuernberg CPU Architecture:Any
Tags: regression

[25 Sep 2009 23:17] Paul DuBois
Description:
Connecting to a 4.1.x server from a 4.1.x or 5.0.x mysql client
causes no problems when disconnecting.

Connecting to a 4.1.x server from a 5.1.x or higher mysql client
results in a memory-free error when disconnecting. This is
true for mysql-5.1 (5.1.39), mysql-trunk (5.4.5) and mysql-6.0-codebase
(6.0.14).

The following examples demonstrate this. The pathnames of the mysql 
client indicate the version number of the MySQL installation from which
the client comes. The -P40126 indicates that the client is connecting
to a 4.1.26 server listening on port 40126.

% /var/mysql/40126/bin/mysql -P40126
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 4.1.26-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> quit
Bye

% /var/mysql/50087/bin/mysql -P40126
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 4.1.26-log

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

% /var/mysql/50139/bin/mysql -P40126
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 4.1.26-log

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye
Error: Freeing unallocated data at line 1248, 'mysql.cc'

% /var/mysql/50405/bin/mysql -P40126
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 4.1.26-log

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye
Error: Freeing unallocated data at line 1248, 'mysql.cc'

% /var/mysql/60014/bin/mysql -P40126
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 4.1.26-log

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye
Error: Freeing unallocated data at line 1265, 'mysql.cc'

How to repeat:
See above.
[25 Sep 2009 23:33] Peter Laursen
It would be very nice to know if also the C-API/libmysql is affected! Do you happen to know?
[25 Sep 2009 23:56] Paul DuBois
Peter, I don't know.  The line number in the error message indicates that the problem occurs trying to free server_version in mysql_end():

sig_handler mysql_end(int sig)
{
  mysql_close(&mysql);

  ...

  my_free(server_version,MYF(MY_ALLOW_ZERO_PTR));

  ...
}
[26 Sep 2009 8:59] Valeriy Kravchuk
Thank you for the bug report. Verified just as described with recent 5.1.40 from bzr on Mac OS X:

valeriy-kravchuks-macbook-pro:5.1 openxs$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 4.1.25-pro-gpl

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> exit
Bye
Error: Freeing unallocated data at line 1248, 'mysql.cc'
valeriy-kravchuks-macbook-pro:5.1 openxs$ bin/mysql --version
bin/mysql  Ver 14.14 Distrib 5.1.40, for apple-darwin9.6.0 (i386) using readline 5.1
[2 Nov 2009 8:46] 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/88890

3158 Tatiana A. Nurnberg	2009-11-02
      Bug#47655: Memory free error when connecting to 4.1 server from 5.1+ client
      
      When starting the (5.1+) mysql command-line client, we try to get
      "select @@version_comment" from the server to present it to the
      user. Recent clients are aware that older servers do not have that
      variable and fall back on other info to be able to present *something*
      at least. This fallback string was allocated through the POSIX interface,
      but released through the my*() suite, which rightfully complained about
      the imbalance in calls when compiled with --debug. While this wasn't
      as bad as it looked (no double-free, use of uninitialized or freed
      buffer, etc.), it did look funky.
      
      Using my_strdup() now for what will be my_free()d later.
     @ client/mysql.cc
        Use my_strdup() for server_version, as we'll my_free() it later
        and don't want to upset the mysql client's memory accounting.
[24 Nov 2009 17:44] Tatiana Azundris Nuernberg
queued for 6.0.14 / 5.1.42 in -bugteam
[2 Dec 2009 8:03] Bugs System
Pushed into 5.1.42 (revid:joro@sun.com-20091202080033-mndu4sxwx19lz2zs) (version source revid:davi.arnaut@sun.com-20091125130912-d7hrln14ef7y5d7i) (merge vers: 5.1.42) (pib:13)
[10 Dec 2009 2:23] Paul DuBois
Noted in 5.1.42 changelog.

Connecting to a 4.1.x server from a 5.1.x or higher mysql client
resulted in a memory-free error when disconnecting.

Setting report to NDI pending push to 5.5.x+.
[16 Dec 2009 8:37] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091216083311-xorsasf5kopjxshf) (version source revid:alik@sun.com-20091214191830-wznm8245ku8xo702) (merge vers: 6.0.14-alpha) (pib:14)
[16 Dec 2009 8:44] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091216082430-s0gtzibcgkv4pqul) (version source revid:alexey.kopytov@sun.com-20091126114659-f3imubfuye9fn7qp) (merge vers: 5.5.0-beta) (pib:14)
[16 Dec 2009 8:50] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20091216083231-rp8ecpnvkkbhtb27) (version source revid:alik@sun.com-20091212203859-fx4rx5uab47wwuzd) (merge vers: 5.6.0-beta) (pib:14)
[18 Dec 2009 1:43] Paul DuBois
Noted in 5.5.1, 6.0.14 changelogs.
[12 Mar 2010 14:10] Bugs System
Pushed into 5.1.44-ndb-7.0.14 (revid:jonas@mysql.com-20100312135944-t0z8s1da2orvl66x) (version source revid:jonas@mysql.com-20100312115609-woou0te4a6s4ae9y) (merge vers: 5.1.44-ndb-7.0.14) (pib:16)
[12 Mar 2010 14:26] Bugs System
Pushed into 5.1.44-ndb-6.2.19 (revid:jonas@mysql.com-20100312134846-tuqhd9w3tv4xgl3d) (version source revid:jonas@mysql.com-20100312060623-mx6407w2vx76h3by) (merge vers: 5.1.44-ndb-6.2.19) (pib:16)
[12 Mar 2010 14:40] Bugs System
Pushed into 5.1.44-ndb-6.3.33 (revid:jonas@mysql.com-20100312135724-xcw8vw2lu3mijrhn) (version source revid:jonas@mysql.com-20100312103652-snkltsd197l7q2yg) (merge vers: 5.1.44-ndb-6.3.33) (pib:16)