mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-06 05:41:37 +00:00
[LibOS] Fix memory leak in __map_elf_object()
Pointer l can point to a newly allocated object (via new_elf_object()). Ensure l is freed on error (on call_lose code path).
This commit is contained in:
@@ -366,11 +366,14 @@ __map_elf_object (struct shim_handle * file,
|
||||
if (file && (!read || !mmap || !seek))
|
||||
return NULL;
|
||||
|
||||
struct link_map * l = remap ? :
|
||||
struct link_map * l = remap ? remap :
|
||||
new_elf_object(file ? (!qstrempty(&file->path) ?
|
||||
qstrgetstr(&file->path) :
|
||||
qstrgetstr(&file->uri)) : "", type);
|
||||
|
||||
if (!l)
|
||||
return NULL;
|
||||
|
||||
const char * errstring __attribute__((unused)) = NULL;
|
||||
int errval = 0;
|
||||
int ret;
|
||||
@@ -378,9 +381,7 @@ __map_elf_object (struct shim_handle * file,
|
||||
if (type != OBJECT_INTERNAL && !file) {
|
||||
errstring = "shared object has to be backed by file";
|
||||
errval = -EINVAL;
|
||||
call_lose:
|
||||
debug("loading %s: %s\n", l->l_name, errstring);
|
||||
return NULL;
|
||||
goto call_lose;
|
||||
}
|
||||
|
||||
/* Scan the program header table, collecting its load commands. */
|
||||
@@ -728,6 +729,14 @@ postmap:
|
||||
setup_elf_hash(l);
|
||||
|
||||
return l;
|
||||
|
||||
call_lose:
|
||||
debug("loading %s: %s\n", l->l_name, errstring);
|
||||
if (l != remap) {
|
||||
/* l was allocated via new_elf_object() */
|
||||
free(l);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline
|
||||
|
||||
Reference in New Issue
Block a user