You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/04/21 10:38:44 UTC

[incubator-nuttx] 01/04: binfmt_execmodule: add errout_with_args exit point

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

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

commit 6b1ee4c2e24347588c48fe425f2600b4e1baef86
Author: Ville Juven <vi...@unikie.com>
AuthorDate: Fri Apr 8 11:10:01 2022 +0300

    binfmt_execmodule: add errout_with_args exit point
    
    Ensures that when errout_xx is taken, args are freed
---
 binfmt/binfmt_execmodule.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c
index 61b41cbf01..b6db1860a5 100644
--- a/binfmt/binfmt_execmodule.c
+++ b/binfmt/binfmt_execmodule.c
@@ -157,8 +157,7 @@ int exec_module(FAR const struct binary_s *binp,
   if (ret < 0)
     {
       berr("ERROR: up_addrenv_select() failed: %d\n", ret);
-      binfmt_freeargv(argv);
-      goto errout_with_tcb;
+      goto errout_with_args;
     }
 
   binfo("Initialize the user heap (heapsize=%d)\n", binp->addrenv.heapsize);
@@ -182,13 +181,14 @@ int exec_module(FAR const struct binary_s *binp,
                         binp->stacksize, binp->entrypt, argv);
     }
 
-  binfmt_freeargv(argv);
   if (ret < 0)
     {
       berr("nxtask_init() failed: %d\n", ret);
       goto errout_with_addrenv;
     }
 
+  binfmt_freeargv(argv);
+
 #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
   /* Allocate the kernel stack */
 
@@ -282,6 +282,8 @@ errout_with_addrenv:
 #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
   up_addrenv_restore(&oldenv);
 #endif
+errout_with_args:
+  binfmt_freeargv(argv);
 errout_with_tcb:
   kmm_free(tcb);
   return ret;