Added checks for malloc'd memory.

Issue: 5