Check mallocs, propagate error to caller.
Merge pull request #2 from scolphoy/master

Check mallocs, propagate error to caller.