From: René Scharfe Date: Sun, 9 Jun 2013 17:39:18 +0000 (+0200) Subject: read-cache: free cache in discard_index X-Git-Tag: v1.8.3.4~33^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a0fc4db01dfa69d836dc6f24218974a674ec29ac;p=thirdparty%2Fgit.git read-cache: free cache in discard_index discard_cache doesn't have to free the array of cache entries, because the next call of read_cache can simply reuse it, as they all operate on the global variable the_index. discard_index on the other hand does have to free it, because it can be used e.g. with index_state variables on the stack, in which case a missing free would cause an unrecoverable leak. This patch releases the memory and removes a comment that was relevant for discard_cache but has become outdated. Since discard_cache is just a wrapper around discard_index nowadays, we lose the optimization that avoids reallocation of that array within loops of read_cache and discard_cache. That doesn't cause a performance regression for me, however (HEAD = this patch, HEAD^ = master + p0002): Test // HEAD^ HEAD ---------------\\----------------------------------------------------- 0002.1: read_ca// 1000 times 0.62(0.58+0.04) 0.61(0.58+0.02) -1.6% Suggested-by: Felipe Contreras Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- diff --git a/read-cache.c b/read-cache.c index 04ed561bfe..4245f8ef30 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1518,8 +1518,9 @@ int discard_index(struct index_state *istate) free_name_hash(istate); cache_tree_free(&(istate->cache_tree)); istate->initialized = 0; - - /* no need to throw away allocated active_cache */ + free(istate->cache); + istate->cache = NULL; + istate->cache_alloc = 0; return 0; }