diff options
| author | tardigrade <[email protected]> | 2026-09-08 20:47:57 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-09-08 11:17:57 -0400 |
| commit | 29afcc394667660edd9e53cc17e6232b9e60aa96 (patch) | |
| tree | 8b1362c384d8df4ac48c6948dddc7d74fbf04d64 /common_modules/module_manager | |
| parent | b0ec8bfbb964a78e82c71b20bb6f79ef7597df32 (diff) | |
Fixed a kernel stack leak when deleting user-mode module threads (#692)
* modules: free kernel stack on thread deletion
Signed-off-by: Prashit Vora <[email protected]>
* 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 <[email protected]>
Co-authored-by: Frédéric Desbiens <[email protected]>
Assisted-by: Copilot (Opus 5) <[email protected]>
Diffstat (limited to 'common_modules/module_manager')
| -rw-r--r-- | common_modules/module_manager/inc/txm_module_manager_dispatch.h | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/common_modules/module_manager/inc/txm_module_manager_dispatch.h b/common_modules/module_manager/inc/txm_module_manager_dispatch.h index 03bd86eb..46536606 100644 --- a/common_modules/module_manager/inc/txm_module_manager_dispatch.h +++ b/common_modules/module_manager/inc/txm_module_manager_dispatch.h @@ -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); } |
