pack: free the new pack struct if we fail to insert

If we fail to insert the packfile in the map, make sure to free it.

This makes the free function only attempt to remove its mwindows from
the global list if we have opened the packfile to avoid accessing the
list unlocked.
tree: free in error conditions

As reported by coverity, we would leak some memory in error conditions.
pack: clean up error returns

Set a message when we fail to lock.

Also make the put function void, since it's called from free, which
cannot report errors. The only errors we can experience here are
internal state corruption, so we assert that we are trying to put a
pack which we have previously got.
Merge pull request #2442 from libgit2/cmn/leaks

Fix a couple of leaks
Improvements to git_transport extensibility

git_remote_set_transport now takes a transport factory rather than a transport
git_clone_options now allows the caller to set a transport factory
Change how git_clone_options customizes remotes