...
The realloc()
function deallocates the old object pointed to by ptr and returns a pointer to a new object that has the size specified by of a specified size. If memory for the new object cannot be allocated, the realloc()
function does not deallocate the old object and its value is unchanged. If the realloc() function returns NULL, failing to free the original memory will result in a memory leak. As a result, the following idiom is generally recommended for reallocating memory:
...