mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-30 21:43:34 +08:00
Fix a recently introduced memory leak
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5568 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -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 = 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_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_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 = 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
|
TSK_SRCS += task_start.c task_delete.c task_deletecurrent.c task_exithook.c
|
||||||
@@ -81,6 +81,7 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
GRP_SRCS = group_create.c group_join.c group_leave.c group_find.c
|
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)
|
ifeq ($(CONFIG_SCHED_HAVE_PARENT),y)
|
||||||
GRP_SRCS += task_reparent.c
|
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);
|
pid_t pid);
|
||||||
void group_removechildren(FAR struct task_group_s *group);
|
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_CHILD_STATUS */
|
||||||
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
||||||
|
|
||||||
|
|||||||
+62
-45
@@ -124,6 +124,64 @@ void group_remove(FAR struct task_group_s *group)
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
* Public Functions
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@@ -150,7 +208,6 @@ void group_remove(FAR struct task_group_s *group)
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
#ifdef HAVE_GROUP_MEMBERS
|
||||||
|
|
||||||
void group_leave(FAR _TCB *tcb)
|
void group_leave(FAR _TCB *tcb)
|
||||||
{
|
{
|
||||||
FAR struct task_group_s *group;
|
FAR struct task_group_s *group;
|
||||||
@@ -171,31 +228,9 @@ void group_leave(FAR _TCB *tcb)
|
|||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
/* Release all of the resource contained within the group */
|
/* Release all of the resource held by the task group */
|
||||||
/* Free all un-reaped child exit status */
|
|
||||||
|
|
||||||
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
group_release(tcb, group);
|
||||||
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
|
|
||||||
/* Remove the group from the list of groups */
|
|
||||||
|
|
||||||
group_remove(group);
|
|
||||||
|
|
||||||
/* Release the group container itself */
|
|
||||||
|
|
||||||
sched_free(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In any event, we can detach the group from the TCB so that we won't
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
/* Release all of the resource contained within the group */
|
/* Release all of the resource held by the task group */
|
||||||
/* Free all un-reaped child exit status */
|
|
||||||
|
|
||||||
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
group_release(tcb, group);
|
||||||
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 */
|
|
||||||
|
|
||||||
sched_free(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In any event, we can detach the group from the TCB so we won't do
|
/* In any event, we can detach the group from the TCB so we won't do
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/sched_releasefiles.c
|
* sched/group_releasefiles.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: sched_releasefiles
|
* Name: group_releasefiles
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Release file resources attached to a TCB. This file may be called
|
* 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)
|
if (tcb)
|
||||||
{
|
{
|
||||||
@@ -105,7 +105,6 @@ enum os_crash_codes_e
|
|||||||
# define sched_setupidlefiles(t) (OK)
|
# define sched_setupidlefiles(t) (OK)
|
||||||
# define sched_setuptaskfiles(t) (OK)
|
# define sched_setuptaskfiles(t) (OK)
|
||||||
# define sched_setuppthreadfiles(t) (OK)
|
# define sched_setuppthreadfiles(t) (OK)
|
||||||
# define sched_releasefiles(t) (OK)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* One processor family supported by NuttX has a single, fixed hardware stack.
|
/* 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
|
#if CONFIG_NFILE_STREAMS > 0
|
||||||
int sched_setupstreams(FAR _TCB *tcb);
|
int sched_setupstreams(FAR _TCB *tcb);
|
||||||
#endif
|
#endif
|
||||||
int sched_releasefiles(FAR _TCB *tcb);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int sched_releasetcb(FAR _TCB *tcb);
|
int sched_releasetcb(FAR _TCB *tcb);
|
||||||
|
|||||||
Reference in New Issue
Block a user