>Description: dmalloc identifies memory leaks when using mysqlclient c library once a malloc and associated free have been used. Although these memory leaks are not within the mysqlclient library itself they are found in mainly nsswitch.c and elf libraries such as dl-open.c and dl-version.c that are used by the myslclient library.
>How-To-Repeat: Consider the code: *********************************************CODE**************************************************** #include <stdlib.h> #include <stdio.h> #include <mysql/mysql.h> #include "dmalloc.h" int main() { MYSQL mysql; char *test; //test = malloc(sizeof(char) * 200); mysql_init(&mysql); mysql_real_connect(&mysql,"127.0.0.1","username","password","database",0,NULL,0); mysql_close(&mysql); //free(test); printf("Finished!\n"); } *********************************************END OF CODE**************************************************** compiled using : "gcc mysql_mem.c -o mysql_mem -lmysqlclient -ldmalloc" This produces no dmalloc log file *until* the malloc and free are uncommented. Then the following dmalloc logfile is created: *********************************************DMALLOC LOG**************************************************** 1034954529: 80: Dmalloc version '4.8.2' from 'http://dmalloc.com/' 1034954529: 80: flags = 0x4f47543, logfile 'test-log' 1034954529: 80: interval = 0, addr = 0, seen # = 0 1034954529: 80: starting time = 1034954528 1034954529: 80: free bucket count/bits: 109/5 34/6 31/7 15/8 8/9 3/10 1/11 1/14 1034954529: 80: basic-block 4096 bytes, alignment 8 bytes, heap grows up 1034954529: 80: heap: 0x808c000 to 0x809c000, size 65536 bytes (16 blocks) 1034954529: 80: heap checked 0 1034954529: 80: alloc calls: malloc 65, calloc 2, realloc 0, free 13 1034954529: 80: alloc calls: recalloc 0, memalign 0, valloc 0 1034954529: 80: total memory allocated: 17169 bytes (67 pnts) 1034954529: 80: max in use at one time: 16214 bytes (61 pnts) 1034954529: 80: max alloced with 1 call: 8192 bytes 1034954529: 80: max alloc rounding loss: 11466 bytes (41%) 1034954529: 80: max memory space wasted: 14510 bytes (34%) 1034954529: 80: final user memory space: basic 5, divided 7, 42190 bytes 1034954529: 80: final admin overhead: basic 1, divided 3, 16384 bytes (25%) 1034954529: 80: final external space: 0 bytes (0 blocks) 1034954529: 80: top 10 allocations: 1034954529: 80: total-size count in-use-size count source 1034954529: 80: 8540 5 64 1 ra=0x4002ee7a 1034954529: 80: 4088 1 4088 1 ra=0x40034a2b 1034954529: 80: 1024 1 1024 1 ra=0x40153408 1034954529: 80: 1008 26 1008 26 ra=0x4014e975 1034954529: 80: 728 2 0 0 ra=0x400c4571 1034954529: 80: 512 1 512 1 ra=0x4000abfd 1034954529: 80: 364 1 0 0 ra=0x400c6871 1034954529: 80: 242 15 242 15 ra=0x4014edfe 1034954529: 80: 200 1 0 0 mysql_mem.c:11 1034954529: 80: 17169 67 7214 54 Total of 20 1034954529: 80: dumping not-freed pointers changed since 0: 1034954529: 80: not freed: '0x808e208|s1' (128 bytes) from 'ra=0x4000ebba' 1034954529: 80: not freed: '0x808f008|s1' (1024 bytes) from 'ra=0x40153408' 1034954529: 80: not freed: '0x8092008|s1' (8 bytes) from 'ra=0x4014e805' 1034954529: 80: not freed: '0x8092028|s1' (15 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092048|s1' (15 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092068|s1' (14 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092088|s1' (14 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x80920a8|s1' (19 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x80920c8|s1' (15 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x80920e8|s1' (17 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092108|s1' (17 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092128|s1' (18 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092148|s1' (12 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092168|s1' (17 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092188|s1' (17 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x80921a8|s1' (18 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x80921c8|s1' (18 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x80921e8|s1' (16 bytes) from 'ra=0x4014edfe' 1034954529: 80: not freed: '0x8092208|s1' (16 bytes) from 'ra=0x4013e76d' 1034954529: 80: not freed: '0x8092228|s1' (8 bytes) from 'ra=0x4014e1fb' 1034954529: 80: not freed: '0x8092248|s1' (12 bytes) from 'ra=0x4014eef3' 1034954529: 80: not freed: '0x8094008|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094048|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094088|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x80940c8|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094108|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094148|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094188|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x80941c8|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094208|s1' (36 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094248|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094288|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x80942c8|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094308|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094348|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094388|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x80943c8|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094408|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094448|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094488|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x80944c8|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094508|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094548|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094588|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x80945c8|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094608|s1' (38 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094648|s1' (40 bytes) from 'ra=0x4014e975' 1034954529: 80: not freed: '0x8094688|s1' (23 bytes) from 'ra=0x40007f98' 1034954529: 80: not freed: '0x80946c8|s1' (30 bytes) from 'ra=0x4000ac0e' 1034954529: 80: not freed: '0x8094708|s1' (23 bytes) from 'ra=0x4000ae6c' 1034954529: 80: not freed: '0x8094748|s1' (28 bytes) from 'ra=0x4000c78e' 1034954529: 80: not freed: '0x8095008|s1' (512 bytes) from 'ra=0x4000abfd' 1034954529: 80: not freed: '0x8096088|s1' (64 bytes) from 'ra=0x4002ee7a' 1034954529: 80: not freed: '0x809a008|s1' (4088 bytes) from 'ra=0x40034a2b' 1034954529: 80: total-size count source 1034954529: 80: 4088 1 ra=0x40034a2b 1034954529: 80: 1024 1 ra=0x40153408 1034954529: 80: 1008 26 ra=0x4014e975 1034954529: 80: 512 1 ra=0x4000abfd 1034954529: 80: 242 15 ra=0x4014edfe 1034954529: 80: 128 1 ra=0x4000ebba 1034954529: 80: 64 1 ra=0x4002ee7a 1034954529: 80: 30 1 ra=0x4000ac0e 1034954529: 80: 28 1 ra=0x4000c78e 1034954529: 80: 23 1 ra=0x40007f98 1034954529: 80: 23 1 ra=0x4000ae6c 1034954529: 80: 16 1 ra=0x4013e76d 1034954529: 80: 12 1 ra=0x4014eef3 1034954529: 80: 8 1 ra=0x4014e1fb 1034954529: 80: 8 1 ra=0x4014e805 1034954529: 80: 7214 54 Total of 15 1034954529: 80: unknown memory: 54 pointers, 7214 bytes 1034954529: 80: ending time = 1034954529, elapsed since start = 0:00:01 1034954529: 81: WARNING: tried to free(0) from 'ra=0x4019d9ae' 1034954529: 81: free: invalid pointer: from 'ra=0x4019d9ae' 1034954529: 81: ERROR: _chunk_free: pointer is null (err 20) *********************************************END OF DMALLOC LOG**************************************************** Using gdb the memory address are resolved to the following: *********************************************GDB ADDRESS RESOLUTION**************************************************** (gdb) info line *0x4019d9ae Line 264 of "md5-crypt.c" starts at address 0x4019d9ae <free_mem+30> and ends at 0x4019d9b8 <free_mem+40>. (gdb) info line *0x40034a2b No line number information available for address 0x40034a2b <my_once_alloc+107> (gdb) info line *0x40153408 Line 109 of "../nss/getXXbyYY.c" starts at address 0x401533fe <getservbyname+314> and ends at 0x4015340e <getservbyname+330>. (gdb) info line *0x4014e975 Line 514 of "nsswitch.c" starts at address 0x4014e962 <nss_parse_service_list+114> and ends at 0x4014e978 <nss_parse_service_list+136>. (gdb) info line *0x4000abfd Line 40 of "dl-object.c" starts at address 0x4000abf8 <_dl_new_object+52> and ends at 0x4000ac00 <_dl_new_object+60>. (gdb) info line *0x4014edfe Line 656 of "nsswitch.c" starts at address 0x4014edf3 <nss_getline+131> and ends at 0x4014ee01 <nss_getline+145>. (gdb) *********************************************END OF GDB STUFF**************************************************** >Fix: >Submitter-Id: <submitter ID> >Originator: Chris Masters >Organization: >MySQL support: none >Synopsis: mysqlclient c library memeory leak detected using dmalloc >Severity: non-critical >Priority: >Category: mysql >Class: sw-bug >Release: mysql-3.23.52 (Official MySQL RPM) >Server: /usr/bin/mysqladmin Ver 8.23 Distrib 3.23.52, for pc-linux-gnu on i686 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.52 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 4 days 21 hours 18 min 59 sec Threads: 24 Questions: 1290615 Slow queries: 0 Opens: 75 Flush tables: 1 Open tables: 25 Queries per second avg: 3.056 >Environment: System: Linux 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 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-redhat-linux/2.96/specs gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) Compilation info: CC='gcc' CFLAGS='-O6 -fno-omit-frame-pointer -mpentium' CXX='gcc' CXXFLAGS='-O6 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti -mpentium' LDFLAGS='' LIBC: lrwxrwxrwx 1 root root 13 Jul 31 11:24 /lib/libc.so.6 -> libc-2.2.4.so -rwxr-xr-x 1 root root 1282588 Sep 4 2001 /lib/libc-2.2.4.so -rw-r--r-- 1 root root 27304836 Sep 4 2001 /usr/lib/libc.a -rw-r--r-- 1 root root 178 Sep 4 2001 /usr/lib/libc.so Configure command: ./configure --disable-shared --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-other-libc=/usr/local/mysql-glibc --without-berkeley-db --without-innodb --enable-assembler --enable-local-infile --with-mysqld-user=mysql --with-unix-socket-path=/var/lib/mysql/mysql.sock --prefix=/ --with-extra-charsets=complex --exec-prefix=/usr --libexecdir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var/lib/mysql --infodir=/usr/share/info --includedir=/usr/include --mandir=/usr/share/man '--with-comment=Official MySQL RPM' CC=gcc 'CFLAGS=-O6 -fno-omit-frame-pointer -mpentium' 'CXXFLAGS=-O6 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti -mpentium' CXX=gcc --------------------------------------------------------------------- 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