aboutsummaryrefslogtreecommitdiffstats
path: root/match-trees.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-05 12:09:36 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-05 08:49:12 -0700
commit2a0147089151e3dd2cc8e6c91ecaf45fb416630e (patch)
treec785edacde8afbf34fb02e56caccdf19e243f3be /match-trees.c
parentbuiltin/fmt-merge-msg: fix leaking buffers (diff)
downloadgit-2a0147089151e3dd2cc8e6c91ecaf45fb416630e.tar.gz
git-2a0147089151e3dd2cc8e6c91ecaf45fb416630e.zip
match-trees: fix leaking prefixes in `shift_tree()`
In `shift_tree()` we allocate two empty strings that we end up passing to `match_trees()`. If that function finds a better match it will update these pointers to point to a newly allocated strings, freeing the old strings. We never free the final results though, neither the ones we have allocated ourselves, nor the one that `match_trees()` might've returned to us. Fix the resulting memory leaks by creating a common exit path where we free them. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'match-trees.c')
-rw-r--r--match-trees.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/match-trees.c b/match-trees.c
index f17c74d483..147b03abf1 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -294,18 +294,22 @@ void shift_tree(struct repository *r,
unsigned short mode;
if (!*del_prefix)
- return;
+ goto out;
if (get_tree_entry(r, hash2, del_prefix, shifted, &mode))
die("cannot find path %s in tree %s",
del_prefix, oid_to_hex(hash2));
- return;
+ goto out;
}
if (!*add_prefix)
- return;
+ goto out;
splice_tree(hash1, add_prefix, hash2, shifted);
+
+out:
+ free(add_prefix);
+ free(del_prefix);
}
/*