public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix leak of auto_obstack objfile_per_bfd_storage->storage_obstack;
@ 2017-08-26 12:06 Philippe Waroquiers
  2017-09-05 18:31 ` Pedro Alves
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Waroquiers @ 2017-08-26 12:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

  commit 23732b1e32dd58f7c731d9aee56ff0b22a645d53
  Author: Pedro Alves <palves@redhat.com>
  Date:   Tue Jun 27 16:22:08 2017 +0100
changed objfile_per_bfd_storage->storage_obstack
from  'struct obstack storage_obstack;'
to    'auto_obstack storage_obstack;'
So the obstack is auto allocated when the  objfile_per_bfd_storage ctor is
manually called by get_objfile_bfd_data).
However, the ctor call was still followed by a manual call to
      obstack_init (&storage->storage_obstack);

This results in a bunch of leaks detected by valgrind, such as:
==24665== 4,064 bytes in 1 blocks are definitely lost in loss record 11,469 of 11,590
==24665==    at 0x4C27BF5: malloc (vg_replace_malloc.c:299)
==24665==    by 0x5437B7: xmalloc (common-utils.c:44)
==24665==    by 0x77CAA7: _obstack_begin_worker (obstack.c:141)
==24665==    by 0x60168F: auto_obstack (gdb_obstack.h:70)
==24665==    by 0x60168F: get_objfile_bfd_data(objfile*, bfd*) (objfiles.h:188)
==24665==    by 0x601DB6: allocate_objfile(bfd*, char const*, enum_flags<objfile_flag>) (objfiles.c:423)
==24665==    by 0x647753: symbol_file_add_with_addrs(bfd*, char const*, enum_flags<symfile_add_flag>, section_addr_info*, enum_flags<objfile_flag>, objfile*) (symfile.c:1158)
==24665==    by 0x647C7B: symbol_file_add_separate(bfd*, char const*, enum_flags<symfile_add_flag>, objfile*) (symfile.c:1252)
==24665==    by 0x4C7D79: elf_symfile_read(objfile*, enum_flags<symfile_add_flag>) (elfread.c:1270)
==24665==    by 0x647CB4: read_symbols(objfile*, enum_flags<symfile_add_flag>) (symfile.c:861)
==24665==    by 0x647809: syms_from_objfile_1 (symfile.c:1062)

-> remove the manual call to obstack_init.
Reg-tested on Debian 8/amd64, tests results are the same before/after the patch.
valgrind still show some leaks, but less.

gdb/ChangeLog
2017-08-26  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* objfiles.c (get_objfile_bfd_data): Remove useless obstack_init
	call.
---
 gdb/objfiles.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index c49c7ea..96634b3 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -160,7 +160,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
       if (abfd != NULL)
 	storage->gdbarch = gdbarch_from_bfd (abfd);
 
-      obstack_init (&storage->storage_obstack);
       storage->filename_cache = bcache_xmalloc (NULL, NULL);
       storage->macro_cache = bcache_xmalloc (NULL, NULL);
       storage->language_of_main = language_unknown;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix leak of auto_obstack objfile_per_bfd_storage->storage_obstack;
  2017-08-26 12:06 [PATCH] Fix leak of auto_obstack objfile_per_bfd_storage->storage_obstack; Philippe Waroquiers
@ 2017-09-05 18:31 ` Pedro Alves
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2017-09-05 18:31 UTC (permalink / raw)
  To: Philippe Waroquiers, gdb-patches

On 08/26/2017 01:06 PM, Philippe Waroquiers wrote:
>   commit 23732b1e32dd58f7c731d9aee56ff0b22a645d53
>   Author: Pedro Alves <palves@redhat.com>
>   Date:   Tue Jun 27 16:22:08 2017 +0100
> changed objfile_per_bfd_storage->storage_obstack
> from  'struct obstack storage_obstack;'
> to    'auto_obstack storage_obstack;'
> So the obstack is auto allocated when the  objfile_per_bfd_storage ctor is
> manually called by get_objfile_bfd_data).
> However, the ctor call was still followed by a manual call to
>       obstack_init (&storage->storage_obstack);
> 
> This results in a bunch of leaks detected by valgrind, such as:

Whoops, sorry about that.

> gdb/ChangeLog
> 2017-08-26  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> 
> 	* objfiles.c (get_objfile_bfd_data): Remove useless obstack_init
> 	call.

Patch is OK.  I'd call it obvious, even.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-05 18:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-26 12:06 [PATCH] Fix leak of auto_obstack objfile_per_bfd_storage->storage_obstack; Philippe Waroquiers
2017-09-05 18:31 ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).