Added malloc error checking.

As mentioned in #15, I added error checking for all mallocs.
Yes, you are right. My mistake. I'll fix that.