Git fork

wt-status: fix leaking buffer with sparse directories

When hitting a sparse directory in `wt_status_collect_changes_initial()`
we use a `struct strbuf` to assemble the directory's name. We never free
that buffer though, causing a memory leak.

Fix the leak by releasing the buffer. While at it, move the buffer
outside of the loop and reset it to save on some wasteful allocations.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
666643fa c7584168

+6 -1
+1
t/t1092-sparse-checkout-compatibility.sh
··· 5 5 GIT_TEST_SPLIT_INDEX=0 6 6 GIT_TEST_SPARSE_INDEX= 7 7 8 + TEST_PASSES_SANITIZE_LEAK=true 8 9 . ./test-lib.sh 9 10 10 11 test_expect_success 'setup' '
+5 -1
wt-status.c
··· 717 717 static void wt_status_collect_changes_initial(struct wt_status *s) 718 718 { 719 719 struct index_state *istate = s->repo->index; 720 + struct strbuf base = STRBUF_INIT; 720 721 int i; 721 722 722 723 for (i = 0; i < istate->cache_nr; i++) { ··· 735 736 * expanding the trees to find the elements that are new in this 736 737 * tree and marking them with DIFF_STATUS_ADDED. 737 738 */ 738 - struct strbuf base = STRBUF_INIT; 739 739 struct pathspec ps = { 0 }; 740 740 struct tree *tree = lookup_tree(istate->repo, &ce->oid); 741 741 ··· 743 743 ps.has_wildcard = 1; 744 744 ps.max_depth = -1; 745 745 746 + strbuf_reset(&base); 746 747 strbuf_add(&base, ce->name, ce->ce_namelen); 747 748 read_tree_at(istate->repo, tree, &base, 0, &ps, 748 749 add_file_to_list, s); 750 + 749 751 continue; 750 752 } 751 753 ··· 772 774 s->committable = 1; 773 775 } 774 776 } 777 + 778 + strbuf_release(&base); 775 779 } 776 780 777 781 static void wt_status_collect_untracked(struct wt_status *s)