aboutsummaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-26 21:01:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-26 21:01:19 +0000
commit3bec164b3ae1cd7f9b5dcec532e7d073be96d45d (patch)
tree2c5a08e4daba522a5bcc3bc41537bd8e3361da5c /nuttx
parent5b6482a22bb8b656e3d70a6efc5ae2c77ed2a58b (diff)
downloadpx4-firmware-3bec164b3ae1cd7f9b5dcec532e7d073be96d45d.tar.gz
px4-firmware-3bec164b3ae1cd7f9b5dcec532e7d073be96d45d.tar.bz2
px4-firmware-3bec164b3ae1cd7f9b5dcec532e7d073be96d45d.zip
Fix a recently introduced memory leak
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5568 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/sched/Makefile3
-rw-r--r--nuttx/sched/group_internal.h8
-rw-r--r--nuttx/sched/group_leave.c107
-rw-r--r--nuttx/sched/group_releasefiles.c (renamed from nuttx/sched/sched_releasefiles.c)6
-rw-r--r--nuttx/sched/os_internal.h2
5 files changed, 75 insertions, 51 deletions
diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile
index d059152e0..c8fe7cf69 100644
--- a/nuttx/sched/Makefile
+++ b/nuttx/sched/Makefile
@@ -41,7 +41,7 @@ AOBJS = $(ASRCS:.S=$(OBJEXT))
MISC_SRCS = os_start.c os_bringup.c errno_getptr.c errno_get.c errno_set.c
MISC_SRCS += sched_garbage.c sched_setupstreams.c sched_getfiles.c sched_getsockets.c
MISC_SRCS += sched_getstreams.c sched_setupidlefiles.c sched_setuptaskfiles.c
-MISC_SRCS += sched_setuppthreadfiles.c sched_releasefiles.c
+MISC_SRCS += sched_setuppthreadfiles.c
TSK_SRCS = prctl.c task_create.c task_init.c task_setup.c task_activate.c
TSK_SRCS += task_start.c task_delete.c task_deletecurrent.c task_exithook.c
@@ -81,6 +81,7 @@ endif
endif
GRP_SRCS = group_create.c group_join.c group_leave.c group_find.c
+GRP_SRCS += group_releasefiles.c
ifeq ($(CONFIG_SCHED_HAVE_PARENT),y)
GRP_SRCS += task_reparent.c
diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h
index b78b38453..39d0a2b7c 100644
--- a/nuttx/sched/group_internal.h
+++ b/nuttx/sched/group_internal.h
@@ -127,6 +127,14 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group,
pid_t pid);
void group_removechildren(FAR struct task_group_s *group);
+/* File/network resources */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
+int group_releasefiles(FAR _TCB *tcb);
+#else
+# define group_releasefiles(t) (OK)
+#endif
+
#endif /* CONFIG_SCHED_CHILD_STATUS */
#endif /* CONFIG_SCHED_HAVE_PARENT */
diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c
index f5dca1829..158ba30b5 100644
--- a/nuttx/sched/group_leave.c
+++ b/nuttx/sched/group_leave.c
@@ -125,6 +125,64 @@ void group_remove(FAR struct task_group_s *group)
#endif
/*****************************************************************************
+ * Name: group_release
+ *
+ * Description:
+ * Release group resources after the last member has left the group.
+ *
+ * Parameters:
+ * group - The group to be removed.
+ *
+ * Return Value:
+ * None.
+ *
+ * Assumptions:
+ * Called during task deletion in a safe context. No special precautions
+ * are required here.
+ *
+ *****************************************************************************/
+
+static inline void group_release(FAR _TCB *tcb,
+ FAR struct task_group_s *group)
+{
+ /* Free all un-reaped child exit status */
+
+#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
+ group_removechildren(group);
+#endif
+
+ /* Free all file-related resources now. We really need to close files as
+ * soon as possible while we still have a functioning task.
+ */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
+ (void)group_releasefiles(tcb);
+#endif
+
+ /* Release all shared environment variables */
+
+#ifndef CONFIG_DISABLE_ENVIRON
+ env_release(tcb);
+#endif
+
+ /* Remove the group from the list of groups */
+
+ group_remove(group);
+
+ /* Release the members array */
+
+ if (group->tg_members)
+ {
+ sched_free(group->tg_members);
+ group->tg_members = NULL;
+ }
+
+ /* Release the group container itself */
+
+ sched_free(group);
+}
+
+/*****************************************************************************
* Public Functions
*****************************************************************************/
@@ -150,7 +208,6 @@ void group_remove(FAR struct task_group_s *group)
*****************************************************************************/
#ifdef HAVE_GROUP_MEMBERS
-
void group_leave(FAR _TCB *tcb)
{
FAR struct task_group_s *group;
@@ -171,31 +228,9 @@ void group_leave(FAR _TCB *tcb)
if (ret == 0)
{
- /* Release all of the resource contained within the group */
- /* Free all un-reaped child exit status */
-
-#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
- group_removechildren(tcb->group);
-#endif
- /* Free all file-related resources now. We really need to close
- * files as soon as possible while we still have a functioning task.
- */
-
-#if CONFIG_NFILE_DESCRIPTORS > 0
- (void)sched_releasefiles(tcb);
-#endif
- /* Release all shared environment variables */
+ /* Release all of the resource held by the task group */
-#ifndef CONFIG_DISABLE_ENVIRON
- env_release(tcb);
-#endif
- /* Remove the group from the list of groups */
-
- group_remove(group);
-
- /* Release the group container itself */
-
- sched_free(group);
+ group_release(tcb, group);
}
/* In any event, we can detach the group from the TCB so that we won't
@@ -232,27 +267,9 @@ void group_leave(FAR _TCB *tcb)
else
{
- /* Release all of the resource contained within the group */
- /* Free all un-reaped child exit status */
-
-#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
- group_removechildren(tcb->group);
-#endif
- /* Free all file-related resources now. We really need to close
- * files as soon as possible while we still have a functioning task.
- */
-
-#if CONFIG_NFILE_DESCRIPTORS > 0
- (void)sched_releasefiles(tcb);
-#endif
- /* Release all shared environment variables */
-
-#ifndef CONFIG_DISABLE_ENVIRON
- env_release(tcb);
-#endif
- /* Release the group container itself */
+ /* Release all of the resource held by the task group */
- sched_free(group);
+ group_release(tcb, group);
}
/* In any event, we can detach the group from the TCB so we won't do
diff --git a/nuttx/sched/sched_releasefiles.c b/nuttx/sched/group_releasefiles.c
index 4be92f4eb..40bf373b4 100644
--- a/nuttx/sched/sched_releasefiles.c
+++ b/nuttx/sched/group_releasefiles.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * sched/sched_releasefiles.c
+ * sched/group_releasefiles.c
*
* Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -55,7 +55,7 @@
****************************************************************************/
/****************************************************************************
- * Name: sched_releasefiles
+ * Name: group_releasefiles
*
* Description:
* Release file resources attached to a TCB. This file may be called
@@ -73,7 +73,7 @@
*
****************************************************************************/
-int sched_releasefiles(_TCB *tcb)
+int group_releasefiles(_TCB *tcb)
{
if (tcb)
{
diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h
index e3d0fd48f..5aa6487d0 100644
--- a/nuttx/sched/os_internal.h
+++ b/nuttx/sched/os_internal.h
@@ -105,7 +105,6 @@ enum os_crash_codes_e
# define sched_setupidlefiles(t) (OK)
# define sched_setuptaskfiles(t) (OK)
# define sched_setuppthreadfiles(t) (OK)
-# define sched_releasefiles(t) (OK)
#endif
/* One processor family supported by NuttX has a single, fixed hardware stack.
@@ -301,7 +300,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb);
#if CONFIG_NFILE_STREAMS > 0
int sched_setupstreams(FAR _TCB *tcb);
#endif
-int sched_releasefiles(FAR _TCB *tcb);
#endif
int sched_releasetcb(FAR _TCB *tcb);