local transport: catch double-opens

Combinations of connect + fetch can call local_open multiple
times. Detect this and skip the initialization stage.
commit: simplify and correct refcounting in nth_gen_ancestor

We can make use of git_object_dup to use refcounting instead of pointer
comparison to make sure we don't free the caller's object.

This also lets us simplify the case for '~0' which is now just an
assignment instead of looking up the object we have at hand.
branch: fix leak when checking against HEAD

We look up a reference in order to figure out if it's the current
branch, which we need to free once we're done with the check.

As a bonus, only perform the check when we're passed the force flag, as
it's a useless check otherwise.
Plug a few leaks in the tests
Merge pull request #2169 from libgit2/valgrind

Plug leaks