aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-06-03 16:55:39 +0930
committerAlan Modra <amodra@gmail.com>2020-06-03 17:59:44 +0930
commit4a32244804f942a54960039c7968b1df2a177b4d (patch)
tree8262708c62d4ad388f33a14df32a88a20900187a /binutils/objcopy.c
parent0ed18fa177858d67fec42babbca3fef4ae1d939f (diff)
downloadgdb-4a32244804f942a54960039c7968b1df2a177b4d.zip
gdb-4a32244804f942a54960039c7968b1df2a177b4d.tar.gz
gdb-4a32244804f942a54960039c7968b1df2a177b4d.tar.bz2
PR26069, strip/objcopy memory leaks
PR 26069 * objcopy.c (copy_relocations_in_section): Free relpp on error. Don't accidentally free isection->orelocation.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 5760d06..3866c7f 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4294,6 +4294,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
status = 1;
bfd_nonfatal_message (NULL, ibfd, isection,
_("relocation count is negative"));
+ free (relpp);
return;
}
}
@@ -4318,7 +4319,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
temp_relpp [temp_relcount++] = relpp [i];
}
relcount = temp_relcount;
- if (isection->orelocation == NULL)
+ if (relpp != isection->orelocation)
free (relpp);
relpp = temp_relpp;
}
@@ -4327,7 +4328,8 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
if (relcount == 0)
{
osection->flags &= ~SEC_RELOC;
- free (relpp);
+ if (relpp != isection->orelocation)
+ free (relpp);
}
}
}