Skip to content

Commit 16bfbe6

Browse files
committed
Merge branch 'jn/maint-plug-leak' into maint
* jn/maint-plug-leak: write-tree: Avoid leak when index refers to an invalid object read-tree: stop leaking tree objects core: Stop leaking ondisk_cache_entrys
2 parents 316fa40 + b6b56ac commit 16bfbe6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

cache-tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ static int update_one(struct cache_tree *it,
328328
mode = ce->ce_mode;
329329
entlen = pathlen - baselen;
330330
}
331-
if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
331+
if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
332+
strbuf_release(&buffer);
332333
return error("invalid object %06o %s for '%.*s'",
333334
mode, sha1_to_hex(sha1), entlen+baselen, path);
335+
}
334336

335337
if (ce->ce_flags & CE_REMOVE)
336338
continue; /* entry being removed */

read-cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
15161516
int size = ondisk_ce_size(ce);
15171517
struct ondisk_cache_entry *ondisk = xcalloc(1, size);
15181518
char *name;
1519+
int result;
15191520

15201521
ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
15211522
ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
@@ -1539,7 +1540,9 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
15391540
name = ondisk->name;
15401541
memcpy(name, ce->name, ce_namelen(ce));
15411542

1542-
return ce_write(c, fd, ondisk, size);
1543+
result = ce_write(c, fd, ondisk, size);
1544+
free(ondisk);
1545+
return result;
15431546
}
15441547

15451548
int write_index(struct index_state *istate, int newfd)

unpack-trees.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
329329
{
330330
int i, ret, bottom;
331331
struct tree_desc t[MAX_UNPACK_TREES];
332+
void *buf[MAX_UNPACK_TREES];
332333
struct traverse_info newinfo;
333334
struct name_entry *p;
334335

@@ -346,12 +347,16 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
346347
const unsigned char *sha1 = NULL;
347348
if (dirmask & 1)
348349
sha1 = names[i].sha1;
349-
fill_tree_descriptor(t+i, sha1);
350+
buf[i] = fill_tree_descriptor(t+i, sha1);
350351
}
351352

352353
bottom = switch_cache_bottom(&newinfo);
353354
ret = traverse_trees(n, t, &newinfo);
354355
restore_cache_bottom(&newinfo, bottom);
356+
357+
for (i = 0; i < n; i++)
358+
free(buf[i]);
359+
355360
return ret;
356361
}
357362

0 commit comments

Comments
 (0)