summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-02 23:56:54 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-02 23:56:54 +0000
commitbed10d9288e1c61599580049d63fe74873c08b37 (patch)
treec2045a94c067d8c6d0bf486449349494b9f1c1ff /apps
parent2cc0db0c264e064ee203c2f19b91f7ba013fdf25 (diff)
downloadpx4-nuttx-bed10d9288e1c61599580049d63fe74873c08b37.tar.gz
px4-nuttx-bed10d9288e1c61599580049d63fe74873c08b37.tar.bz2
px4-nuttx-bed10d9288e1c61599580049d63fe74873c08b37.zip
Correct a memory leak in NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5600 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rw-r--r--apps/builtin/exec_builtin.c32
-rw-r--r--apps/nshlib/nsh_parse.c14
2 files changed, 36 insertions, 10 deletions
diff --git a/apps/builtin/exec_builtin.c b/apps/builtin/exec_builtin.c
index 1924687e3..c262b43da 100644
--- a/apps/builtin/exec_builtin.c
+++ b/apps/builtin/exec_builtin.c
@@ -140,16 +140,16 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
/* Initialize attributes for task_spawn(). */
- ret = posix_spawn_file_actions_init(&file_actions);
+ ret = posix_spawnattr_init(&attr);
if (ret != 0)
{
goto errout_with_errno;
}
- ret = posix_spawnattr_init(&attr);
+ ret = posix_spawn_file_actions_init(&file_actions);
if (ret != 0)
{
- goto errout_with_errno;
+ goto errout_with_attrs;
}
/* Set the correct task size and priority */
@@ -158,13 +158,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
ret = posix_spawnattr_setschedparam(&attr, &param);
if (ret != 0)
{
- goto errout_with_errno;
+ goto errout_with_actions;
}
ret = task_spawnattr_setstacksize(&attr, builtin->stacksize);
if (ret != 0)
{
- goto errout_with_errno;
+ goto errout_with_actions;
}
/* If robin robin scheduling is enabled, then set the scheduling policy
@@ -175,7 +175,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
ret = posix_spawnattr_setschedpolicy(&attr, SCHED_RR);
if (ret != 0)
{
- goto errout_with_errno;
+ goto errout_with_actions;
}
ret = posix_spawnattr_setflags(&attr,
@@ -183,13 +183,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
POSIX_SPAWN_SETSCHEDULER);
if (ret != 0)
{
- goto errout_with_errno;
+ goto errout_with_actions;
}
#else
ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM);
if (ret != 0)
{
- goto errout_with_errno;
+ goto errout_with_actions;
}
#endif
@@ -204,7 +204,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
if (ret != 0)
{
sdbg("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret);
- goto errout_with_errno;
+ goto errout_with_actions;
}
}
@@ -216,16 +216,28 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
if (ret != 0)
{
sdbg("ERROR: task_spawn failed: %d\n", ret);
- goto errout_with_errno;
+ goto errout_with_actions;
}
+ /* Free attibutes and file actions. Ignoring return values in the case
+ * of an error.
+ */
+
/* Return the task ID of the new task if the task was sucessfully
* started. Otherwise, ret will be ERROR (and the errno value will
* be set appropriately).
*/
+ (void)posix_spawn_file_actions_destroy(&file_actions);
+ (void)posix_spawnattr_destroy(&attr);
return pid;
+errout_with_actions:
+ (void)posix_spawn_file_actions_destroy(&file_actions);
+
+errout_with_attrs:
+ (void)posix_spawnattr_destroy(&attr);
+
errout_with_errno:
set_errno(ret);
return ERROR;
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index f679d9b32..26b41e89b 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -1424,6 +1424,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* successfully). So certainly it is not an NSH command.
*/
+ /* Free the redirected output file path */
+
+ nsh_freefullpath(redirfile);
+ redirfile = NULL;
+
+ /* Save the result: success if 0; failure if 1 */
+
return nsh_saveresult(vtbl, ret != OK);
}
@@ -1458,6 +1465,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* successfully). So certainly it is not an NSH command.
*/
+ /* Free the redirected output file path */
+
+ nsh_freefullpath(redirfile);
+ redirfile = NULL;
+
+ /* Save the result: success if 0; failure if 1 */
+
return nsh_saveresult(vtbl, ret != OK);
}