Sep 5, 2013 at 4:12am UTC
Can some explain me how this code disturbs the memory partition blocks
char* p = (char*) malloc(100);
free(p) // I am getting error here that next block of memory was over written.
Sep 5, 2013 at 4:53am UTC
Its true, but when ever the allocated memory is getting freed that time we are getting error, it say that next block of memory is corrupted. can you suggest some good links to understand the memory partitioning.
Sep 5, 2013 at 5:16am UTC
It's implementation defined, based on OS. There's tons of different malloc implementations. Although, it shouldn't really matter to your application.
Sep 5, 2013 at 10:30am UTC
when ever the allocated memory is getting freed that time we are getting error, it say that next block of memory is corrupted
That's because the heap's been corrupted earlier, either with a buffer overrun or reusing a free'd block. The code you posted is fine, apart from the missing check for NULL.
EDIT: Didn't notice the 100 byte allocation, and 200 byte write. Well, there's your buffer overwrite.
Last edited on
Sep 5, 2013 at 2:47pm UTC