Skip to content
Snippets Groups Projects
Commit 7f474703 authored by patacongo's avatar patacongo
Browse files

Correct a memory leak in NSH

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5600 42af7a65-404d-4744-a932-0658087f49c3
parent cca7618d
No related branches found
No related tags found
No related merge requests found
...@@ -140,16 +140,16 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, ...@@ -140,16 +140,16 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
/* Initialize attributes for task_spawn(). */ /* Initialize attributes for task_spawn(). */
ret = posix_spawn_file_actions_init(&file_actions); ret = posix_spawnattr_init(&attr);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_errno;
} }
ret = posix_spawnattr_init(&attr); ret = posix_spawn_file_actions_init(&file_actions);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_attrs;
} }
/* Set the correct task size and priority */ /* Set the correct task size and priority */
...@@ -158,13 +158,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, ...@@ -158,13 +158,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
ret = posix_spawnattr_setschedparam(&attr, &param); ret = posix_spawnattr_setschedparam(&attr, &param);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_actions;
} }
ret = task_spawnattr_setstacksize(&attr, builtin->stacksize); ret = task_spawnattr_setstacksize(&attr, builtin->stacksize);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_actions;
} }
/* If robin robin scheduling is enabled, then set the scheduling policy /* 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, ...@@ -175,7 +175,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
ret = posix_spawnattr_setschedpolicy(&attr, SCHED_RR); ret = posix_spawnattr_setschedpolicy(&attr, SCHED_RR);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_actions;
} }
ret = posix_spawnattr_setflags(&attr, ret = posix_spawnattr_setflags(&attr,
...@@ -183,13 +183,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, ...@@ -183,13 +183,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
POSIX_SPAWN_SETSCHEDULER); POSIX_SPAWN_SETSCHEDULER);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_actions;
} }
#else #else
ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM); ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM);
if (ret != 0) if (ret != 0)
{ {
goto errout_with_errno; goto errout_with_actions;
} }
#endif #endif
...@@ -204,7 +204,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv, ...@@ -204,7 +204,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
if (ret != 0) if (ret != 0)
{ {
sdbg("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret); 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, ...@@ -216,16 +216,28 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
if (ret != 0) if (ret != 0)
{ {
sdbg("ERROR: task_spawn failed: %d\n", ret); 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 /* Return the task ID of the new task if the task was sucessfully
* started. Otherwise, ret will be ERROR (and the errno value will * started. Otherwise, ret will be ERROR (and the errno value will
* be set appropriately). * be set appropriately).
*/ */
(void)posix_spawn_file_actions_destroy(&file_actions);
(void)posix_spawnattr_destroy(&attr);
return pid; return pid;
errout_with_actions:
(void)posix_spawn_file_actions_destroy(&file_actions);
errout_with_attrs:
(void)posix_spawnattr_destroy(&attr);
errout_with_errno: errout_with_errno:
set_errno(ret); set_errno(ret);
return ERROR; return ERROR;
......
...@@ -1424,6 +1424,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) ...@@ -1424,6 +1424,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* successfully). So certainly it is not an NSH command. * 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); return nsh_saveresult(vtbl, ret != OK);
} }
...@@ -1458,6 +1465,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) ...@@ -1458,6 +1465,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* successfully). So certainly it is not an NSH command. * 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); return nsh_saveresult(vtbl, ret != OK);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment