Content originally posted in LPCWare by CodeRedSupport on Mon Jun 17 03:15:25 MST 2013
Quote: Lumos
Hello,
I am using LPCXpresso v5.2.2 [Build 2108].
I am trying to use realloc function from stdlib.h (Redlib - semihost).
For test I am calling this part of code in the loop:
void* ptr1 = NULL;
void* ptr2 = NULL;
ptr1 = realloc(NULL, 300);
ptr2 = realloc(ptr1, 301);
//free(ptr1);
free(ptr2);
When deallocation of ptr1 is commented-out, code crashes very soon.
But, in case free(ptr1); is commented, code is running without any crash.
From description of realloc function, old space should be deallocated automatically, but from this test it looks different. Manual deallocation is needed.
It looks like you are correct - Redlib's realloc is not releasing memory correctly. We'll investigate for fixing in a future LPCXpresso release.
Regards,
CodeRedSupport