summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-03 13:48:20 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-03 13:48:20 +0000
commit0066db82f921ad84a9017242396e37259f3d71f4 (patch)
tree13a8a1e51a818be68c2e178cbd2f55502d4e9971
parentbed10d9288e1c61599580049d63fe74873c08b37 (diff)
downloadpx4-nuttx-0066db82f921ad84a9017242396e37259f3d71f4.tar.gz
px4-nuttx-0066db82f921ad84a9017242396e37259f3d71f4.tar.bz2
px4-nuttx-0066db82f921ad84a9017242396e37259f3d71f4.zip
NSH needs to call pthread_detach() to avoid memory leak
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5601 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/ChangeLog.txt2
-rw-r--r--apps/nshlib/nsh_parse.c18
2 files changed, 16 insertions, 4 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index d9a42fe73..abeab4a5c 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -511,4 +511,6 @@
* apps/builtin/exec_builtin.c: Now uses task_spawn() to start
builtin applications.
* Type of argv has changed from const char ** to char * const *
+ * apps/nshlib/nsh_parse.c: Fix memory lead: Need to detach after
+ creating a pthread.
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index 26b41e89b..4ee86b4cc 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -1426,8 +1426,10 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Free the redirected output file path */
- nsh_freefullpath(redirfile);
- redirfile = NULL;
+ if (redirfile)
+ {
+ nsh_freefullpath(redirfile);
+ }
/* Save the result: success if 0; failure if 1 */
@@ -1467,8 +1469,10 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Free the redirected output file path */
- nsh_freefullpath(redirfile);
- redirfile = NULL;
+ if (redirfile)
+ {
+ nsh_freefullpath(redirfile);
+ }
/* Save the result: success if 0; failure if 1 */
@@ -1596,6 +1600,12 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
goto errout;
}
+ /* Detach from the pthread since we are not going to join with it.
+ * Otherwise, we would have a memory leak.
+ */
+
+ (void)pthread_detach(thread);
+
nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority);
}
else