Heap usage error detected RCM4300


I work with a rabbit 4300 and Dynamic C 10.72.
My system is composed of slave boards which communicate with the rabbit board throught RS485 link.

Lot’s of data from these slave boards like voltages, current, temperatures, status, are displayed continusly 5 by 5 on a the embedded web site (each 2 seconds.

I’m working on a old software. As it’s very old, I noticed that some parts of my code could be optimized. that’s what I did.

Also I increased the numbers of slave boards and increase the number of variables, especially for the status of the slave cards.

I have the following runtime error sometimes when data are displayed from the slave boards on the embedded web site :
Run time error : Heap usage error detected
function : internal_realloc
line : 2724


I am a bit desperate but how can I solve this issue?

Best regards

You’ve probably corrupted some memory in the heap by writing beyond the boundary of some memory you’ve allocated. I don’t know the malloc library well, but there is probably a header before the allocated memory that’s been corrupted by a write to the previous region. If you can identify that region, you can focus on code related to writing there.

You could try enabling _MALLOC_PRINT_FAIL to see if you get useful information. In general, I’d recommend reading the comment at the start of malloc.lib and using that as a starting point to your debugging.

For example, you can specify your own CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION macros. Map those macros to your own functions (you’ll have to determine the data type for the parameters) where you print the parameters. If you make that function debuggable, you’ll be able to set a breakpoint and use Dynamic C to look at the call stack (to determine what function caused the error) but also to look at the contents of memory before the region you’re trying to reallocate.