This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

Re: [RFA] elfread.c (elf_symtab_read): Stop memory leak.


Joel Brobecker wrote:
2011-03-05 Michael Snyder <msnyder@vmware.com>

* elfread.c (elf_symtab_read): Stop memory leak.

I think that's OK. A little more nervous than usual, as I had to look through a fair bit of code. But you did run this change past the testsuite, right?

Not one by one, but I batch them up, yes.



Note that we could possibly be using alloca to avoid the use
of heap allocation.  However, as I have learnt the hard way
in the past, it's a really bad idea to do so in a loop (one
can exhaust the stack very effectively that way).

Thanks, committed.



Index: elfread.c
===================================================================
RCS file: /cvs/src/src/gdb/elfread.c,v
retrieving revision 1.103
diff -u -p -r1.103 elfread.c
--- elfread.c 7 Jan 2011 19:36:16 -0000 1.103
+++ elfread.c 5 Mar 2011 20:33:20 -0000
@@ -242,6 +242,7 @@ elf_symtab_read (struct objfile *objfile
char *filesymname = "";
struct dbx_symfile_info *dbx = objfile->deprecated_sym_stab_info;
int stripped = (bfd_get_symcount (objfile->obfd) == 0);
+ struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
for (i = 0; i < number_of_symbols; i++)
{
@@ -464,6 +465,7 @@ elf_symtab_read (struct objfile *objfile
* max_index));
sectinfo = (struct stab_section_info *)
xmalloc (size);
+ make_cleanup (xfree, sectinfo);
memset (sectinfo, 0, size);
sectinfo->num_sections = max_index;
if (filesym == NULL)
@@ -572,6 +574,7 @@ elf_symtab_read (struct objfile *objfile
}
}
}
+ do_cleanups (back_to);
}
struct build_id




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