This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

memory leak in bfd_find_nearest_line()


Hi,

I am having a weird leak in bfd_find_nearest_line() if I use the
binutils 2.20.1-3ubuntu7 package, but if I download the sources for
this package, build bfd myself and use it (either statically or
dynamically), the leak disappears. How can that be possible?

You can try it yourself by doing:

git clone git://github.com/certik/rcp.git
cd rcp
cmake .
make
examples/test_memory/test_memory

then run "top" in another terminal and observer that the memory usage
is growing (the test_memory program calls bfd_openr(),
bfd_find_nearest_line(), bfd_close() in an infinite loop).

Valgrind complains about 20 things roughly, one of them is:

==300== 4,064 bytes in 1 blocks are possibly lost in loss record 15 of 21
==300==    at 0x4C284A8: malloc (vg_replace_malloc.c:236)
==300==    by 0x50FA3CC: objalloc_create (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x50832C8: bfd_hash_table_init_n (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x50781B1: bfd_preserve_save (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x5099E18: bfd_elf64_object_p (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x507D651: bfd_check_format_matches (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x5090FC6: ??? (in /usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x5091106: _bfd_dwarf2_find_nearest_line (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x509D0B9: _bfd_elf_find_nearest_line (in
/usr/lib/libbfd-2.20.1-system.20100303.so)
==300==    by 0x4E40C2B: (anonymous namespace)::process_section(bfd*,
bfd_section*, void*) (Teuchos_stacktrace.cpp:226)
==300==    by 0x50811CB: bfd_map_over_sections (in
/usr/lib/libbfd-2.20.1-system.20100303.so)

I was able to find the definitions of all the functions above, except
bfd_elf64_object_p, but I am not sure from the source code what is
happening, and why it doesn't get deallocated.

Does anyone more familiar with bfd know, what is going on?


To compile bfd from source, do:

git checkout -t origin/bfd
./compile
cmake .
make
examples/test_memory/test_memory

then there is no leak at all. The only difference between these two
branches is that in the "bfd" branch, I compile bfd() from source and
use it, instead of the Ubuntu one.

If you use the master branch (which leaks) and apply this patch:


--- a/src/Teuchos_stacktrace.cpp
+++ b/src/Teuchos_stacktrace.cpp
@@ -222,8 +222,10 @@ void process_section(bfd *abfd, asection *section, void *_d
    // Finds the line corresponding to the offset

    const char *filename=NULL, *function_name=NULL;
+    /*
    data->line_found = bfd_find_nearest_line(abfd, section, data->symbol_table,
        offset, &filename, &function_name, &data->line);
+        */

    if (filename == NULL)
        data->filename = "";


then there is no memory leak either. Which suggest that the leak is
caused by bfd_find_nearest_line(). However, since I can't reproduce it
by compiling bfd from source (the same version that was used to create
the Ubuntu binary package), I don't know who to debug this. Any ideas?

In the "bfd" branch, I link bfd statically, so I also tried to link it
dynamically, just like I use the Ubuntu version of bfd:

git checkout -t origin/bfd-shared
./compile
cmake .
make
examples/test_memory/test_memory


and again, no leak in "top". Whenever there is no leak, then valgrind
doesn't show anything.


It might be just some Ubuntu problem, that for some reason the
binutils package is broken and leaks, but maybe it's a bug in
binutils. If there is someone familiar with bfd_find_nearest_line(),
maybe you get some idea (given the valgrind output above), what could
be the reason? Or do you have any tips, how I could debug this
problem?

Thanks,
Ondrej Certik
http://ondrejcertik.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]