[Bug-Fix] Resource leaks

In file "nuttx/libs/libc/modlib/modlib_bind.c", line656 not check return value of lib_malloc(), and line661 not free dyn.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This commit is contained in:
wangzhi16 2024-09-11 15:19:30 +08:00 committed by Xiang Xiao
parent 63db77628e
commit 129b738e6b

View File

@ -590,11 +590,18 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
ARCH_ELFDATA_DEF;
dyn = lib_malloc(shdr->sh_size);
if (dyn == NULL)
{
berr("Failed to allocate memory for elf dynamic section\n");
return -ENOMEM;
}
ret = modlib_read(loadinfo, (FAR uint8_t *)dyn, shdr->sh_size,
shdr->sh_offset);
if (ret < 0)
{
berr("Failed to read dynamic section header");
lib_free(dyn);
return ret;
}