Commit 915e44c6 authored by Stefan Beller's avatar Stefan Beller Committed by Junio C Hamano

read-cache: fix memleak

`ce` is allocated in make_cache_entry and should be freed if it is not
used any more. refresh_cache_entry as a wrapper around refresh_cache_ent
will either return

 - the `ce` given as the parameter, when it was up-to-date;
 - a new updated cache entry which is allocated to new memory; or
 - a NULL when refreshing failed.

In the latter two cases, the original cache-entry `ce` is not used
and needs to be freed.  The rule can be expressed as "if the return
value from refresh is different from the original ce, ce is no
longer used."
Helped-by: default avatarJunio C Hamano <[email protected]>
Signed-off-by: Stefan Beller's avatarStefan Beller <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 067178ed
......@@ -748,12 +748,9 @@ struct cache_entry *make_cache_entry(unsigned int mode,
ce->ce_mode = create_ce_mode(mode);
ret = refresh_cache_entry(ce, refresh_options);
if (!ret) {
if (ret != ce)
free(ce);
return NULL;
} else {
return ret;
}
return ret;
}
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment