FYI: use cleanup in zlib_decompress_section

Tom Tromey tromey@redhat.com
Wed Jun 17 20:29:00 GMT 2009


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



More information about the Gdb-patches mailing list