summaryrefslogtreecommitdiffstats
path: root/refspec.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-09-24 23:57:40 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-25 19:24:54 +0200
commitea4780307cc5007c6136ed216d45841d21ccfe75 (patch)
tree365db66aec7fabb4de7b6182ac0a7571b0e543a6 /refspec.c
parenttransport-helper: fix strbuf leak in push_refs_with_push() (diff)
downloadgit-ea4780307cc5007c6136ed216d45841d21ccfe75.tar.xz
git-ea4780307cc5007c6136ed216d45841d21ccfe75.zip
fetch: free "raw" string when shrinking refspec
The "--prefetch" option to git-fetch modifies the default refspec, including eliminating some entries entirely. When we drop an entry we free the strings in the refspec_item, but we forgot to free the matching string in the "raw" array of the refspec struct. There's no behavioral bug here (since we correctly shrink the raw array, too), but we're leaking the allocated string. Let's add in the leak-fix, and while we're at it drop "const" from the type of the raw string array. These strings are always allocated by refspec_append(), etc, and this makes the memory ownership more clear. This is all a bit more intimate with the refspec code than I'd like, and I suspect it would be better if each refspec_item held on to its own raw string, we had a single array, and we could use refspec_item_clear() to clean up everything. But that's a non-trivial refactoring, since refspec_item structs can be held outside of a "struct refspec", without having a matching raw string at all. So let's leave that for now and just fix the leak in the most immediate way. This lets us mark t5582 as leak-free. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refspec.c')
-rw-r--r--refspec.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/refspec.c b/refspec.c
index ec90ab349a..c3cf003443 100644
--- a/refspec.c
+++ b/refspec.c
@@ -225,7 +225,7 @@ void refspec_clear(struct refspec *rs)
rs->nr = 0;
for (i = 0; i < rs->raw_nr; i++)
- free((char *)rs->raw[i]);
+ free(rs->raw[i]);
FREE_AND_NULL(rs->raw);
rs->raw_alloc = 0;
rs->raw_nr = 0;