Home/Support/Support Forum/Heap usage error detected
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Heap usage error detected

0 votes
Hello,
I work with a RCM6700 and Dynamic C 10.72.

I have the following runtime error although my program is not using any dynamic allocation.

Run time error : Heap usage error detected
file : MALLOC.LIB
function : mspace_free
line : 3313

My program uses root and xmem storage and I suspect that some line of code is updating root memory while I intend to update xmem or vice versa.

When I get the runtime error DC crashes and I cannot go back and find out how my program got there. How can I debug this situation to itendify the faulty line(s) of code(s)?

Thanks,
Massimo
asked Jun 10, 2016 in Rabbit Software by MassimoP New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

+1 vote
These things are always difficult to track down as the offending code may have done its work long before the call to mspace_free().

You could try enabling debug in malloc.lib and putting a break point on the error detection code in mspace_free(). It might be possible to look at the memory block where the error occurred to determine where the corruption came from.

One thing that helps with DC 10.72 (and earlier DC 10 versions) is the support for far pointers and far data which makes it easier to allocate variables in different areas of memory without having to manually move data between xmem and root. Much of the time you don't have to think about it unless you are trying to reduce code size or speed up some operations by explicitly placing data in root memory.

You might look at defining the USAGE_ERROR_ACTION macro to call some of your own code to do some post mortem dumps etc when the memory error occurs.

Regards,
Peter
answered Jun 11, 2016 by petermcs Veteran of the Digi Community (1,130 points)
...