Make sure to free some memory when exceptions occur.
 - Fixes #146