libgit2/libgit2 — pull request #1705 by arrbee (2013-07-03 19:41:46+00:00)
Title: Try harder not to double free index entries

The index isn't really thread safe, but we can easily be more careful and avoid double frees and the like, which are serious problems (as opposed to a lookup which might return the incorrect value but if the index in being updated, that is much harder to avoid).

This uses the atomic swap operation to get the index entry data and replace it will NULL before freeing the data. This should make sure that the data is only freed one time even if someone accidentally accesses the index from multiple threads.

This also makes `git_index_read_tree` only update the index contents after the tree traversal has created the new vector of index entries.

I plan on doing some other work soon on improving the index internals, but this is a small fix that should avoid the specific double-free problem.