79150098

Date: 2024-11-02 06:45:01
Score: 0.5
Natty:
Report link

What will happen with old memory block place?

This question was not yet answered. The answer is simple, it is easy to check in your code. In my case, when realloc returns the same address (usually if I reduce the block size), calling free with old address produce no error, which is true since it is also a new address. When it returns different address, calling free with old address fails.

So, it does free the old block when it is reallocated:

void* location = realloc(arr, NEW_SIZE);
// do not delete arr, it points to the same or freed block
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): What
  • Low reputation (0.5):
Posted by: dmitrycello