Check for null pointer on malloc.
Fix code typo.