List:MySQL++« Previous MessageNext Message »
From:Kun Niu Date:June 2 2007 7:22am
Subject:Possible memory leak of mysql++?
View as plain text  
Dear maintainer,
I've been testing mysql++ on my Debian system.
My libmysql++-dev is version 2.0.7-3.
My mysql server is version 5.0.38-1..
My g++ is version 4.1.2-5.
The following is my test program.

#include <mysql++/mysql++.h>
#include <string>
#include <iostream>

using namespace std;

using namespace mysqlpp;

void test_result( const Result &result )
{
  //Result temp_result( result );
  Row row;
  Row::size_type i;
  for( i = 0; row = result.at(i); i++ )
  {
    cout<<row.at(0)<<endl;
  }
}

string database = "perldbi";
string host = "localhost";
string username = "niu";
string password = "haoniukun";

int main()
{
  Connection con(false);
  con.connect( database.c_str(), host.c_str(), username.c_str(),
password.c_str() );
  Query query = con.query();
  query<<"select name from perltable where name='kun'";
  Result res = query.store();
  Result &rres = res;
  if(query)
    test_result( res );
  return 0;
}

And the following is valgrind output.

niu@shuang:~/src/c++$ valgrind --leak-check=full --show-reachable=yes ./Mysql
==26905== Memcheck, a memory error detector.
==26905== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==26905== Using LibVEX rev 1732, a library for dynamic binary translation.
==26905== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==26905== Using valgrind-3.2.3-Debian, a dynamic binary
instrumentation framework.
==26905== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==26905== For more details, rerun with: -v
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016413: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401641E: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016429: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016434: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016413: (within /lib/ld-2.5.so)
==26905==    by 0x40121D4: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401641E: (within /lib/ld-2.5.so)
==26905==    by 0x40121D4: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016429: (within /lib/ld-2.5.so)
==26905==    by 0x40121D4: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016434: (within /lib/ld-2.5.so)
==26905==    by 0x40121D4: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x4016551: (within /lib/ld-2.5.so)
==26905==    by 0x40121D4: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401655C: (within /lib/ld-2.5.so)
==26905==    by 0x40121D4: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Invalid read of size 4
==26905==    at 0x4016519: (within /lib/ld-2.5.so)
==26905==    by 0x4006009: (within /lib/ld-2.5.so)
==26905==    by 0x40084F5: (within /lib/ld-2.5.so)
==26905==    by 0x400C616: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x400CBDA: (within /lib/ld-2.5.so)
==26905==    by 0x4012234: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==  Address 0x4524F54 is 20 bytes inside a block of size 23 alloc'd
==26905==    at 0x40234B0: malloc (vg_replace_malloc.c:149)
==26905==    by 0x4008AF3: (within /lib/ld-2.5.so)
==26905==    by 0x400C616: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x400CBDA: (within /lib/ld-2.5.so)
==26905==    by 0x4012234: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x400B3CC: (within /lib/ld-2.5.so)
==26905==    by 0x401230B: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x400B0CA: (within /lib/ld-2.5.so)
==26905==    by 0x401230B: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x444F8EF: (within /lib/libc-2.5.so)
==26905==    by 0x4451425: (within /lib/libc-2.5.so)
==26905==    by 0x4457498: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401636E: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x4450102: __nss_next (in /lib/libc-2.5.so)
==26905==    by 0x445741A: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B16CD: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401637D: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x4450102: __nss_next (in /lib/libc-2.5.so)
==26905==    by 0x445741A: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B16CD: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401638C: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x4450102: __nss_next (in /lib/libc-2.5.so)
==26905==    by 0x445741A: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B16CD: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
==26905==
==26905== Conditional jump or move depends on uninitialised value(s)
==26905==    at 0x401639B: (within /lib/ld-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x4011C5D: (within /lib/ld-2.5.so)
==26905==    by 0x4474631: (within /lib/libc-2.5.so)
==26905==    by 0x400E255: (within /lib/ld-2.5.so)
==26905==    by 0x44747E4: __libc_dlopen_mode (in /lib/libc-2.5.so)
==26905==    by 0x444F7EB: __nss_lookup_function (in /lib/libc-2.5.so)
==26905==    by 0x4450102: __nss_next (in /lib/libc-2.5.so)
==26905==    by 0x445741A: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==    by 0x408BA71: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B16CD: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
牛坤
==26905==
==26905== ERROR SUMMARY: 22 errors from 17 contexts (suppressed: 31 from 1)
==26905== malloc/free: in use at exit: 61,362 bytes in 17 blocks.
==26905== malloc/free: 157 allocs, 140 frees, 139,613 bytes allocated.
==26905== For counts of detected errors, rerun with: -v
==26905== searching for pointers to 17 not-freed blocks.
==26905== checked 666,768 bytes.
==26905==
==26905==
==26905== 16 bytes in 1 blocks are still reachable in loss record 1 of 3
==26905==    at 0x40234B0: malloc (vg_replace_malloc.c:149)
==26905==    by 0x408D15D: my_malloc (in /usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x408DE5E: my_error_register (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x408CE01: init_client_errs (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x408BA08: mysql_server_init (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B16CD: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x4236515: mysqlpp::Connection::Connection(bool) (in
/usr/lib/libmysqlpp.so.2.0.7)
==26905==    by 0x804A60E: main (Mysql.cpp:27)
==26905==
==26905==
==26905== 26 bytes in 1 blocks are definitely lost in loss record 2 of 3
==26905==    at 0x40234B0: malloc (vg_replace_malloc.c:149)
==26905==    by 0x46F46DF: ???
==26905==    by 0x46F4AA6: ???
==26905==    by 0x46CD81C: ???
==26905==    by 0x46C7564: ???
==26905==    by 0x46C7B32: ???
==26905==    by 0x462672D: ???
==26905==    by 0x4626817: ???
==26905==    by 0x4625F95: ???
==26905==    by 0x46261D4: ???
==26905==    by 0x44573DD: getservbyname_r (in /lib/libc-2.5.so)
==26905==    by 0x4457284: getservbyname (in /lib/libc-2.5.so)
==26905==
==26905==
==26905== 61,320 bytes in 15 blocks are still reachable in loss record 3 of 3
==26905==    at 0x40234B0: malloc (vg_replace_malloc.c:149)
==26905==    by 0x4093DF5: my_once_alloc (in /usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x409455B: (within /usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x4094F81: (within /usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40951E8: get_charset_by_csname (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B14CC: mysql_init_character_set (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x40B35CC: mysql_real_connect (in
/usr/lib/libmysqlclient.so.15.0.0)
==26905==    by 0x42383BD: mysqlpp::Connection::connect(char const*,
char const*, char const*, char const*, unsigned, char, unsigned, char
const*, unsigned) (in /usr/lib/libmysqlpp.so.2.0.7)
==26905==    by 0x804A6A8: main (Mysql.cpp:28)
==26905==
==26905== LEAK SUMMARY:
==26905==    definitely lost: 26 bytes in 1 blocks.
==26905==      possibly lost: 0 bytes in 0 blocks.
==26905==    still reachable: 61,336 bytes in 16 blocks.
==26905==         suppressed: 0 bytes in 0 blocks.

It seems that the main problem comes from getservname_r.
I wonder if it's a serious issue.
Since the memory leak in each connection is really tiny, it really
hard to find it out without long run testing.

Looking forward to further information.
Thank you for your attention.
-- 
         牛坤
Thread
Possible memory leak of mysql++?Kun Niu2 Jun
  • Re: Possible memory leak of mysql++?Warren Young4 Jun
    • Re: Possible memory leak of mysql++?Niu Kun10 Jun
      • Re: Possible memory leak of mysql++?Warren Young12 Jun
        • Re: Possible memory leak of mysql++?Niu Kun12 Jun