mirror of
https://github.com/eclipse-threadx/threadx.git
synced 2026-10-06 06:59:08 +08:00
Fixed a kernel stack leak when deleting user-mode module threads (#692)
* modules: free kernel stack on thread deletion Signed-off-by: Prashit Vora <prashitvora2006@gmail.com> * Preserved the thread object release when the kernel stack cannot be freed Releasing the kernel stack ahead of the thread object made a failure of the kernel stack deallocation abort the thread object release. The thread had already been deleted at that point, so the thread object would have stayed allocated for the lifetime of the module. The thread object is now always released once the delete succeeds, and the kernel stack failure is reported only when it does not mask a thread object failure. --------- Signed-off-by: Prashit Vora <prashitvora2006@gmail.com> Co-authored-by: Frédéric Desbiens <frederic.desbiens@eclipse-foundation.org> Assisted-by: Copilot (Opus 5) <noreply@github.com>
This commit is contained in:
co-authored by
Frédéric Desbiens
parent
b0ec8bfbb9
commit
29afcc3946
@@ -8,6 +8,8 @@
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
// Some portions generated by Codex (GPT-5).
|
||||
// Some portions generated by Copilot (Opus 5).
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
@@ -2061,7 +2063,12 @@ ALIGN_TYPE return_value;
|
||||
static ALIGN_TYPE _txm_module_manager_tx_thread_delete_dispatch(TXM_MODULE_INSTANCE *module_instance, ALIGN_TYPE param_0)
|
||||
{
|
||||
|
||||
ALIGN_TYPE return_value;
|
||||
TX_THREAD *thread_ptr;
|
||||
ALIGN_TYPE return_value;
|
||||
ALIGN_TYPE stack_status;
|
||||
|
||||
thread_ptr = (TX_THREAD *) param_0;
|
||||
stack_status = (ALIGN_TYPE) TX_SUCCESS;
|
||||
|
||||
if (module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION)
|
||||
{
|
||||
@@ -2069,14 +2076,27 @@ ALIGN_TYPE return_value;
|
||||
return(TXM_MODULE_INVALID_MEMORY);
|
||||
}
|
||||
|
||||
return_value = (ALIGN_TYPE) _txe_thread_delete(
|
||||
(TX_THREAD *) param_0
|
||||
);
|
||||
return_value = (ALIGN_TYPE) _txe_thread_delete(thread_ptr);
|
||||
|
||||
/* Deallocate object memory. */
|
||||
/* Deallocate the kernel stack for a user-mode thread. */
|
||||
if ((return_value == TX_SUCCESS) &&
|
||||
(module_instance -> txm_module_instance_property_flags & TXM_MODULE_USER_MODE))
|
||||
{
|
||||
stack_status = _txm_module_manager_object_deallocate(thread_ptr -> tx_thread_module_kernel_stack_start);
|
||||
}
|
||||
|
||||
/* Deallocate thread object memory. This must be attempted even when the kernel
|
||||
stack could not be released, otherwise a successful thread delete would leave
|
||||
the thread object allocated forever. */
|
||||
if (return_value == TX_SUCCESS)
|
||||
{
|
||||
return_value = _txm_module_manager_object_deallocate((VOID *) param_0);
|
||||
return_value = _txm_module_manager_object_deallocate((VOID *) thread_ptr);
|
||||
|
||||
/* Report the kernel stack failure if the thread object was released. */
|
||||
if ((return_value == TX_SUCCESS) && (stack_status != TX_SUCCESS))
|
||||
{
|
||||
return_value = stack_status;
|
||||
}
|
||||
}
|
||||
return(return_value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user