libgit2/libgit2 — pull request #1176 by arrbee (2012-12-28 06:35:08+00:00)
Title: Alternative fix for iterator memory leak

An earlier change to `git_diff_from_iterators` introduced a memory leak where the allocated spoolandsort iterator was not returned to the caller and thus not freed.

PR #1165 proposes changing some iterator APIs to use `git_iterator**` so we can reallocate the iterator at will, but that seems unexpected.

Instead, this makes it so that an iterator can be changed in place. The callbacks are isolated in a separate structure and a pointer to that structure can be reassigned by the spoolandsort extension.

This means that spoolandsort doesn't create a new iterator; it just allocates a new block of callbacks (along with space for its own extra data) and swaps that into the iterator.

Additionally, since spoolandsort is only needed to switch the case sensitivity of an iterator, this simplifies the API to only take the `ignore_case` boolean and to be a no-op if the iterator already matches the requested case sensitivity.