indexer: properly free the packfile resources

The indexer needs to call the packfile's free function so it takes care of
freeing the caches.

We still need to close the mwf descriptor manually so we can rename the
packfile into its final name on Windows.
tests: plug leaks
pack: fixes to the cache

The offset should be git_off_t, and we should check the return value
of the mutex lock function.
checkout: Teach checkout to cope with orphaned Head

Fix #1236
Fix Travis compilation warnings