threadx icon indicating copy to clipboard operation
threadx copied to clipboard

Threadx modules kernel stack memory leakage

Open amgross opened this issue 1 year ago • 1 comments

Describe the bug tx_thread_module_kernel_stack_start is allocated at _txm_module_manager_thread_create from the object pool, but is not released at thread delete function (it is deleted upon module stop when all objects of the module are deleted)

To Reproduce Run from module:

    while(1)
    {
		status = txm_module_object_allocate(<thread_ptr>, sizeof(TX_THREAD));
		assert(TX_SUCCESS == status);

		status = tx_thread_create(<thread_ptr>, "my thread", <my_thread_func>, 0, <stack_ptr>,
                <stack size>, <priority>, <priority>, <time slice>, TX_DONT_START);
		assert(TX_SUCCESS == status);

		status = tx_thread_terminate(<thread_ptr>);
		assert(TX_SUCCESS == status);

		// This system call deallocating also <thread_ptr>, so will need to allocate it afterward
		tx_thread_delete(<thread_ptr>);
		assert(TX_SUCCESS == status);
    }

Expected behavior tx_thread_module_kernel_stack_start should be released upon thread delete.

Impact Can leak object pool out of memory, which cause no more option to create OS objects from module

Logs and console output

Additional context

amgross avatar Jul 29 '24 05:07 amgross

Workaround: add to tx_port.h (or tx_user.h)

extern UINT  _txm_module_manager_object_deallocate(VOID *object_ptr);
#define TX_THREAD_DELETE_PORT_COMPLETION(t) _txm_module_manager_object_deallocate(t -> tx_thread_module_kernel_stack_start);

amgross avatar Jul 29 '24 10:07 amgross

Anyone in @eclipse-threadx/iot-threadx-contributors willing to tackle this one?

fdesbiens avatar Feb 27 '25 14:02 fdesbiens

@eclipse-threadx/iot-threadx-committers and @eclipse-threadx/iot-threadx-contributors: Please provide your feedback.

fdesbiens avatar Mar 19 '25 18:03 fdesbiens

Agree with @amgross' workaround for now while we figure out a proper fix.

yuxinzhou5 avatar Apr 08 '25 06:04 yuxinzhou5

please provide the SNMP configurations with Azzure rtos (netxduo) im confusing about configurations , please help me anybody

sravani-25-03-2003 avatar Apr 19 '25 07:04 sravani-25-03-2003

@fdesbiens @amgross @yuxinzhou5 @sravani-25-03-2003 I would like to take this issue up. Can anyone please point out where these changes need to be made?

DrBinary9 avatar Sep 16 '25 18:09 DrBinary9