When realloc() succeeds but moves the block to a new address, what happens to the old block?
Correct answer D. It is freed automatically after its contents are copied
Explanation
realloc may resize in place or allocate a new block. If it moves, it copies the old contents up to the smaller of the old and new sizes and then frees the old block itself. Any pointers to the old block become invalid, and freeing the old pointer again is a double free. Extra bytes in a larger block are not initialised.
Answer checked How we write and check questions
Discussion