Added malloc error checking.

As mentioned in #15, I added error checking for all mallocs.