List:MySQL++« Previous MessageNext Message »
From:Bruno Adami Date:May 10 2009 10:05pm
Subject:Possible memory leak?
View as plain text  
Hello :)

Its my first time subscribing to a list, I dont know if I need to send to this email, but
it is a try :)

Mysqlpp is a great wrapper for MySQL C Api, it makes our lifes easyer, I mean it, thank
you!

I was playing with some examples and I used valgrind to check for memory leaks on my
program:

valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./Test

And I got the following output:

==21941== Memcheck, a memory error detector.
==21941== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==21941== Using LibVEX rev 1884, a library for dynamic binary translation.
==21941== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==21941== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==21941== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==21941== For more details, rerun with: -v
==21941==
Check1
==21941== Invalid read of size 4
==21941==    at 0x4016A87: (within /lib/ld-2.9.so)
==21941==    by 0x42C5901: (within /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x400E035: (within /lib/ld-2.9.so)
==21941==    by 0x42C5AC4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x429D23F: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x429D30E: (within /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x429F16C: __nss_services_lookup2 (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x42A5E95: getservbyname_r (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x42A5BED: getservbyname (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x4348B85: mysql_server_init (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x4370E58: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x40548B3: mysqlpp::DBDriver::DBDriver() (dbdriver.cpp:48)
==21941==  Address 0x456a094 is 44 bytes inside a block of size 46 alloc'd
==21941==    at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==21941==    by 0x400E143: (within /lib/ld-2.9.so)
==21941==    by 0x4007DB5: (within /lib/ld-2.9.so)
==21941==    by 0x4012216: (within /lib/ld-2.9.so)
==21941==    by 0x400E035: (within /lib/ld-2.9.so)
==21941==    by 0x4011C1D: (within /lib/ld-2.9.so)
==21941==    by 0x42C5901: (within /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x400E035: (within /lib/ld-2.9.so)
==21941==    by 0x42C5AC4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x429D23F: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x429D30E: (within /lib/tls/i686/cmov/libc-2.9.so)
==21941==    by 0x429F16C: __nss_services_lookup2 (in /lib/tls/i686/cmov/libc-2.9.so)
Check2
Check3
Check4
Check5
==21941==
==21941== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 58 from 4)
==21941== malloc/free: in use at exit: 61,336 bytes in 16 blocks.
==21941== malloc/free: 124 allocs, 108 frees, 157,076 bytes allocated.
==21941== For counts of detected errors, rerun with: -v
==21941== searching for pointers to 16 not-freed blocks.
==21941== checked 622,212 bytes.
==21941==
==21941==
==21941== 16 bytes in 1 blocks are still reachable in loss record 1 of 2
==21941==    at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==21941==    by 0x434A52C: my_malloc (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x434B2DA: my_error_register (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x434A13F: init_client_errs (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x4348B18: mysql_server_init (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x4370E58: mysql_init (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x40548B3: mysqlpp::DBDriver::DBDriver() (dbdriver.cpp:48)
==21941==    by 0x404E12F: mysqlpp::Connection::Connection(bool) (connection.cpp:41)
==21941==    by 0x80489F9: main (main.cpp:7)
==21941==
==21941==
==21941== 61,320 bytes in 15 blocks are still reachable in loss record 2 of 2
==21941==    at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==21941==    by 0x4351CD2: my_once_alloc (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x43523AA: (within /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x4352E41: (within /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x435305F: get_charset_by_csname (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x4370C22: mysql_init_character_set (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x4372D1D: mysql_real_connect (in /usr/lib/libmysqlclient.so.15.0.0)
==21941==    by 0x40553A9: mysqlpp::DBDriver::connect(char const*, char const*, unsigned
int, char const*, char const*, char const*) (dbdriver.cpp:89)
==21941==    by 0x404EDE9: mysqlpp::Connection::connect(char const*, char const*, char
const*, char const*, unsigned int) (connection.cpp:98)
==21941==    by 0x8048A7F: main (main.cpp:11)
==21941==
==21941== LEAK SUMMARY:
==21941==    definitely lost: 0 bytes in 0 blocks.
==21941==      possibly lost: 0 bytes in 0 blocks.
==21941==    still reachable: 61,336 bytes in 16 blocks.
==21941==         suppressed: 0 bytes in 0 blocks.

All I do in my code is this:

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

int main()
{
    std::cout << "Check1" << std::endl;
    mysqlpp::Connection conn;
    std::cout << "Check2" << std::endl;
    conn.disable_exceptions();
    std::cout << "Check3" << std::endl;
    if (!conn.connect("Kakele","127.0.0.1","root","kakele1990",8080))
    {
        std::cout << conn.error() << std::endl;
        return 0;
    }
    std::cout << "Check4" << std::endl;
    conn.disconnect();
    std::cout << "Check5" << std::endl;
    return 1;
}

I am using the 3.0.9 version! Am I doing something wrong?

Thank you!
_________________________________________________________________
Emoticons e Winks super diferentes para o Messenger. Baixe agora, é grátis!
http://specials.br.msn.com/ilovemessenger/pacotes.aspx
Thread
Possible memory leak?Bruno Adami11 May
  • RE: Possible memory leak?Mark Easton11 May
  • Re: Possible memory leak?Warren Young11 May
    • RE: Possible memory leak?Bruno Adami11 May
    • RE: Possible memory leak?Bruno Adami11 May
      • RE: Possible memory leak?Kevin Stevens11 May
  • RE: Possible memory leak?Bruno Adami11 May
    • RE: Possible memory leak?Mark Easton11 May
    • Re: Possible memory leak?Warren Young11 May