From: 邓尧 <to...@gm...> - 2013-03-01 09:27:25
|
Hi, I just wrote a simple "hello world" program with libdwarf. It just create a Dwarf_Debug instance and then destroy it, simple as this, I still got memory leaks. elftoolchain built with command "pmake MKPIC=yes MKPROFILE=no MKLINKLIB=no -k", the platform is Ubuntu Linux 12.04, gcc 4.7, x86_64, kernel version 3.2.0. I tried both elftoolchain-0.6.1 and the latest svn trunk. got similar leak information from valgrind, here is my source code (linked against libelf_pic.a & libdwarf_pic.a) #include <unistd.h> #include <fcntl.h> #include <dwarf.h> #include <libdwarf.h> #include <assert.h> int main() { Dwarf_Debug debug; Dwarf_Error error; int descriptor = open("a.out", O_RDONLY); // "a.out" is the program itself. assert(dwarf_init(descriptor, DW_DLC_READ, NULL, NULL, &debug, &error) == 0); dwarf_finish(debug, &error); close(descriptor); return 0; } This is the leak information reported by valgrind: ==1909== Memcheck, a memory error detector ==1909== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==1909== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==1909== Command: ./a.out ==1909== ==1909== ==1909== HEAP SUMMARY: ==1909== in use at exit: 29,763 bytes in 57 blocks ==1909== total heap usage: 63 allocs, 6 frees, 31,307 bytes allocated ==1909== ==1909== 29,763 (136 direct, 29,627 indirect) bytes in 1 blocks are definitely lost in loss record 9 of 9 ==1909== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==1909== by 0x41EFFA: _libelf_allocate_elf (in /tmp/a.out) ==1909== by 0x4138F6: _libelf_memory (in /tmp/a.out) ==1909== by 0x411EBE: _libelf_open_object (in /tmp/a.out) ==1909== by 0x410CFB: elf_begin (in /tmp/a.out) ==1909== by 0x4014A7: dwarf_init (in /tmp/a.out) ==1909== by 0x401187: main (dw.c:11) ==1909== ==1909== LEAK SUMMARY: ==1909== definitely lost: 136 bytes in 1 blocks ==1909== indirectly lost: 29,627 bytes in 56 blocks ==1909== possibly lost: 0 bytes in 0 blocks ==1909== still reachable: 0 bytes in 0 blocks ==1909== suppressed: 0 bytes in 0 blocks ==1909== ==1909== For counts of detected and suppressed errors, rerun with: -v ==1909== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2) Thanks Yao |