Fix various problems found while using the library

Biggest ones are the memory leaks and the EXC_BAD_ACCESS on corrupted archives.

Sorry for the size of the pull request, I can split it by fix if you prefer.