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:
Guennadi Liakhovetski 2023-11-09 14:19:05 +01:00 committed by Anas Nashif
commit 86da7840bd

View file

@ -861,8 +861,11 @@ int llext_load(struct llext_loader *ldr, const char *name, struct llext **ext,
ldr->hdr = ehdr;
ret = do_llext_load(ldr, *ext, ldr_parm);
if (ret < 0)
if (ret < 0) {
k_heap_free(&llext_heap, *ext);
*ext = NULL;
return ret;
}
strncpy((*ext)->name, name, sizeof((*ext)->name));
(*ext)->name[sizeof((*ext)->name) - 1] = '\0';