The way you're handling exceptions here and over the next few lines leaks memory in case an error is returned from the libgit2 api calls.