You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/07/20 11:56:42 UTC

[incubator-nuttx] branch master updated: binfmt: Fix memory leak in ELF loader

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 23d57be21b binfmt: Fix memory leak in ELF loader
23d57be21b is described below

commit 23d57be21b79531f1ecaf4882bae62a8153ede4a
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Wed Jul 20 17:06:53 2022 +0900

    binfmt: Fix memory leak in ELF loader
    
    Summary:
    - I noticed that the hello (ELF) application causes a memory leak.
    - Finally, I found that the data section is not deallocated.
    - This commit fixes this issue.
    
    Impact:
    - None
    
    Testing:
    - Tested with spresense:wifi_smp, rv-virt:nsh64, sabre-6quad:netnsh
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 binfmt/elf.c                  | 5 +++--
 include/nuttx/binfmt/binfmt.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/binfmt/elf.c b/binfmt/elf.c
index 85fbe300aa..ef225ec06e 100644
--- a/binfmt/elf.c
+++ b/binfmt/elf.c
@@ -277,9 +277,10 @@ static int elf_loadbinary(FAR struct binary_s *binp,
   up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv);
 #else
   binp->alloc[0]  = (FAR void *)loadinfo.textalloc;
+  binp->alloc[1]  = (FAR void *)loadinfo.dataalloc;
 #ifdef CONFIG_BINFMT_CONSTRUCTORS
-  binp->alloc[1]  = loadinfo.ctoralloc;
-  binp->alloc[2]  = loadinfo.dtoralloc;
+  binp->alloc[2]  = loadinfo.ctoralloc;
+  binp->alloc[3]  = loadinfo.dtoralloc;
 #endif
 #endif
 
diff --git a/include/nuttx/binfmt/binfmt.h b/include/nuttx/binfmt/binfmt.h
index 8c17d8f53b..e730551628 100644
--- a/include/nuttx/binfmt/binfmt.h
+++ b/include/nuttx/binfmt/binfmt.h
@@ -39,7 +39,7 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define BINFMT_NALLOC 3
+#define BINFMT_NALLOC 4
 
 /****************************************************************************
  * Public Types