mktree: plug per-tree leak in --batch mode
In --batch mode "git mktree" reuses its entry buffer across trees, resetting `used` to 0 after writing each tree. It never frees the `treeent` structures the previous tree appended, though, so once the next tree overwrites those slots the earlier allocations are leaked. A single-tree invocation hides this, as the entries stay reachable through the `entries` global until exit. Free each entry when resetting the buffer, and free the buffer itself before returning. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>seen
parent
b6f5e80fdf
commit
6272f3bd17
|
|
@ -200,8 +200,11 @@ int cmd_mktree(int ac,
|
|||
puts(oid_to_hex(&oid));
|
||||
fflush(stdout);
|
||||
}
|
||||
for (int i = 0; i < used; i++)
|
||||
free(entries[i]);
|
||||
used=0; /* reset tree entry buffer for re-use in batch mode */
|
||||
}
|
||||
free(entries);
|
||||
strbuf_release(&sb);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue