Fix memory management concerning libgit2 structures