libelf: Don't leak memory when out of memory in updatemmap.
authorMark Wielaard <mjw@redhat.com>
Sat, 13 Feb 2016 18:51:48 +0000 (19:51 +0100)
committerMark Wielaard <mjw@redhat.com>
Mon, 22 Feb 2016 11:14:44 +0000 (12:14 +0100)
We forgot to free scns when returning ELF_E_NOMEM.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf32_updatefile.c

index b966923..350e4eb 100644 (file)
@@ -1,3 +1,7 @@
+2016-02-13  Mark Wielaard  <mjw@redhat.com>
+
+       * elf32_updatefile.c (updatemmap): Free scns when out of memory.
+
 2016-01-28  Mark Wielaard  <mjw@redhat.com>
 
        * elf.h: Update from glibc. Add new i386 and x86_64 relocations.
index 0909219..d0fabb1 100644 (file)
@@ -1,5 +1,5 @@
 /* Write changed data structures.
-   Copyright (C) 2000-2010, 2014, 2015 Red Hat, Inc.
+   Copyright (C) 2000-2010, 2014, 2015, 2016 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -269,6 +269,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
              void *p = malloc (sizeof (ElfW2(LIBELFBITS,Shdr)));
              if (unlikely (p == NULL))
                {
+                 free (scns);
                  __libelf_seterrno (ELF_E_NOMEM);
                  return -1;
                }
@@ -295,6 +296,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
              void *p = malloc (scn->data_list.data.d.d_size);
              if (unlikely (p == NULL))
                {
+                 free (scns);
                  __libelf_seterrno (ELF_E_NOMEM);
                  return -1;
                }