From 58dcc29b6d1ca38f57e26cae6a34a8713f41fa5b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 1 Mar 2020 18:18:47 -0500 Subject: [PATCH] runtime_loader: Fix memory leak in init_dependencies. get_sorted_image_list allocates initList even if "count" winds up being 0, so we need to free it in this case also. Spotted by Coverity. --- src/system/runtime_loader/elf.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/system/runtime_loader/elf.cpp b/src/system/runtime_loader/elf.cpp index 4f0b0a801d..64b6f40eb9 100644 --- a/src/system/runtime_loader/elf.cpp +++ b/src/system/runtime_loader/elf.cpp @@ -306,7 +306,7 @@ relocate_dependencies(image_t *image) static void init_dependencies(image_t *image, bool initHead) { - image_t **initList; + image_t **initList = NULL; ssize_t count, i; if (initHead && image->preinit_array) { @@ -316,8 +316,10 @@ init_dependencies(image_t *image, bool initHead) } count = get_sorted_image_list(image, &initList, RFLAG_INITIALIZED); - if (count <= 0) + if (count <= 0) { + free(initList); return; + } if (!initHead) { // this removes the "calling" image