Clean up the dynamically allocated memory