Clean up and check if calloc succeeded.