Fixing memory leaks when git errors occur