summaryrefslogtreecommitdiffstats
path: root/src/strip.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2013-03-01 11:51:58 +0100
committerMark Wielaard <[email protected]>2013-03-01 11:51:58 +0100
commita58951b183fb3e051870b19c95d8082a3efa3ddb (patch)
tree1c8f194f4f00e63d8abdb4306e40ce84e37a19b4 /src/strip.c
parentb94cceae503b56fb360cd597f154fa2b33552887 (diff)
Fix two memory leaks in findtextrel and strip.
The findtextrel leak is real, when processing lots of files without text relocations the files and memory wouldn't be released. The strip leak is minor since it can only happen when using -f which only allows one file as argument. But it is nice to see valgrind say: "All heap blocks were freed -- no leaks are possible". Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'src/strip.c')
-rw-r--r--src/strip.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/strip.c b/src/strip.c
index 5e9c8833..05adc206 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -432,6 +432,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
Elf_Data debuglink_crc_data;
bool any_symtab_changes = false;
Elf_Data *shstrtab_data = NULL;
+ void *debuglink_buf = NULL;
/* Create the full name of the file. */
if (prefix != NULL)
@@ -1046,7 +1047,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
shdr_info[cnt].data->d_align = 4;
shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size
= crc_offset + 4;
- shdr_info[cnt].data->d_buf = xcalloc (1, shdr_info[cnt].data->d_size);
+ debuglink_buf = xcalloc (1, shdr_info[cnt].data->d_size);
+ shdr_info[cnt].data->d_buf = debuglink_buf;
strcpy (shdr_info[cnt].data->d_buf, debug_basename);
@@ -2013,6 +2015,9 @@ while computing checksum for debug information"));
free (shdr_info[cnt].debug_data->d_buf);
}
+ /* Free data we allocated for the .gnu_debuglink section. */
+ free (debuglink_buf);
+
/* Free the memory. */
if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC)
free (shdr_info);