Skip to content

Commit 915e44c

Browse files
stefanbellergitster
authored andcommitted
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: Junio C Hamano <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 067178e commit 915e44c

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

read-cache.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,9 @@ struct cache_entry *make_cache_entry(unsigned int mode,
748748
ce->ce_mode = create_ce_mode(mode);
749749

750750
ret = refresh_cache_entry(ce, refresh_options);
751-
if (!ret) {
751+
if (ret != ce)
752752
free(ce);
753-
return NULL;
754-
} else {
755-
return ret;
756-
}
753+
return ret;
757754
}
758755

759756
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)

0 commit comments

Comments
 (0)