From 16dac58f4ad959ee92bd4ed97aa53f20824aa4f9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 12 Jan 2014 14:16:05 -0600 Subject: Fix a memory leak in last NSH change: Forgot to close a temporary file --- apps/ChangeLog.txt | 2 ++ apps/nshlib/nsh_parse.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index d2711e456..3ac05c656 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -774,4 +774,6 @@ * apps/nshlib/nsh_parse.c: Can now handle arguments that are concatenations of constant strings, command return data, application return data, and environment variables (2014-1-11). + * apps/nshlib/nsh_parse.c: Fix a memory leak ... forgot to close + a temporary file (2013-1-12). diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index 4fdeb422a..b9f1d1853 100644 --- a/apps/nshlib/nsh_parse.c +++ b/apps/nshlib/nsh_parse.c @@ -166,7 +166,7 @@ static int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, #endif #ifdef CONFIG_NSH_CMDPARMS -static int nsh_parse_funcparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline, +static int nsh_parse_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline, FAR const char *redirfile); #endif static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline); @@ -184,7 +184,9 @@ static const char g_arg_separator[] = "`$"; #endif static const char g_redirect1[] = ">"; static const char g_redirect2[] = ">>"; +#ifndef CONFIG_DISABLE_ENVIRON static const char g_exitstatus[] = "?"; +#endif static const char g_success[] = "0"; static const char g_failure[] = "1"; static const char g_nullstring[] = ""; @@ -775,6 +777,10 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1, /* Make sure that the new string is null terminated */ argument[index] = '\0'; + + /* Close the temporary file and return the concatenated value */ + + close (fd); return argument; errout_with_fd: @@ -820,7 +826,7 @@ static FAR char *nsh_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline, * options. */ - ret = nsh_parse_funcparm(vtbl, cmdline, tmpfile); + ret = nsh_parse_cmdparm(vtbl, cmdline, tmpfile); if (ret != OK) { /* Report the failure */ @@ -1539,7 +1545,7 @@ static int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, #endif /**************************************************************************** - * Name: nsh_parse_funcparm + * Name: nsh_parse_cmdparm * * Description: * This function parses and executes a simple NSH command. Output is @@ -1553,8 +1559,8 @@ static int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, ****************************************************************************/ #ifdef CONFIG_NSH_CMDPARMS -static int nsh_parse_funcparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline, - FAR const char *redirfile) +static int nsh_parse_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline, + FAR const char *redirfile) { NSH_MEMLIST_TYPE memlist; FAR char *argv[MAX_ARGV_ENTRIES]; -- cgit v1.2.3