Handle malloc errors