This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to handle _free_box() failure?

Hello - we're using RL-ARM RTX on an STM32F105 based product, and passing messages between tasks in our system strictly via mailboxes and memory pools, using _alloc_box() and _free_box() to obtain and release messages.

Occasionally we see _free_box() return a failure value. Is there a recommended best practice for handling this? Clearly we do need to return that memory to the pool - without a better solution, I might loop trying repeated calls to _free_box() with delays in between. The examples I've seen online don't suggest what a failure might indicate, or what the recommended way to handle them is.

Or does this suggest there might be some problem with the memory pool itself, and the most appropriate fix might be elsewhere?

Thanks for any tips!

  • Hi,
    you should check if the pointer to the memory you try to free is valid. It may be, that the pointer gets corrupted.

    If possible, add some code to trace memory allocations and freeings, including the addresses, of the allocated/freed memory.

    Regards

  • The examples I've seen online don't suggest what a failure might indicate, or what the recommended way to handle them is.

    _free_box attempts to determine whether the memory you're trying to free actually belongs to the memory block you're trying to free it from. It fails if it thinks it doesn't.

    I would think the most likely cause of the problem is a bug in your code - as such, I guess you know what the recommended approach is...

  • OK, great to know about the specific failure reasons. Definitely helps guide my approach - thanks very much!