Skip to content

Commit b4e8fef

Browse files
committed
Merge branch 'sb/plug-leak-in-make-cache-entry'
"update-index --refresh" used to leak when an entry cannot be refreshed for whatever reason. * sb/plug-leak-in-make-cache-entry: read-cache.c: free cache entry when refreshing fails
2 parents be94b33 + bc1c2ca commit b4e8fef

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

read-cache.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
725725
unsigned int refresh_options)
726726
{
727727
int size, len;
728-
struct cache_entry *ce;
728+
struct cache_entry *ce, *ret;
729729

730730
if (!verify_path(path)) {
731731
error("Invalid path '%s'", path);
@@ -742,7 +742,13 @@ struct cache_entry *make_cache_entry(unsigned int mode,
742742
ce->ce_namelen = len;
743743
ce->ce_mode = create_ce_mode(mode);
744744

745-
return refresh_cache_entry(ce, refresh_options);
745+
ret = refresh_cache_entry(ce, refresh_options);
746+
if (!ret) {
747+
free(ce);
748+
return NULL;
749+
} else {
750+
return ret;
751+
}
746752
}
747753

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

0 commit comments

Comments
 (0)