From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 09/20] builtin/repack: fix leaks when computing packs to repack
Date: Thu, 22 Aug 2024 11:17:36 +0200 [thread overview]
Message-ID: <6bca72e5c574d5f930c9cefe7fc803ac30e0c28a.1724315484.git.ps@pks.im> (raw)
In-Reply-To: <cover.1724315484.git.ps@pks.im>
When writing an MIDX in git-repack(1) we first collect all the pack
names that we want to add to it in a string list. This list is marked as
`NODUP`, which indicates that it will neither duplicate nor own strings
added to it. In `write_midx_included_packs()` we then `insert()` strings
via `xstrdup()` or `strbuf_detach()`, but the resulting strings will not
be owned by anything and thus leak.
Fix this issue by marking the list as `DUP` and using a local buffer to
compute the pack names.
This leak is hit in t5319, but plugging it is not sufficient to make the
whole test suite pass.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/repack.c | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index 62cfa50c50f..8bb875532b4 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -732,14 +732,23 @@ static void midx_included_packs(struct string_list *include,
struct pack_geometry *geometry)
{
struct string_list_item *item;
+ struct strbuf buf = STRBUF_INIT;
+
+ for_each_string_list_item(item, &existing->kept_packs) {
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "%s.idx", item->string);
+ string_list_insert(include, buf.buf);
+ }
+
+ for_each_string_list_item(item, names) {
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "pack-%s.idx", item->string);
+ string_list_insert(include, buf.buf);
+ }
- for_each_string_list_item(item, &existing->kept_packs)
- string_list_insert(include, xstrfmt("%s.idx", item->string));
- for_each_string_list_item(item, names)
- string_list_insert(include, xstrfmt("pack-%s.idx", item->string));
if (geometry->split_factor) {
- struct strbuf buf = STRBUF_INIT;
uint32_t i;
+
for (i = geometry->split; i < geometry->pack_nr; i++) {
struct packed_git *p = geometry->pack[i];
@@ -754,17 +763,21 @@ static void midx_included_packs(struct string_list *include,
if (!p->pack_local)
continue;
+ strbuf_reset(&buf);
strbuf_addstr(&buf, pack_basename(p));
strbuf_strip_suffix(&buf, ".pack");
strbuf_addstr(&buf, ".idx");
- string_list_insert(include, strbuf_detach(&buf, NULL));
+ string_list_insert(include, buf.buf);
}
} else {
for_each_string_list_item(item, &existing->non_kept_packs) {
if (pack_is_marked_for_deletion(item))
continue;
- string_list_insert(include, xstrfmt("%s.idx", item->string));
+
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "%s.idx", item->string);
+ string_list_insert(include, buf.buf);
}
}
@@ -784,8 +797,13 @@ static void midx_included_packs(struct string_list *include,
*/
if (pack_is_marked_for_deletion(item))
continue;
- string_list_insert(include, xstrfmt("%s.idx", item->string));
+
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "%s.idx", item->string);
+ string_list_insert(include, buf.buf);
}
+
+ strbuf_release(&buf);
}
static int write_midx_included_packs(struct string_list *include,
@@ -1476,7 +1494,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
mark_packs_for_deletion(&existing, &names);
if (write_midx) {
- struct string_list include = STRING_LIST_INIT_NODUP;
+ struct string_list include = STRING_LIST_INIT_DUP;
midx_included_packs(&include, &existing, &names, &geometry);
ret = write_midx_included_packs(&include, &geometry, &names,
--
2.46.0.164.g477ce5ccd6.dirty
next prev parent reply other threads:[~2024-08-22 9:17 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 14:04 [PATCH 00/20] Memory leak fixes (pt.5) Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 01/20] mailinfo: fix leaking header data Patrick Steinhardt
2024-08-20 19:25 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 02/20] convert: fix leaks when resetting attributes Patrick Steinhardt
2024-08-20 19:51 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 03/20] pretty: fix memory leaks when parsing pretty formats Patrick Steinhardt
2024-08-20 20:36 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 04/20] pretty: fix leaking key/value separator buffer Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 05/20] builtin/merge-tree: fix leaking `-X` strategy options Patrick Steinhardt
2024-08-20 22:10 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 06/20] builtin/upload-archive: fix leaking args passed to `write_archive()` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 07/20] builtin/archive: fix leaking `OPT_FILENAME()` value Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 08/20] midx-write: fix leaking hashfile on error cases Patrick Steinhardt
2024-08-20 23:19 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 09/20] builtin/repack: fix leaks when computing packs to repack Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 10/20] t/helper: fix leaking multi-pack-indices in "read-midx" Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 11/20] transport: fix leaking OID arrays in git:// transport data Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 12/20] builtin/send-pack: fix leaking refspecs Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 13/20] sideband: fix leaks when configuring sideband colors Patrick Steinhardt
2024-08-20 23:52 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 14/20] builtin/fetch-pack: fix leaking refs Patrick Steinhardt
2024-08-21 17:46 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 15/20] remote: fix leaking config strings Patrick Steinhardt
2024-08-21 17:58 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-22 16:04 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 16/20] remote: fix leaks when matching refspecs Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 17/20] remote: fix leaking peer ref when expanding refmap Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 18/20] builtin/fetch: fix leaking transaction with `--atomic` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 19/20] transport: fix leaking arguments when fetching from bundle Patrick Steinhardt
2024-08-21 18:07 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-22 16:06 ` Junio C Hamano
2024-08-20 14:06 ` [PATCH 20/20] transport: fix leaking negotiation tips Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 00/20] Memory leak fixes (pt.5) Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 01/20] mailinfo: fix leaking header data Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 02/20] convert: fix leaks when resetting attributes Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 03/20] pretty: fix memory leaks when parsing pretty formats Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 04/20] pretty: fix leaking key/value separator buffer Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 05/20] builtin/merge-tree: fix leaking `-X` strategy options Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 06/20] builtin/upload-archive: fix leaking args passed to `write_archive()` Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 07/20] builtin/archive: fix leaking `OPT_FILENAME()` value Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 08/20] midx-write: fix leaking hashfile on error cases Patrick Steinhardt
2024-08-22 9:17 ` Patrick Steinhardt [this message]
2024-08-22 9:17 ` [PATCH v2 10/20] t/helper: fix leaking multi-pack-indices in "read-midx" Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 11/20] transport: fix leaking OID arrays in git:// transport data Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 12/20] builtin/send-pack: fix leaking refspecs Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 13/20] sideband: fix leaks when configuring sideband colors Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 14/20] builtin/fetch-pack: fix leaking refs Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 15/20] remote: fix leaking config strings Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 16/20] remote: fix leaks when matching refspecs Patrick Steinhardt
2024-08-22 9:18 ` [PATCH v2 17/20] remote: fix leaking peer ref when expanding refmap Patrick Steinhardt
2024-08-22 9:18 ` [PATCH v2 18/20] builtin/fetch: fix leaking transaction with `--atomic` Patrick Steinhardt
2024-08-22 9:18 ` [PATCH v2 19/20] transport: fix leaking arguments when fetching from bundle Patrick Steinhardt
2024-08-22 18:21 ` Junio C Hamano
2024-08-22 9:18 ` [PATCH v2 20/20] transport: fix leaking negotiation tips Patrick Steinhardt
2024-08-22 19:01 ` [PATCH v2 00/20] Memory leak fixes (pt.5) Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6bca72e5c574d5f930c9cefe7fc803ac30e0c28a.1724315484.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).