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.
This commit is contained in:
Augustin Cavalier
2020-03-01 18:18:47 -05:00
parent 51d0d6e229
commit 58dcc29b6d
+4 -2
View File
@@ -306,7 +306,7 @@ relocate_dependencies(image_t *image)
static void static void
init_dependencies(image_t *image, bool initHead) init_dependencies(image_t *image, bool initHead)
{ {
image_t **initList; image_t **initList = NULL;
ssize_t count, i; ssize_t count, i;
if (initHead && image->preinit_array) { 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); count = get_sorted_image_list(image, &initList, RFLAG_INITIALIZED);
if (count <= 0) if (count <= 0) {
free(initList);
return; return;
}
if (!initHead) { if (!initHead) {
// this removes the "calling" image // this removes the "calling" image