In any code you write which dynamically allocates memory, you have 2 responsibilities regarding any block of memory allocated: (1) always preserve a pointer to the starting address for the block of memory so, (2) it can be freed when it is no longer needed. Freeing the memory is up to you.
If you assign a new block of memory to a pointer that currently points to an existing block of memory without first freeing the block, you have just overwritten the starting address for the original block of memory held by the pointer (violating rule 1 above) and you have now lost the ability to free the original block -- which is your memory leak.