add missing null pointer check after malloc