diff --git a/libc/misc/lib_stream.c b/libc/misc/lib_stream.c index f152157236..2ad3cd740e 100644 --- a/libc/misc/lib_stream.c +++ b/libc/misc/lib_stream.c @@ -162,14 +162,14 @@ void lib_stream_release(FAR struct task_group_s *group) if (list->sl_streams[i].fs_bufstart) { -#ifndef CONFIG_ARCH_ADDRENV +#ifndef CONFIG_BUILD_KERNEL /* Release memory from the user heap */ sched_ufree(list->sl_streams[i].fs_bufstart); #else /* If the exiting group is unprivileged, then it has an address * environment. Don't bother to release the memory in this case... - * There is no point sense the memory lies in the user heap which + * There is no point since the memory lies in the user heap which * will be destroyed anyway. But if this is a privileged group, * when we still have to release the memory using the kernel * allocator. @@ -177,7 +177,7 @@ void lib_stream_release(FAR struct task_group_s *group) if ((group->tg_flags & GROUP_FLAG_PRIVILEGED) != 0) { - sched_ufree(list->sl_streams[i].fs_bufstart); + sched_kfree(list->sl_streams[i].fs_bufstart); } #endif } diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index bcf9e1daeb..6b44ba68a0 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -230,15 +230,39 @@ static inline void group_release(FAR struct task_group_s *group) } #endif -#if CONFIG_NFILE_STREAMS > 0 && (defined(CONFIG_BUILD_PROTECTED) || \ - defined(CONFIG_BUILD_KERNEL)) && defined(CONFIG_MM_KERNEL_HEAP) - +#if CONFIG_NFILE_STREAMS > 0 && defined(CONFIG_MM_KERNEL_HEAP) /* In a flat, single-heap build. The stream list is part of the - * group structure. But in a kernel build with a kernel allocator, it - * must be separately de-allocated user the user-space deallocator. + * group structure and, hence will be freed when the group structure + * is freed. Otherwise, it is separately allocated an must be + * freed here. + */ + +# if defined(CONFIG_BUILD_PROTECTED) + /* In the protected build, the task's stream list is always allocated + * and freed from the single, global user allocator. */ sched_ufree(group->tg_streamlist); + +# elif defined(CONFIG_BUILD_KERNEL) + /* In the kernel build, the unprivileged process' stream list will be + * allocated from with its per-process, private user heap. But in that + * case, there is no reason to do anything here: That allocation resides + * in the user heap which which be completely freed when we destroy the + * process' address environment. + */ + + if ((group->tg_flags & GROUP_FLAG_PRIVILEGED) != 0) + { + /* But kernel threads are different in this build configuration: Their + * stream lists were allocated from the common, global kernel heap and + * must explicitly freed here. + */ + + sched_kfree(group->tg_streamlist); + } + +# endif #endif /* Release the group container itself */