Avoiding harmful memcpy call if the allocation failed. Resetting the size which avoids further harmful freeing invalid pointer. Closer to the comment behavior description.