llext: fix a memory leak in an error case
If a function fails it should release all the resources it has managed to acquire. Fix llext_load() to free memory that it has allocated in case of an error. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
parent
a2acd7b2fb
commit
86da7840bd
1 changed files with 4 additions and 1 deletions
|
@ -861,8 +861,11 @@ int llext_load(struct llext_loader *ldr, const char *name, struct llext **ext,
|
||||||
|
|
||||||
ldr->hdr = ehdr;
|
ldr->hdr = ehdr;
|
||||||
ret = do_llext_load(ldr, *ext, ldr_parm);
|
ret = do_llext_load(ldr, *ext, ldr_parm);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
|
k_heap_free(&llext_heap, *ext);
|
||||||
|
*ext = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
strncpy((*ext)->name, name, sizeof((*ext)->name));
|
strncpy((*ext)->name, name, sizeof((*ext)->name));
|
||||||
(*ext)->name[sizeof((*ext)->name) - 1] = '\0';
|
(*ext)->name[sizeof((*ext)->name) - 1] = '\0';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue