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

Fix a recently introduced memory leak

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5568 42af7a65-404d-4744-a932-0658087f49c3
parent ff293217
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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 */
......
......@@ -124,6 +124,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
......
/****************************************************************************
* 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)
{
......
......@@ -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);
......
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