>Description:
I use a little subset of mysql++ capabilities
- Connection
- Query ( only Query::store )
- Result
Memory leak I discovered is located somewhere in Result::operator= and is
available only after update;
Proof of concept code is supplied.
It leaks 1 Mb of memory in 10 seconds executing about 12000 updates
I use Intel celeron 333, 2.4.18 linux kernel on late slackware distibution.
MySQL++ 1.7.9 built from source, no __USLC__ conditional defined
>How-To-Repeat:
#include <iostream>
#include <mysql++>
using namespace std;
#define DBNAME "test"
#define DBHOST "localhost"
#define DBUSER "root"
#define DBPW ""
const string dbname(DBNAME);
const string dbhost(DBHOST);
const string dbuser(DBUSER);
const string dbpw(DBPW);
#define dlog cerr
Connection* con=0;
Result res;
//Result *res=0;
void sql(const char* q)
{
// dlog << "[ DB ] Query sent: " << q << endl;
try {
Query query = con->query();
// Use of dynamically allocated and manually cleaned Result
// will eliminate memory leak
// if(res) delete res;
// res=new Result();
// *res=query.store(q);
// MEMORY LEAK
res=query.store(q);
}
catch(BadQuery &e)
{
dlog << "[ DB ] MySQLLow -- BadQuery: " << e.error << endl;
throw;
}
catch(exception& e)
{
dlog << "[ DB ] MySQLLow -- exception: " << e.what() << endl;
throw;
}
catch(...)
{
dlog << "[ DB ] MySQLLow -- exception: ?" << endl;
throw;
}
}
void connect(void)
{
dlog << "[ DB ] Connecting to database: " << dbname << endl;
try {
con=new Connection(use_exceptions);
con->connect("",dbhost.c_str(),dbuser.c_str(),dbpw.c_str());
try {
con->select_db(dbname);
} catch (BadQuery &er) {
con->create_db(dbname.c_str());
con->select_db(dbname.c_str());
}
}
catch(BadQuery &e)
{
dlog << "MySQLLow -- BadQuery: " << e.error << endl;
throw;
}
catch(exception& e)
{
dlog << "MySQLLow -- exception: " << e.what() << endl;
throw;
}
}
int main(void)
{
connect();
int i=0;
while(true)
{
sql("SELECT * FROM a");
// comment out this line to eliminate memory leak
sql("UPDATE a SET i=i+1");
dlog << '.';
}
}
>Fix:
Workaround:
Recreating Result object each query elminates this problem.
But we still hope on MySQL++ development team, aint we =?
>Submitter-Id: <submitter ID>
>Originator:
>Organization:
>MySQL support: none
>Synopsis: mysql++ memory leak
>Severity: serious
>Priority: high
>Category: mysql
>Class: sw-bug
>Release: mysql-3.23.39 (Source distribution)
>Server: /usr/bin/mysqladmin Ver 8.21 Distrib 3.23.39, for slackware-linux-gnu on i386
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 3.23.39-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysql/mysql.sock
Uptime: 2 days 21 hours 27 min 45 sec
Threads: 11 Questions: 2375042 Slow queries: 2 Opens: 195656 Flush tables: 1 Open
tables: 4 Queries per second avg: 9.498
>Environment:
System: Linux kerzum 2.4.18 #4 SMP Sun Oct 13 19:50:52 MSD 2002 i686 unknown
Architecture: i686
Some paths: /usr/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc /usr/bin/cc
GCC: Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/specs
gcc version 2.95.3 20010315 (release)
Compilation info: CC='gcc' CFLAGS='' CXX='c++' CXXFLAGS='' LDFLAGS=''
LIBC:
lrwxrwxrwx 1 root root 13 Oct 13 20:28 /lib/libc.so.6 -> libc-2.2.3.so
-rwxr-xr-x 1 root root 4783716 May 26 2001 /lib/libc-2.2.3.so
-rw-r--r-- 1 root root 24721042 May 26 2001 /usr/lib/libc.a
-rw-r--r-- 1 root root 178 May 26 2001 /usr/lib/libc.so
Configure command: ./configure --prefix=/usr --with-mysqld-user=mysql
--with-unix-socket-path=/var/run/mysql/mysql.sock --localstatedir=/var/lib/mysql
--with-pthread --enable-thread-safe-client --enable-assembler --with-raid
--with-libwrap --without-bench i386-slackware-linux
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php