[PATCH v5 08/36] read-cache: plug a few leaks
- From
Felipe Contreras <felipe.contreras@gmail.com>
- Date
- Jun 9, 2013, 19:24 UTC
- Message-ID
- <1370805890-3453-9-git-send-email-felipe.contreras@gmail.com>
- In-Reply-To
- <1370805890-3453-1-git-send-email-felipe.contreras@gmail.com>
We are not freeing 'istate->cache' properly.
We can't rely on 'initialized' to keep track of the 'istate->cache', because it doesn't really mean it's initialized. So assume it always has data, and free it before overwriting it.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- read-cache.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/read-cache.c b/read-cache.c index 5e30746..a1dd04d 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1451,6 +1451,7 @@ int read_index_from(struct index_state *istate, const char *path) istate->version = ntohl(hdr->hdr_version); istate->cache_nr = ntohl(hdr->hdr_entries); istate->cache_alloc = alloc_nr(istate->cache_nr); + free(istate->cache); istate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache)); istate->initialized = 1; @@ -1512,6 +1513,9 @@ int discard_index(struct index_state *istate) for (i = 0; i < istate->cache_nr; i++) free(istate->cache[i]); + free(istate->cache); + istate->cache = NULL; + istate->cache_alloc = 0; resolve_undo_clear_index(istate); istate->cache_nr = 0; istate->cache_changed = 0;
-- 1.8.3.698.g079b096