memory leak with a very simple program (mysql embedded) - I must be duing something wrong
Posted by: Noam Ambar
Date: December 27, 2005 05:44AM

When I run the program below (mysql_embedded), it causes a memory leak of ~6MB. When I add more iterations to the loop, it consumes the entire machine's memory. valgrind shows that the leak is on mysql_server_init but I assume that this is not true since the leak is increased when I add iterations to the loop. Table T1 is an empty table with one column.

Also when I replace the "SELECT" statement with "UPDATE" statement there is no memory leak so I guess that it is related to the result set but I don't know how.

I get the same results on MySql4 and MySql5.

Any help will be appreciated.

Thanks,

Noam

int main()
{
try
{
string path = "/tmp/testarea";
CMySqlDatabase::startup(path);
mysql_thread_init();

MYSQL* handle = mysql_init(NULL);
mysql_real_connect(handle, NULL, NULL, NULL, "netstar", 0, NULL, 0);
for(int i=0; i<3000; i++)
{
cout << "iteration " << i << endl;
MYSQL_STMT* stmt = mysql_stmt_init(handle);
//char* command = "SELECT 1 FROM T1";
char* command = "UPDATE T1 SET i1 = 1";
mysql_stmt_prepare(stmt, command, strlen(command));
mysql_stmt_execute(stmt);
mysql_stmt_free_result(stmt);
mysql_stmt_close(stmt);
}
mysql_close(handle);

}
catch(CMySqlException e)
{
cout << e.getMessage() << endl;
}
}



valgrind output:

==9484== 6004992 bytes in 2911 blocks are definitely lost in loss record 14 of 16
==9484== at 0x1B904595: malloc (vg_replace_malloc.c:130)
==9484== by 0x806757A: my_malloc (my_malloc.c:35)
==9484== by 0x8061669: init_dynamic_array (in /a/nfs/iil/iec/sws/work/nambar/development/head/common/cpp/mysql/testfeeder)
==9484== by 0x8165A61: _hash_init (in /a/nfs/iil/iec/sws/work/nambar/development/head/common/cpp/mysql/testfeeder)
==9484== by 0x80AFF94: init_max_user_conn() (sql_parse.cc:503)
==9484== by 0x8073AF2: init_embedded_server (mysqld.cc:3115)
==9484== by 0x8056813: mysql_server_init (libmysql.c:162)
==9484== by 0x804D6E8: CMySqlDatabase::startup(std::string&) (CMySqlDatabase.cpp:76)
==9484== by 0x805241E: main (main.cpp:13)

Options: ReplyQuote


Subject
Views
Written By
Posted
memory leak with a very simple program (mysql embedded) - I must be duing something wrong
808
December 27, 2005 05:44AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.