AnsweredAssumed Answered

MQX Resource Cleanup Concepts

Question asked by Michael Meier on Sep 6, 2013
Latest reply on Sep 11, 2013 by Martin Latal

I have spent some time chasing down an elusive bug. At the heart of the bug lies MQX resource cleanup.

 

I have opened an ADC converter file as well as a number of files for its associated channels in one task, called main_task. After main_task initialized all the hardware and software components, it returns. Upon this return, MQX freed the memory that the ADC driver allocated. This is because the ADC driver allocated the memory with _mem_alloc_zero, so not with a _mem_alloc_system_... function. Even though the ADC driver's memory is freed, the ADC driver is _not_ stopped. Its intterupt routine happily continues write A/D samples into its supposed buffer, which is now memory in the memory allocator's free list and might later become memory for some other part of the application. Ultimately, this led to the system crashing.

 

I don't understand MQX's double personality when it comes to resource cleanup on task end or destroy. Memory allocated with _mem_alloc_...(), not with _mem_alloc_system_...() is freed. This matches documentation. Mutexes initialized with _mutex_init() get cleaned up on _task_destroy() via _mutex_cleanup(). The ADC driver, however, does not get stopped or cleaned up on task destroy.

 

What are MQX's concepts when it comes to resource cleanup? Which resources can I expect to be cleaned up?

Outcomes