This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[COMMITTED] libelf: Fix possible resource leak in elf[32|64]_updatefile.


When we cannot allocate enough memory to convert the data in
updatemmap we should free the scns before returning an error.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libelf/ChangeLog          | 5 +++++
 libelf/elf32_updatefile.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index a2e4ee9..fd908e2 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2019-03-06  Mark Wielaard  <mark@klomp.org>
+
+	* elf32_updatefile.c (updatemmap): Free scns before returning
+	allocation failure.
+
 2019-02-24  Mark Wielaard  <mark@klomp.org>
 
 	* gelf_xlate.c (__elf_xfctstof): Remove alias.
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 2899c6f..457d18e 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -365,6 +365,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
 			    char *converted = aligned_alloc (align, size);
 			    if (converted == NULL)
 			      {
+				free (scns);
 				__libelf_seterrno (ELF_E_NOMEM);
 				return 1;
 			      }
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]