This is the mail archive of the
mailing list for the binutils project.
Re: bfd_get_full_section_contents memory leak, plus
>>>>> "Alan" == Alan Modra <firstname.lastname@example.org> writes:
Alan> You're correct. Sorry, I didn't look closely enough at the code.
No problem, thank you for taking another look.
Alan> I guess the reason for the internal decompress buffer is to save time
Alan> decompressing in situations where the section is read more than once.
Alan> I think it would be better to just decompress over again, and leave
Alan> any caching to the caller. After all, for non-compressed sections
Alan> we read the data off disk again.
That fixes both my issues nicely.
The appended removes the caching for the uncompression case. I left the
COMPRESS_SECTION_DONE code in place, because it seems to me that a BFD
user could possibly compress section data in place
(bfd_compress_section_contents still sets sec->contents, and as gdb
doesn't use this code I was reluctant to touch it), and then later call
* compress.c (bfd_get_full_section_contents): Don't cache
diff --git a/bfd/compress.c b/bfd/compress.c
index 52c884c..bc14f2c 100644
@@ -165,7 +165,6 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
- bfd_byte *uncompressed_buffer;
if (abfd->direction != write_direction && sec->rawsize != 0)
@@ -220,24 +219,24 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
- uncompressed_buffer = (bfd_byte *) bfd_malloc (uncompressed_size);
- if (uncompressed_buffer == NULL)
+ if (p == NULL)
+ p = (bfd_byte *) bfd_malloc (uncompressed_size);
+ if (p == NULL)
if (!decompress_contents (compressed_buffer, compressed_size,
- uncompressed_buffer, uncompressed_size))
+ p, uncompressed_size))
- free (uncompressed_buffer);
+ free (p);
- sec->contents = uncompressed_buffer;
- sec->compress_status = COMPRESS_SECTION_DONE;
- /* Fall thru */
+ *ptr = p;
+ return TRUE;