Make sure that on all error paths the pre-allocated phdr is freed and
set to NULL. The notcvt malloc failure path was missed.
* libelf/elf32_getphdr.c (getphdr_wrlock): Free state.phdr and
set it to NULL on notcvt malloc failure.
Signed-off-by: Mark Wielaard <[email protected]>
---
libelf/elf32_getphdr.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libelf/elf32_getphdr.c b/libelf/elf32_getphdr.c
index 4bfca24b8d06..9aa1b6259163 100644
--- a/libelf/elf32_getphdr.c
+++ b/libelf/elf32_getphdr.c
@@ -150,6 +150,8 @@ __elfw2(LIBELFBITS,getphdr_wrlock) (Elf *elf)
if (unlikely (notcvt == NULL))
{
__libelf_seterrno (ELF_E_NOMEM);
+ free (elf->state.ELFW(elf,LIBELFBITS).phdr);
+ elf->state.ELFW(elf,LIBELFBITS).phdr = NULL;
goto out;
}
memcpy (notcvt, file_phdr, size);
--
2.56.0