Bug #49957 Memory Corruption by C connector (libmysqlclient_r.so.16.0.0)
Submitted: 28 Dec 2009 11:49 Modified: 23 Apr 2010 9:15
Reporter: Rajesh Choudhary Email Updates:
Status: No Feedback Impact on me:
Category:Connector / C Severity:S1 (Critical)
Version:5.1.31 OS:Linux (Seems that bug is introduced in new version libmysqlclient_r.so.16.0.0)
Assigned to: CPU Architecture:Any
Tags: MySQL-shared-community-5.1.31-0.rhel5

[28 Dec 2009 11:49] Rajesh Choudhary
My C++ application is using MySQL++ as C++ wrapper which is internally using MySQL client library "libmysqlclient_r.so.16.0.0" as C-wrapper for calling queries and/or Stored-Procedures from application.
My application is using connection-pool (of MySQL++), so it will use same connection many times.

While using a connection, "MYSQL_RES * mysql_store_result(MYSQL *mysql)" API of "libmysqlclient_r.so.16.0.0" library is called to get result. 
It is observed that after this call, value of a member variable (DBDriver::is_connected_) of MySQL++ is changed by itself to "false".

Because of this, connection cannot be used second-time.

When I move back to older version of client library, i.e. "libmysqlclient_r.so.15.0.0", everything was working fine.

How to repeat:
Variables of DBDriver class of MySQL++ are declared as shown under:
class DBDriver
   MYSQL mysql_;
   bool is_connected_;

Declare a variable of type MYSQL (here mysql), and just below it declare some other variable (here is_connected_). Pass pointer of MYSQL variable to mysql_store_result() API. When call is over, value of variable lying just after (in process memory map) MYSQL variable will be changed (here value of is_connected_ will be changed).

Suggested fix:
Seems that bug is introduced in new version libmysqlclient_r.so.16.0.0, as everything is working fine with older version i.e. libmysqlclient.so.15.0.0 (shipped with client rpm : mysql-5.0.22-2.1).
[28 Dec 2009 14:31] Valeriy Kravchuk
Thank you for the problem report. Please, check with libmysqlclient_r.so.* from a newer version, 5.1.41, and inform about the results.
[30 Dec 2009 7:44] Rajesh Choudhary
I have tested application with libmysqlclient_r.so.* from newer version 5.1.41, but problem persists.
[30 Dec 2009 14:29] Godofredo Miguel Solorzano
Could you please provide a test case and run it with Valgrind and show here your results?. Thanks in advance.
[31 Dec 2009 12:38] Rajesh Choudhary
valgrind output for SUCCESSFUL case (libmysqlclient_r.so.15)

Attachment: valgrind_log_lib15.txt (text/plain), 7.17 KiB.

[31 Dec 2009 12:38] Rajesh Choudhary
valgrind output for ERROR case (libmysqlclient_r.so.16)

Attachment: valgrind_log_lib16.txt (text/plain), 8.26 KiB.

[31 Dec 2009 12:39] Rajesh Choudhary
Test Case:
-> Create one connection.
-> Get Connection
-> Call Select Query on a table.
-> Release connection.
-> Get Connection (same connection which was released)
-> Call SP

I run my test case (test file attached : main.cpp) with valgrind 2 times, one for Successful case and second for Error case (no change in source code for both tests, only library is changed from libmysqlclient_r.so.15 to libmysqlclient_r.so.16):

(1). using libmysqlclient_r.so.15 library : SUCCESSFUL case : valgrind output (valgrind_log_lib15.txt) attached.

(2). using libmysqlclient_r.so.16 library : ERROR case : valgrind output (valgrind_log_lib16.txt) attached.

Valgrind ooptions used: --tool=memcheck --leak-check=yes
[1 Feb 2010 9:21] Tonci Grgin
Rajesh, is it possible that you did not recompile your application against libmysql16 but just used the same which you used against libmysql15? Versions 15 and 16 have ABI changes, which might create such problems.
[1 Feb 2010 9:59] Rajesh Choudhary
Hello Tonci,
I have build my application with respective library before testing.
[1 Feb 2010 11:11] Tonci Grgin
Rajesh, comments like this usually means I'm confused and trying to reduce the case info. Following on that, did you consult MySQL++ devs regarding this and what did they say?
[2 Feb 2010 5:23] Rajesh Choudhary
I have raised this problem in this forum only. I havn't approached MySQL++ Devs, as same code is working fine with libmysqlclient-15 but giving issue with libmysqlclient-16 moreover I debug their code and found no issue with it.
[23 Mar 2010 9:15] Valeriy Kravchuk
Please, check with libmysqlclient_r.so.16.0.0 from newer version of MySQL, 5.1.45, and inform about the results.
[23 Apr 2010 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".