Added malloc error checking.

As mentioned in #15, I added error checking for all mallocs.
Why *headers? Shouldn't it just be headers?