Skip to content

Commit b50386c

Browse files
Kevin Willfordgitster
authored andcommitted
read-cache: fix memory leak in do_write_index
The previous_name_buf was never getting released when there was an error in ce_write_entry or allow was false and execution was returned to the caller. Signed-off-by: Kevin Willford <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3921a0b commit b50386c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

read-cache.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
21922192
int newfd = tempfile->fd;
21932193
git_SHA_CTX c;
21942194
struct cache_header hdr;
2195-
int i, err, removed, extended, hdr_version;
2195+
int i, err = 0, removed, extended, hdr_version;
21962196
struct cache_entry **cache = istate->cache;
21972197
int entries = istate->cache_nr;
21982198
struct stat st;
@@ -2247,15 +2247,21 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
22472247
if (allow)
22482248
warning(msg, ce->name);
22492249
else
2250-
return error(msg, ce->name);
2250+
err = error(msg, ce->name);
22512251

22522252
drop_cache_tree = 1;
22532253
}
22542254
if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
2255-
return -1;
2255+
err = -1;
2256+
2257+
if (err)
2258+
break;
22562259
}
22572260
strbuf_release(&previous_name_buf);
22582261

2262+
if (err)
2263+
return err;
2264+
22592265
/* Write extension data here */
22602266
if (!strip_extensions && istate->split_index) {
22612267
struct strbuf sb = STRBUF_INIT;

0 commit comments

Comments
 (0)