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.
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.