Bug #44703 freeing memory across module boundaries
Submitted: 6 May 2009 18:23 Modified: 7 May 2009 9:13
Reporter: Matthias Brantner Email Updates:
Status: Verified Impact on me:
Category:Connector / C++ Severity:S4 (Feature request)
Version: OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: memory management

[6 May 2009 18:23] Matthias Brantner
I was just browsing the MySQL Connector documentation for C++ (http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-getting-started-examples.html) and realized that using the connector as a (dynamic) library might cause problems. This is due to the fact the memory that is allocated by the MySQL Connector (e.g. sql::mysql::MySQL_Driver::get_mysql_driver_instance() or sql::Connection::connector) is freed by the user.

Taking the example from the website:

sql::mysql::MySQL_Driver *driver;
sql::Connection *con;

driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
con = driver->connect("tcp://", "user", "password");

delete con;

The memory pointed to by the variable con is allocated by the connector and released by the user of the connector. As far as I know, this is not a good practise because freeing memory that is allocated in a different runtime/on a different heap might crash.

Fixing this might also fix the last known issue in Section 21.6.8 (http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-bugs.html): "To avoid potential crashes the build configuration...".

How to repeat:
Build the examples in debug mode on Windows and link against a C standard library that was compiled in release mode (see  Section 21.6.8 of the documentation).

Suggested fix:
Introduce either smart pointers (whose destructors call delete within the library itself) or functions that the user need to call in order to free the memory.
[7 May 2009 9:11] Tonci Grgin
Hi Matthias and thanks for your report.

I agree with your analysis thus setting to verified. Could you just lower the severity to S4 (feature request) if you don't mind as this is a feature request after all.

[7 May 2009 9:13] Matthias Brantner
lowering severity since it's a feature request.
[7 May 2009 15:28] Ulf Wendel
Good feature request. Christian Koch pointed out something similar at http://lists.mysql.com/connector-cplusplus/16 . Let's collect suggestions and see how they may fit into our schedule.