This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: use cleanup in zlib_decompress_section
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 17 Jun 2009 14:29:27 -0600
- Subject: FYI: use cleanup in zlib_decompress_section
- Reply-to: tromey at redhat dot com
I'm checking this in.
Yesterday I noticed again that zlib_decompress_section can leak memory
when there is an error. It uses an explicit free, but it should use a
cleanup.
This patch fixes the problem.
Tom
2009-06-17 Tom Tromey <tromey@redhat.com>
* dwarf2read.c (zlib_decompress_section): Use a cleanup.
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.311
diff -u -r1.311 dwarf2read.c
--- dwarf2read.c 17 Jun 2009 18:47:35 -0000 1.311
+++ dwarf2read.c 17 Jun 2009 20:28:57 -0000
@@ -1208,6 +1208,7 @@
#else
bfd_size_type compressed_size = bfd_get_section_size (sectp);
gdb_byte *compressed_buffer = xmalloc (compressed_size);
+ struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
bfd_size_type uncompressed_size;
gdb_byte *uncompressed_buffer;
z_stream strm;
@@ -1264,7 +1265,7 @@
error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
bfd_get_filename (abfd), rc);
- xfree (compressed_buffer);
+ do_cleanups (cleanup);
*outbuf = uncompressed_buffer;
*outsize = uncompressed_size;
#endif