From 6992a8f4cc9549e673fc3dfebe8f6db1eb83f8fd Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 29 Dec 2022 08:49:03 +0900 Subject: [PATCH] sched: group: Fix memory corruption in group_leave.c Summary: - I noticed that nxplayer (HTTP audio streaming) + command execution via telnet sometimes causes memory corruption. See https://github.com/apache/nuttx/pull/7947 for the detail. - This commit fixes this issue by calling lib_stream_release() before lib_stream_release() in group_leave.c Impact: - Should be none Testing: - Tested with spresense:wifi_smp Signed-off-by: Masayuki Ishikawa --- sched/group/group_leave.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 4ab8cf06dc4..2b1d11fdc0e 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -156,6 +156,12 @@ static inline void group_release(FAR struct task_group_s *group) pthread_release(group); #endif +#ifdef CONFIG_FILE_STREAM + /* Free resource held by the stream list */ + + lib_stream_release(group); +#endif /* CONFIG_FILE_STREAM */ + /* Free all file-related resources now. We really need to close files as * soon as possible while we still have a functioning task. */ @@ -164,12 +170,6 @@ static inline void group_release(FAR struct task_group_s *group) files_releaselist(&group->tg_filelist); -#ifdef CONFIG_FILE_STREAM - /* Free resource held by the stream list */ - - lib_stream_release(group); -#endif /* CONFIG_FILE_STREAM */ - #ifndef CONFIG_DISABLE_ENVIRON /* Release all shared environment variables */