Fix handling malloc returning NULL