Fix some memory leaks

Please review, I'm unsure about two maybe required memset's.

There are still some more possible leaks caused by GITERR_CHECK_ALLOC (see issue #1754).