Heap_4 allocation failure when allocating from fwrite/fopen


I’m using heap_4 management scheme, and used a patch to route dynamic allocations using malloc, to be allocated through pvportmalloc.
In one of the functions I have calls to fopen, fwrite, fread where the allocation doesn’t succeed even though I have sufficient memory available, I allocated the same amount of elements with the same size in a different function (regular dynamic allocation, not through fopen, fwrite, etc.) and the allocations succeed (I also allocated in the same function and it succeeds)
Can you advise on what could be the cause of this issue and how to solve it? thank you!
Attached: first photo - failed allocations
second photo: successful allocations in the same function
Third photo: successful allocations in a different function

p.s: please ignore the next variable, I didn’t set it when I saved the info in the array (I first created a linked list to track allocated blocks, through the address and size, and came upon this issue, I changed to a static array to verify the problem isn’t in the linked list management).

Thank you!

Can you place a breakpoint in pvPortMalloc to verify that it is called and if so, why is it failing?

Hello Gaurav,

Issue is solved! the problem was not routing the free() function also to vPortFree(). fwrite(), fopen(), etc. allocate and deallocate dynamically internally and I was tracking their allocations and not their deallocations also.

Thank you

1 Like

Thank you for reporting back!