Added malloc error checking.
Merge pull request #23 from jan-schreib/malloc-error-checking

Added malloc error checking.