From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 14/23] builtin/repack: fix leaking configuration
Date: Mon, 16 Sep 2024 13:46:05 +0200 [thread overview]
Message-ID: <a5f3931eee1e49c60e1d5be214263aeaf3d5c65f.1726484308.git.ps@pks.im> (raw)
In-Reply-To: <cover.1726484308.git.ps@pks.im>
When repacking, we assemble git-pack-objects(1) arguments both for the
"normal" pack and for the cruft pack. This configuration gets populated
with a bunch of `OPT_PASSTHRU` options that we end up passing to the
child process. These options are allocated, but never free'd.
Create a new `pack_objects_args_release()` function that releases the
memory for us and call it for both sets of options.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/repack.c | 57 ++++++++++++++++++++++++++---------
t/t5329-pack-objects-cruft.sh | 2 ++
t/t7700-repack.sh | 1 +
3 files changed, 45 insertions(+), 15 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index 3ee8cfa732f..c31d5653f1f 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -85,17 +85,34 @@ static int repack_config(const char *var, const char *value,
run_update_server_info = git_config_bool(var, value);
return 0;
}
- if (!strcmp(var, "repack.cruftwindow"))
+ if (!strcmp(var, "repack.cruftwindow")) {
+ free(cruft_po_args->window);
return git_config_string(&cruft_po_args->window, var, value);
- if (!strcmp(var, "repack.cruftwindowmemory"))
+ }
+ if (!strcmp(var, "repack.cruftwindowmemory")) {
+ free(cruft_po_args->window_memory);
return git_config_string(&cruft_po_args->window_memory, var, value);
- if (!strcmp(var, "repack.cruftdepth"))
+ }
+ if (!strcmp(var, "repack.cruftdepth")) {
+ free(cruft_po_args->depth);
return git_config_string(&cruft_po_args->depth, var, value);
- if (!strcmp(var, "repack.cruftthreads"))
+ }
+ if (!strcmp(var, "repack.cruftthreads")) {
+ free(cruft_po_args->threads);
return git_config_string(&cruft_po_args->threads, var, value);
+ }
return git_default_config(var, value, ctx, cb);
}
+static void pack_objects_args_release(struct pack_objects_args *args)
+{
+ free(args->window);
+ free(args->window_memory);
+ free(args->depth);
+ free(args->threads);
+ list_objects_filter_release(&args->filter_options);
+}
+
struct existing_packs {
struct string_list kept_packs;
struct string_list non_kept_packs;
@@ -1152,12 +1169,16 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
const char *unpack_unreachable = NULL;
int keep_unreachable = 0;
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
- struct pack_objects_args po_args = {NULL};
- struct pack_objects_args cruft_po_args = {NULL};
+ struct pack_objects_args po_args = { 0 };
+ struct pack_objects_args cruft_po_args = { 0 };
int write_midx = 0;
const char *cruft_expiration = NULL;
const char *expire_to = NULL;
const char *filter_to = NULL;
+ const char *opt_window = NULL;
+ const char *opt_window_memory = NULL;
+ const char *opt_depth = NULL;
+ const char *opt_threads = NULL;
struct option builtin_repack_options[] = {
OPT_BIT('a', NULL, &pack_everything,
@@ -1191,13 +1212,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
N_("with -A, do not loosen objects older than this")),
OPT_BOOL('k', "keep-unreachable", &keep_unreachable,
N_("with -a, repack unreachable objects")),
- OPT_STRING(0, "window", &po_args.window, N_("n"),
+ OPT_STRING(0, "window", &opt_window, N_("n"),
N_("size of the window used for delta compression")),
- OPT_STRING(0, "window-memory", &po_args.window_memory, N_("bytes"),
+ OPT_STRING(0, "window-memory", &opt_window_memory, N_("bytes"),
N_("same as the above, but limit memory size instead of entries count")),
- OPT_STRING(0, "depth", &po_args.depth, N_("n"),
+ OPT_STRING(0, "depth", &opt_depth, N_("n"),
N_("limits the maximum delta depth")),
- OPT_STRING(0, "threads", &po_args.threads, N_("n"),
+ OPT_STRING(0, "threads", &opt_threads, N_("n"),
N_("limits the maximum number of threads")),
OPT_MAGNITUDE(0, "max-pack-size", &po_args.max_pack_size,
N_("maximum size of each packfile")),
@@ -1224,6 +1245,11 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, builtin_repack_options,
git_repack_usage, 0);
+ po_args.window = xstrdup_or_null(opt_window);
+ po_args.window_memory = xstrdup_or_null(opt_window_memory);
+ po_args.depth = xstrdup_or_null(opt_depth);
+ po_args.threads = xstrdup_or_null(opt_threads);
+
if (delete_redundant && repository_format_precious_objects)
die(_("cannot delete packs in a precious-objects repo"));
@@ -1389,13 +1415,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
const char *pack_prefix = find_pack_prefix(packdir, packtmp);
if (!cruft_po_args.window)
- cruft_po_args.window = po_args.window;
+ cruft_po_args.window = xstrdup_or_null(po_args.window);
if (!cruft_po_args.window_memory)
- cruft_po_args.window_memory = po_args.window_memory;
+ cruft_po_args.window_memory = xstrdup_or_null(po_args.window_memory);
if (!cruft_po_args.depth)
- cruft_po_args.depth = po_args.depth;
+ cruft_po_args.depth = xstrdup_or_null(po_args.depth);
if (!cruft_po_args.threads)
- cruft_po_args.threads = po_args.threads;
+ cruft_po_args.threads = xstrdup_or_null(po_args.threads);
if (!cruft_po_args.max_pack_size)
cruft_po_args.max_pack_size = po_args.max_pack_size;
@@ -1547,7 +1573,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
string_list_clear(&names, 1);
existing_packs_release(&existing);
free_pack_geometry(&geometry);
- list_objects_filter_release(&po_args.filter_options);
+ pack_objects_args_release(&po_args);
+ pack_objects_args_release(&cruft_po_args);
return ret;
}
diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh
index fc5fedbe9b0..445739d06c9 100755
--- a/t/t5329-pack-objects-cruft.sh
+++ b/t/t5329-pack-objects-cruft.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='cruft pack related pack-objects tests'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
objdir=.git/objects
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index be1188e7365..c4c3d1a15d9 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -2,6 +2,7 @@
test_description='git repack works correctly'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "${TEST_DIRECTORY}/lib-bitmap.sh"
. "${TEST_DIRECTORY}/lib-midx.sh"
--
2.46.0.551.gc5ee8f2d1c.dirty
next prev parent reply other threads:[~2024-09-16 11:46 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-16 11:45 [PATCH 00/23] Memory leak fixes (pt.7) Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 01/23] builtin/help: fix dangling reference to `html_path` Patrick Steinhardt
2024-09-16 16:24 ` Justin Tobler
2024-09-16 11:45 ` [PATCH 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 03/23] git: fix leaking argv when handling builtins Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 04/23] submodule: fix leaking update strategy Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 05/23] builtin/submodule--helper: clear child process when not running it Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 06/23] builtin/submodule--helper: fix leaking error buffer Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 07/23] t/helper: fix leaking subrepo in nested submodule config helper Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 08/23] builtin/submodule--helper: fix leaking remote ref on errors Patrick Steinhardt
2024-09-16 18:51 ` Justin Tobler
2024-09-17 10:19 ` Patrick Steinhardt
2024-09-25 20:26 ` Junio C Hamano
2024-09-26 11:58 ` Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 09/23] dir: fix off by one errors for ignored and untracked entries Patrick Steinhardt
2024-09-20 16:43 ` Junio C Hamano
2024-09-16 11:45 ` [PATCH 10/23] builtin/pull: fix leaking "ff" option Patrick Steinhardt
2024-09-20 17:00 ` Junio C Hamano
2024-09-24 7:20 ` Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 11/23] diff: fix leaking orderfile option Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 12/23] parse-options: free previous value of `OPTION_FILENAME` Patrick Steinhardt
2024-09-20 17:21 ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 13/23] diffcore-order: fix leaking buffer when parsing orderfiles Patrick Steinhardt
2024-09-16 11:46 ` Patrick Steinhardt [this message]
2024-09-20 17:28 ` [PATCH 14/23] builtin/repack: fix leaking configuration Junio C Hamano
2024-09-16 11:46 ` [PATCH 15/23] builtin/difftool: plug several trivial memory leaks Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 16/23] trace2: destroy context stored in thread-local storage Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 17/23] submodule: fix leaking submodule ODB paths Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 18/23] grep: fix leaking grep pattern Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 19/23] promisor-remote: fix leaking partial clone filter Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 20/23] builtin/maintenance: fix leaking config string Patrick Steinhardt
2024-09-20 17:59 ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 22/23] revision: fix leaking parents when simplifying commits Patrick Steinhardt
2024-09-19 17:17 ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Patrick Steinhardt
2024-09-19 18:54 ` [PATCH 00/23] Memory leak fixes (pt.7) Junio C Hamano
2024-09-24 7:20 ` Patrick Steinhardt
2024-09-26 11:45 ` [PATCH v2 " Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 01/23] builtin/help: fix dangling reference to `html_path` Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 03/23] git: fix leaking argv when handling builtins Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 04/23] submodule: fix leaking update strategy Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 05/23] builtin/submodule--helper: clear child process when not running it Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 06/23] builtin/submodule--helper: fix leaking error buffer Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 07/23] t/helper: fix leaking subrepo in nested submodule config helper Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 08/23] builtin/submodule--helper: fix leaking remote ref on errors Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 09/23] dir: fix off by one errors for ignored and untracked entries Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 10/23] builtin/pull: fix leaking "ff" option Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 11/23] diff: fix leaking orderfile option Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 12/23] parse-options: free previous value of `OPTION_FILENAME` Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 13/23] diffcore-order: fix leaking buffer when parsing orderfiles Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 14/23] builtin/repack: fix leaking configuration Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 15/23] builtin/difftool: plug several trivial memory leaks Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 16/23] trace2: destroy context stored in thread-local storage Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 17/23] submodule: fix leaking submodule ODB paths Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 18/23] grep: fix leaking grep pattern Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 19/23] promisor-remote: fix leaking partial clone filter Patrick Steinhardt
2024-09-26 11:46 ` [PATCH v2 20/23] builtin/maintenance: fix leaking config string Patrick Steinhardt
2024-09-26 11:47 ` [PATCH v2 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Patrick Steinhardt
2024-09-26 11:47 ` [PATCH v2 22/23] revision: fix leaking parents when simplifying commits Patrick Steinhardt
2024-09-26 11:47 ` [PATCH v2 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Patrick Steinhardt
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=a5f3931eee1e49c60e1d5be214263aeaf3d5c65f.1726484308.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
/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).