jean-marc wrote on Monday, October 07, 2019:
Hi everyone,
I have have modified the ethernet library for STM32 in the Arduino environment, to make it multitasking-friendly. I am facing a problem with memory leaks, because of the following mechanism:
On initialization I create a recursive mutex that protects the SPI communication with the W5X00 ethernet chip.
When an timeout or other spurious disconnection occur, I exit any loop I can be in, and go back to the initialisation phase of the ethernet chip to attempt a new connection.
However, I am realizing that doing so does not free the memory that was allocated when the mutex was created.
I could not find any API function to destroy an existing mutex.
Actually, if such a function existed, it would not work for me since I have compiled my project using the lightest heap allocation source file, that cannot free the already allocated memory.
So I would rather like, when initializing my ethernet connection, to check wether the recursive mutex already exists. This is easy, as if the variable that points to the mutex is not null, it means that a mutex had already be created. I can then merely reuse it.
However, I am unsure of the nesting level of the mutex at this time, though I took care to Give the,mutex back before exiting any function that has a TakeRecursiveMutex. However, I would like to ensure that the mutex is reinitialized. I thought of adding a loop containing a GiveRecursiveMutex based of the current recursion count of the mutex, but I did not find the appropriate function to get this number.
How can I do? Or is there another way to handle this mechanism?
Thanks in advance.
JM