From 129b738e6b44ca4490bf4f6acaa509a08601a604 Mon Sep 17 00:00:00 2001 From: wangzhi16 Date: Wed, 11 Sep 2024 15:19:30 +0800 Subject: [PATCH] [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 --- libs/libc/modlib/modlib_bind.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/libc/modlib/modlib_bind.c b/libs/libc/modlib/modlib_bind.c index a8602eb4f3..33750bc7f5 100644 --- a/libs/libc/modlib/modlib_bind.c +++ b/libs/libc/modlib/modlib_bind.c @@ -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; }