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; }