aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--builtin/difftool.c6
-rw-r--r--builtin/gc.c131
-rw-r--r--builtin/help.c16
-rw-r--r--builtin/pull.c11
-rw-r--r--builtin/repack.c57
-rw-r--r--builtin/submodule--helper.c26
-rw-r--r--combine-diff.c3
-rw-r--r--diff.c7
-rw-r--r--diff.h2
-rw-r--r--diffcore-break.c4
-rw-r--r--diffcore-order.c19
-rw-r--r--dir.c6
-rw-r--r--git.c22
-rw-r--r--grep.c2
-rw-r--r--parse-options.c22
-rw-r--r--promisor-remote.c2
-rw-r--r--revision.c5
-rw-r--r--submodule-config.c2
-rw-r--r--submodule.c9
-rw-r--r--submodule.h6
-rw-r--r--t/helper/test-submodule-nested-repo-config.c2
-rwxr-xr-xt/t0012-help.sh1
-rwxr-xr-xt/t1414-reflog-walk.sh1
-rwxr-xr-xt/t3011-common-prefixes-and-directory-traversal.sh1
-rwxr-xr-xt/t4008-diff-break-rewrite.sh2
-rwxr-xr-xt/t4022-diff-rewrite.sh1
-rwxr-xr-xt/t4023-diff-rename-typechange.sh1
-rwxr-xr-xt/t4031-diff-rewrite-binary.sh1
-rwxr-xr-xt/t4056-diff-order.sh1
-rwxr-xr-xt/t4204-patch-id.sh1
-rwxr-xr-xt/t5310-pack-bitmaps.sh1
-rwxr-xr-xt/t5326-multi-pack-bitmaps.sh2
-rwxr-xr-xt/t5329-pack-objects-cruft.sh2
-rwxr-xr-xt/t6004-rev-list-path-optim.sh1
-rwxr-xr-xt/t6019-rev-list-ancestry-path.sh1
-rwxr-xr-xt/t6111-rev-list-treesame.sh1
-rwxr-xr-xt/t7061-wtstatus-ignore.sh1
-rwxr-xr-xt/t7406-submodule-update.sh1
-rwxr-xr-xt/t7407-submodule-foreach.sh1
-rwxr-xr-xt/t7408-submodule-reference.sh2
-rwxr-xr-xt/t7411-submodule-config.sh1
-rwxr-xr-xt/t7420-submodule-set-url.sh1
-rwxr-xr-xt/t7521-ignored-mode.sh1
-rwxr-xr-xt/t7524-commit-summary.sh2
-rwxr-xr-xt/t7601-merge-pull-config.sh1
-rwxr-xr-xt/t7700-repack.sh1
-rwxr-xr-xt/t7800-difftool.sh1
-rwxr-xr-xt/t7814-grep-recurse-submodules.sh1
-rwxr-xr-xt/t7900-maintenance.sh1
-rw-r--r--trace2/tr2_tls.c10
50 files changed, 279 insertions, 124 deletions
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 4b416743ff..5772e82106 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -662,6 +662,12 @@ finish:
if (fp)
fclose(fp);
+ hashmap_clear_and_free(&working_tree_dups, struct working_tree_entry, entry);
+ hashmap_clear_and_free(&wt_modified, struct path_entry, entry);
+ hashmap_clear_and_free(&tmp_modified, struct path_entry, entry);
+ hashmap_clear_and_free(&submodules, struct pair_entry, entry);
+ hashmap_clear_and_free(&symlinks2, struct pair_entry, entry);
+ release_index(&wtindex);
free(lbase_dir);
free(rbase_dir);
strbuf_release(&info);
diff --git a/builtin/gc.c b/builtin/gc.c
index c3894fb6bd..d805dfecf0 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1478,9 +1478,9 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
static void initialize_maintenance_strategy(void)
{
- char *config_str;
+ const char *config_str;
- if (git_config_get_string("maintenance.strategy", &config_str))
+ if (git_config_get_string_tmp("maintenance.strategy", &config_str))
return;
if (!strcasecmp(config_str, "incremental")) {
@@ -1782,32 +1782,33 @@ static const char *get_frequency(enum schedule_priority schedule)
* * If $GIT_TEST_MAINT_SCHEDULER is set, return true.
* In this case, the *cmd value is read as input.
*
- * * if the input value *cmd is the key of one of the comma-separated list
- * item, then *is_available is set to true and *cmd is modified and becomes
+ * * if the input value cmd is the key of one of the comma-separated list
+ * item, then *is_available is set to true and *out is set to
* the mock command.
*
* * if the input value *cmd isn’t the key of any of the comma-separated list
- * item, then *is_available is set to false.
+ * item, then *is_available is set to false and *out is set to the original
+ * command.
*
* Ex.:
* GIT_TEST_MAINT_SCHEDULER not set
* +-------+-------------------------------------------------+
* | Input | Output |
- * | *cmd | return code | *cmd | *is_available |
+ * | *cmd | return code | *out | *is_available |
* +-------+-------------+-------------------+---------------+
- * | "foo" | false | "foo" (unchanged) | (unchanged) |
+ * | "foo" | false | NULL | (unchanged) |
* +-------+-------------+-------------------+---------------+
*
* GIT_TEST_MAINT_SCHEDULER set to “foo:./mock_foo.sh,bar:./mock_bar.sh”
* +-------+-------------------------------------------------+
* | Input | Output |
- * | *cmd | return code | *cmd | *is_available |
+ * | *cmd | return code | *out | *is_available |
* +-------+-------------+-------------------+---------------+
* | "foo" | true | "./mock.foo.sh" | true |
- * | "qux" | true | "qux" (unchanged) | false |
+ * | "qux" | true | "qux" (allocated) | false |
* +-------+-------------+-------------------+---------------+
*/
-static int get_schedule_cmd(const char **cmd, int *is_available)
+static int get_schedule_cmd(const char *cmd, int *is_available, char **out)
{
char *testing = xstrdup_or_null(getenv("GIT_TEST_MAINT_SCHEDULER"));
struct string_list_item *item;
@@ -1826,16 +1827,22 @@ static int get_schedule_cmd(const char **cmd, int *is_available)
if (string_list_split_in_place(&pair, item->string, ":", 2) != 2)
continue;
- if (!strcmp(*cmd, pair.items[0].string)) {
- *cmd = pair.items[1].string;
+ if (!strcmp(cmd, pair.items[0].string)) {
+ if (out)
+ *out = xstrdup(pair.items[1].string);
if (is_available)
*is_available = 1;
- string_list_clear(&list, 0);
- UNLEAK(testing);
- return 1;
+ string_list_clear(&pair, 0);
+ goto out;
}
+
+ string_list_clear(&pair, 0);
}
+ if (out)
+ *out = xstrdup(cmd);
+
+out:
string_list_clear(&list, 0);
free(testing);
return 1;
@@ -1852,9 +1859,8 @@ static int get_random_minute(void)
static int is_launchctl_available(void)
{
- const char *cmd = "launchctl";
int is_available;
- if (get_schedule_cmd(&cmd, &is_available))
+ if (get_schedule_cmd("launchctl", &is_available, NULL))
return is_available;
#ifdef __APPLE__
@@ -1892,12 +1898,12 @@ static char *launchctl_get_uid(void)
static int launchctl_boot_plist(int enable, const char *filename)
{
- const char *cmd = "launchctl";
+ char *cmd;
int result;
struct child_process child = CHILD_PROCESS_INIT;
char *uid = launchctl_get_uid();
- get_schedule_cmd(&cmd, NULL);
+ get_schedule_cmd("launchctl", NULL, &cmd);
strvec_split(&child.args, cmd);
strvec_pushl(&child.args, enable ? "bootstrap" : "bootout", uid,
filename, NULL);
@@ -1910,6 +1916,7 @@ static int launchctl_boot_plist(int enable, const char *filename)
result = finish_command(&child);
+ free(cmd);
free(uid);
return result;
}
@@ -1961,10 +1968,10 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
static unsigned long lock_file_timeout_ms = ULONG_MAX;
struct strbuf plist = STRBUF_INIT, plist2 = STRBUF_INIT;
struct stat st;
- const char *cmd = "launchctl";
+ char *cmd;
int minute = get_random_minute();
- get_schedule_cmd(&cmd, NULL);
+ get_schedule_cmd("launchctl", NULL, &cmd);
preamble = "<?xml version=\"1.0\"?>\n"
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
"<plist version=\"1.0\">"
@@ -2054,6 +2061,7 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
free(filename);
free(name);
+ free(cmd);
strbuf_release(&plist);
strbuf_release(&plist2);
return 0;
@@ -2078,9 +2086,8 @@ static int launchctl_update_schedule(int run_maintenance, int fd UNUSED)
static int is_schtasks_available(void)
{
- const char *cmd = "schtasks";
int is_available;
- if (get_schedule_cmd(&cmd, &is_available))
+ if (get_schedule_cmd("schtasks", &is_available, NULL))
return is_available;
#ifdef GIT_WINDOWS_NATIVE
@@ -2099,15 +2106,16 @@ static char *schtasks_task_name(const char *frequency)
static int schtasks_remove_task(enum schedule_priority schedule)
{
- const char *cmd = "schtasks";
+ char *cmd;
struct child_process child = CHILD_PROCESS_INIT;
const char *frequency = get_frequency(schedule);
char *name = schtasks_task_name(frequency);
- get_schedule_cmd(&cmd, NULL);
+ get_schedule_cmd("schtasks", NULL, &cmd);
strvec_split(&child.args, cmd);
strvec_pushl(&child.args, "/delete", "/tn", name, "/f", NULL);
free(name);
+ free(cmd);
return run_command(&child);
}
@@ -2121,7 +2129,7 @@ static int schtasks_remove_tasks(void)
static int schtasks_schedule_task(const char *exec_path, enum schedule_priority schedule)
{
- const char *cmd = "schtasks";
+ char *cmd;
int result;
struct child_process child = CHILD_PROCESS_INIT;
const char *xml;
@@ -2131,7 +2139,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
struct strbuf tfilename = STRBUF_INIT;
int minute = get_random_minute();
- get_schedule_cmd(&cmd, NULL);
+ get_schedule_cmd("schtasks", NULL, &cmd);
strbuf_addf(&tfilename, "%s/schedule_%s_XXXXXX",
repo_get_common_dir(the_repository), frequency);
@@ -2237,6 +2245,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
delete_tempfile(&tfile);
free(name);
+ free(cmd);
return result;
}
@@ -2278,21 +2287,28 @@ static int check_crontab_process(const char *cmd)
static int is_crontab_available(void)
{
- const char *cmd = "crontab";
+ char *cmd;
int is_available;
+ int ret;
- if (get_schedule_cmd(&cmd, &is_available))
- return is_available;
+ if (get_schedule_cmd("crontab", &is_available, &cmd)) {
+ ret = is_available;
+ goto out;
+ }
#ifdef __APPLE__
/*
* macOS has cron, but it requires special permissions and will
* create a UI alert when attempting to run this command.
*/
- return 0;
+ ret = 0;
#else
- return check_crontab_process(cmd);
+ ret = check_crontab_process(cmd);
#endif
+
+out:
+ free(cmd);
+ return ret;
}
#define BEGIN_LINE "# BEGIN GIT MAINTENANCE SCHEDULE"
@@ -2300,7 +2316,7 @@ static int is_crontab_available(void)
static int crontab_update_schedule(int run_maintenance, int fd)
{
- const char *cmd = "crontab";
+ char *cmd;
int result = 0;
int in_old_region = 0;
struct child_process crontab_list = CHILD_PROCESS_INIT;
@@ -2310,15 +2326,17 @@ static int crontab_update_schedule(int run_maintenance, int fd)
struct tempfile *tmpedit = NULL;
int minute = get_random_minute();
- get_schedule_cmd(&cmd, NULL);
+ get_schedule_cmd("crontab", NULL, &cmd);
strvec_split(&crontab_list.args, cmd);
strvec_push(&crontab_list.args, "-l");
crontab_list.in = -1;
crontab_list.out = dup(fd);
crontab_list.git_cmd = 0;
- if (start_command(&crontab_list))
- return error(_("failed to run 'crontab -l'; your system might not support 'cron'"));
+ if (start_command(&crontab_list)) {
+ result = error(_("failed to run 'crontab -l'; your system might not support 'cron'"));
+ goto out;
+ }
/* Ignore exit code, as an empty crontab will return error. */
finish_command(&crontab_list);
@@ -2388,8 +2406,10 @@ static int crontab_update_schedule(int run_maintenance, int fd)
result = error(_("'crontab' died"));
else
fclose(cron_list);
+
out:
delete_tempfile(&tmpedit);
+ free(cmd);
return result;
}
@@ -2412,10 +2432,9 @@ static int real_is_systemd_timer_available(void)
static int is_systemd_timer_available(void)
{
- const char *cmd = "systemctl";
int is_available;
- if (get_schedule_cmd(&cmd, &is_available))
+ if (get_schedule_cmd("systemctl", &is_available, NULL))
return is_available;
return real_is_systemd_timer_available();
@@ -2596,9 +2615,10 @@ static int systemd_timer_enable_unit(int enable,
enum schedule_priority schedule,
int minute)
{
- const char *cmd = "systemctl";
+ char *cmd = NULL;
struct child_process child = CHILD_PROCESS_INIT;
const char *frequency = get_frequency(schedule);
+ int ret;
/*
* Disabling the systemd unit while it is already disabled makes
@@ -2609,20 +2629,25 @@ static int systemd_timer_enable_unit(int enable,
* On the other hand, enabling a systemd unit which is already enabled
* produces no error.
*/
- if (!enable)
+ if (!enable) {
child.no_stderr = 1;
- else if (systemd_timer_write_timer_file(schedule, minute))
- return -1;
+ } else if (systemd_timer_write_timer_file(schedule, minute)) {
+ ret = -1;
+ goto out;
+ }
- get_schedule_cmd(&cmd, NULL);
+ get_schedule_cmd("systemctl", NULL, &cmd);
strvec_split(&child.args, cmd);
strvec_pushl(&child.args, "--user", enable ? "enable" : "disable",
"--now", NULL);
strvec_pushf(&child.args, SYSTEMD_UNIT_FORMAT, frequency, "timer");
- if (start_command(&child))
- return error(_("failed to start systemctl"));
- if (finish_command(&child))
+ if (start_command(&child)) {
+ ret = error(_("failed to start systemctl"));
+ goto out;
+ }
+
+ if (finish_command(&child)) {
/*
* Disabling an already disabled systemd unit makes
* systemctl fail.
@@ -2630,9 +2655,17 @@ static int systemd_timer_enable_unit(int enable,
*
* Enabling an enabled systemd unit doesn't fail.
*/
- if (enable)
- return error(_("failed to run systemctl"));
- return 0;
+ if (enable) {
+ ret = error(_("failed to run systemctl"));
+ goto out;
+ }
+ }
+
+ ret = 0;
+
+out:
+ free(cmd);
+ return ret;
}
/*
diff --git a/builtin/help.c b/builtin/help.c
index a509241a80..4a5a079070 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -54,7 +54,7 @@ static enum help_action {
HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION,
} cmd_mode;
-static const char *html_path;
+static char *html_path;
static int verbose = 1;
static enum help_format help_format = HELP_FORMAT_NONE;
static int exclude_guides;
@@ -411,6 +411,7 @@ static int git_help_config(const char *var, const char *value,
if (!strcmp(var, "help.htmlpath")) {
if (!value)
return config_error_nonbool(var);
+ free(html_path);
html_path = xstrdup(value);
return 0;
}
@@ -515,23 +516,24 @@ static void show_info_page(const char *page)
static void get_html_page_path(struct strbuf *page_path, const char *page)
{
struct stat st;
+ const char *path = html_path;
char *to_free = NULL;
- if (!html_path)
- html_path = to_free = system_path(GIT_HTML_PATH);
+ if (!path)
+ path = to_free = system_path(GIT_HTML_PATH);
/*
* Check that the page we're looking for exists.
*/
- if (!strstr(html_path, "://")) {
- if (stat(mkpath("%s/%s.html", html_path, page), &st)
+ if (!strstr(path, "://")) {
+ if (stat(mkpath("%s/%s.html", path, page), &st)
|| !S_ISREG(st.st_mode))
die("'%s/%s.html': documentation file not found.",
- html_path, page);
+ path, page);
}
strbuf_init(page_path, 0);
- strbuf_addf(page_path, "%s/%s.html", html_path, page);
+ strbuf_addf(page_path, "%s/%s.html", path, page);
free(to_free);
}
diff --git a/builtin/pull.c b/builtin/pull.c
index 149f201320..388ef3d130 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -85,7 +85,7 @@ static const char *opt_squash;
static const char *opt_commit;
static const char *opt_edit;
static const char *cleanup_arg;
-static const char *opt_ff;
+static char *opt_ff;
static const char *opt_verify_signatures;
static const char *opt_verify;
static int opt_autostash = -1;
@@ -1028,8 +1028,10 @@ int cmd_pull(int argc,
* "--rebase" can override a config setting of
* pull.ff=only.
*/
- if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only"))
- opt_ff = "--ff";
+ if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only")) {
+ free(opt_ff);
+ opt_ff = xstrdup("--ff");
+ }
}
if (opt_rebase < 0)
@@ -1139,7 +1141,8 @@ int cmd_pull(int argc,
if (can_ff) {
/* we can fast-forward this without invoking rebase */
- opt_ff = "--ff-only";
+ free(opt_ff);
+ opt_ff = xstrdup("--ff-only");
ret = run_merge();
} else {
ret = run_rebase(&newbase, &upstream);
diff --git a/builtin/repack.c b/builtin/repack.c
index cb4420f085..d6bb37e84a 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -86,17 +86,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;
@@ -1156,12 +1173,16 @@ int cmd_repack(int argc,
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,
@@ -1195,13 +1216,13 @@ int cmd_repack(int argc,
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")),
@@ -1228,6 +1249,11 @@ int cmd_repack(int argc,
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"));
@@ -1393,13 +1419,13 @@ int cmd_repack(int argc,
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;
@@ -1552,7 +1578,8 @@ cleanup:
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/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a1ada86952..0e4252fa79 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -364,9 +364,13 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
if (!info->quiet)
printf(_("Entering '%s'\n"), displaypath);
- if (info->argv[0] && run_command(&cp))
- die(_("run_command returned non-zero status for %s\n."),
- displaypath);
+ if (info->argv[0]) {
+ if (run_command(&cp))
+ die(_("run_command returned non-zero status for %s\n."),
+ displaypath);
+ } else {
+ child_process_clear(&cp);
+ }
if (info->recursive) {
struct child_process cpr = CHILD_PROCESS_INIT;
@@ -1618,6 +1622,8 @@ static int add_possible_reference_from_superproject(
; /* nothing */
}
}
+
+ strbuf_release(&err);
strbuf_release(&sb);
}
@@ -2022,6 +2028,7 @@ struct update_data {
static void update_data_release(struct update_data *ud)
{
free(ud->displaypath);
+ submodule_update_strategy_release(&ud->update_strategy);
module_list_release(&ud->list);
}
@@ -2642,15 +2649,20 @@ static int update_submodule(struct update_data *update_data)
if (!update_data->nofetch) {
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
- 0, NULL))
+ 0, NULL)) {
+ free(remote_ref);
return die_message(_("Unable to fetch in submodule path '%s'"),
update_data->sm_path);
+ }
}
if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
- remote_ref, &update_data->oid))
- return die_message(_("Unable to find %s revision in submodule path '%s'"),
- remote_ref, update_data->sm_path);
+ remote_ref, &update_data->oid)) {
+ ret = die_message(_("Unable to find %s revision in submodule path '%s'"),
+ remote_ref, update_data->sm_path);
+ free(remote_ref);
+ return ret;
+ }
free(remote_ref);
}
diff --git a/combine-diff.c b/combine-diff.c
index 829a44e416..f6b624dc28 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1393,9 +1393,8 @@ static struct combine_diff_path *find_paths_generic(const struct object_id *oid,
{
struct combine_diff_path *paths = NULL;
int i, num_parent = parents->nr;
-
int output_format = opt->output_format;
- const char *orderfile = opt->orderfile;
+ char *orderfile = opt->orderfile;
opt->output_format = DIFF_FORMAT_NO_OUTPUT;
/* tell diff_tree to emit paths in sorted (=tree) order */
diff --git a/diff.c b/diff.c
index 84a6bb0868..173cbe2bed 100644
--- a/diff.c
+++ b/diff.c
@@ -443,8 +443,10 @@ int git_diff_ui_config(const char *var, const char *value,
}
if (!strcmp(var, "diff.wordregex"))
return git_config_string(&diff_word_regex_cfg, var, value);
- if (!strcmp(var, "diff.orderfile"))
+ if (!strcmp(var, "diff.orderfile")) {
+ FREE_AND_NULL(diff_order_file_cfg);
return git_config_pathname(&diff_order_file_cfg, var, value);
+ }
if (!strcmp(var, "diff.ignoresubmodules")) {
if (!value)
@@ -4778,7 +4780,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
if (diff_indent_heuristic)
DIFF_XDL_SET(options, INDENT_HEURISTIC);
- options->orderfile = diff_order_file_cfg;
+ options->orderfile = xstrdup_or_null(diff_order_file_cfg);
if (!options->flags.ignore_submodule_set)
options->flags.ignore_untracked_in_submodules = 1;
@@ -6730,6 +6732,7 @@ void diff_free(struct diff_options *options)
FREE_AND_NULL(options->objfind);
}
+ FREE_AND_NULL(options->orderfile);
for (size_t i = 0; i < options->anchors_nr; i++)
free(options->anchors[i]);
FREE_AND_NULL(options->anchors);
diff --git a/diff.h b/diff.h
index fb40c6e6d6..0cde3b34e2 100644
--- a/diff.h
+++ b/diff.h
@@ -235,7 +235,7 @@ enum diff_submodule_format {
* diffcore library with.
*/
struct diff_options {
- const char *orderfile;
+ char *orderfile;
/*
* "--rotate-to=<file>" would start showing at <file> and when
diff --git a/diffcore-break.c b/diffcore-break.c
index 831b66b5c3..02735f80c6 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -266,8 +266,8 @@ static void merge_broken(struct diff_filepair *p,
* in the resulting tree.
*/
d->one->rename_used++;
- diff_free_filespec_data(d->two);
- diff_free_filespec_data(c->one);
+ free_filespec(d->two);
+ free_filespec(c->one);
free(d);
free(c);
}
diff --git a/diffcore-order.c b/diffcore-order.c
index e7d20ebd2d..912513d3e6 100644
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -14,8 +14,7 @@ static void prepare_order(const char *orderfile)
{
int cnt, pass;
struct strbuf sb = STRBUF_INIT;
- void *map;
- char *cp, *endp;
+ const char *cp, *endp;
ssize_t sz;
if (order)
@@ -24,14 +23,13 @@ static void prepare_order(const char *orderfile)
sz = strbuf_read_file(&sb, orderfile, 0);
if (sz < 0)
die_errno(_("failed to read orderfile '%s'"), orderfile);
- map = strbuf_detach(&sb, NULL);
- endp = (char *) map + sz;
+ endp = sb.buf + sz;
for (pass = 0; pass < 2; pass++) {
cnt = 0;
- cp = map;
+ cp = sb.buf;
while (cp < endp) {
- char *ep;
+ const char *ep;
for (ep = cp; ep < endp && *ep != '\n'; ep++)
;
/* cp to ep has one line */
@@ -40,12 +38,7 @@ static void prepare_order(const char *orderfile)
else if (pass == 0)
cnt++;
else {
- if (*ep == '\n') {
- *ep = 0;
- order[cnt] = cp;
- } else {
- order[cnt] = xmemdupz(cp, ep - cp);
- }
+ order[cnt] = xmemdupz(cp, ep - cp);
cnt++;
}
if (ep < endp)
@@ -57,6 +50,8 @@ static void prepare_order(const char *orderfile)
ALLOC_ARRAY(order, cnt);
}
}
+
+ strbuf_release(&sb);
}
static int match_order(const char *path)
diff --git a/dir.c b/dir.c
index c43b5e3081..e3ddd5b529 100644
--- a/dir.c
+++ b/dir.c
@@ -2136,8 +2136,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
*/
state = path_none;
} else {
- int i;
- for (i = old_ignored_nr + 1; i<dir->ignored_nr; ++i)
+ for (int i = old_ignored_nr; i < dir->ignored_nr; i++)
FREE_AND_NULL(dir->ignored[i]);
dir->ignored_nr = old_ignored_nr;
}
@@ -2149,8 +2148,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
*/
if ((dir->flags & DIR_SHOW_IGNORED_TOO) &&
!(dir->flags & DIR_KEEP_UNTRACKED_CONTENTS)) {
- int i;
- for (i = old_untracked_nr + 1; i<dir->nr; ++i)
+ for (int i = old_untracked_nr; i < dir->nr; i++)
FREE_AND_NULL(dir->entries[i]);
dir->nr = old_untracked_nr;
}
diff --git a/git.c b/git.c
index 2fbea24ec9..2a9752c91c 100644
--- a/git.c
+++ b/git.c
@@ -711,6 +711,7 @@ static void strip_extension(const char **argv)
static void handle_builtin(int argc, const char **argv)
{
struct strvec args = STRVEC_INIT;
+ const char **argv_copy = NULL;
const char *cmd;
struct cmd_struct *builtin;
@@ -731,13 +732,28 @@ static void handle_builtin(int argc, const char **argv)
}
argc++;
- argv = args.v;
+
+ /*
+ * `run_builtin()` will modify the argv array, so we need to
+ * create a shallow copy such that we can free all of its
+ * strings.
+ */
+ CALLOC_ARRAY(argv_copy, argc + 1);
+ COPY_ARRAY(argv_copy, args.v, argc);
+
+ argv = argv_copy;
}
builtin = get_builtin(cmd);
- if (builtin)
- exit(run_builtin(builtin, argc, argv, the_repository));
+ if (builtin) {
+ int ret = run_builtin(builtin, argc, argv, the_repository);
+ strvec_clear(&args);
+ free(argv_copy);
+ exit(ret);
+ }
+
strvec_clear(&args);
+ free(argv_copy);
}
static void execv_dashed_external(const char **argv)
diff --git a/grep.c b/grep.c
index e5761426e4..701e58de04 100644
--- a/grep.c
+++ b/grep.c
@@ -843,11 +843,11 @@ static void free_grep_pat(struct grep_pat *pattern)
free_pcre2_pattern(p);
else
regfree(&p->regexp);
- free(p->pattern);
break;
default:
break;
}
+ free(p->pattern);
free(p);
}
}
diff --git a/parse-options.c b/parse-options.c
index 30b9e68f8a..33bfba0ed4 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -60,12 +60,12 @@ static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p,
return 0;
}
-static void fix_filename(const char *prefix, char **file)
+static char *fix_filename(const char *prefix, const char *file)
{
if (!file || !*file)
- ; /* leave as NULL */
+ return NULL;
else
- *file = prefix_filename_except_for_dash(prefix, *file);
+ return prefix_filename_except_for_dash(prefix, file);
}
static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
@@ -129,18 +129,24 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
return 0;
case OPTION_FILENAME:
+ {
+ const char *value;
+
+ FREE_AND_NULL(*(char **)opt->value);
+
err = 0;
+
if (unset)
- *(const char **)opt->value = NULL;
+ value = NULL;
else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
- *(const char **)opt->value = (const char *)opt->defval;
+ value = (const char *) opt->defval;
else
- err = get_arg(p, opt, flags, (const char **)opt->value);
+ err = get_arg(p, opt, flags, &value);
if (!err)
- fix_filename(p->prefix, (char **)opt->value);
+ *(char **)opt->value = fix_filename(p->prefix, value);
return err;
-
+ }
case OPTION_CALLBACK:
{
const char *p_arg = NULL;
diff --git a/promisor-remote.c b/promisor-remote.c
index 317e1b127f..9345ae3db2 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -154,6 +154,7 @@ static int promisor_remote_config(const char *var, const char *value,
if (!r)
return 0;
+ FREE_AND_NULL(r->partial_clone_filter);
return git_config_string(&r->partial_clone_filter, var, value);
}
@@ -189,6 +190,7 @@ void promisor_remote_clear(struct promisor_remote_config *config)
{
while (config->promisors) {
struct promisor_remote *r = config->promisors;
+ free(r->partial_clone_filter);
config->promisors = config->promisors->next;
free(r);
}
diff --git a/revision.c b/revision.c
index 2d7ad2bddf..e79f39e555 100644
--- a/revision.c
+++ b/revision.c
@@ -1071,7 +1071,11 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
ts->treesame[nth_parent] = 1;
continue;
}
+
+ free_commit_list(parent->next);
parent->next = NULL;
+ while (commit->parents != parent)
+ pop_commit(&commit->parents);
commit->parents = parent;
/*
@@ -1103,6 +1107,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
die("cannot simplify commit %s (invalid %s)",
oid_to_hex(&commit->object.oid),
oid_to_hex(&p->object.oid));
+ free_commit_list(p->parents);
p->parents = NULL;
}
/* fallthrough */
diff --git a/submodule-config.c b/submodule-config.c
index c8f2bb2bdd..471637a725 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -95,7 +95,7 @@ static void free_one_config(struct submodule_entry *entry)
free((void *) entry->config->branch);
free((void *) entry->config->url);
free((void *) entry->config->ignore);
- free((void *) entry->config->update_strategy.command);
+ submodule_update_strategy_release(&entry->config->update_strategy);
free(entry->config);
}
diff --git a/submodule.c b/submodule.c
index 4e71ac0dfd..74d5766f07 100644
--- a/submodule.c
+++ b/submodule.c
@@ -175,11 +175,11 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_NODUP;
+static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
void add_submodule_odb_by_path(const char *path)
{
- string_list_insert(&added_submodule_odb_paths, xstrdup(path));
+ string_list_insert(&added_submodule_odb_paths, path);
}
int register_all_submodule_odb_as_alternates(void)
@@ -424,6 +424,11 @@ int parse_submodule_update_strategy(const char *value,
return 0;
}
+void submodule_update_strategy_release(struct submodule_update_strategy *strategy)
+{
+ free((char *) strategy->command);
+}
+
const char *submodule_update_type_to_string(enum submodule_update_type type)
{
switch (type) {
diff --git a/submodule.h b/submodule.h
index b50d29eba4..4deb1b5f84 100644
--- a/submodule.h
+++ b/submodule.h
@@ -41,6 +41,10 @@ struct submodule_update_strategy {
.type = SM_UPDATE_UNSPECIFIED, \
}
+int parse_submodule_update_strategy(const char *value,
+ struct submodule_update_strategy *dst);
+void submodule_update_strategy_release(struct submodule_update_strategy *strategy);
+
int is_gitmodules_unmerged(struct index_state *istate);
int is_writing_gitmodules_ok(void);
int is_staging_gitmodules_ok(struct index_state *istate);
@@ -70,8 +74,6 @@ void die_in_unpopulated_submodule(struct index_state *istate,
void die_path_inside_submodule(struct index_state *istate,
const struct pathspec *ps);
enum submodule_update_type parse_submodule_update_type(const char *value);
-int parse_submodule_update_strategy(const char *value,
- struct submodule_update_strategy *dst);
const char *submodule_update_type_to_string(enum submodule_update_type type);
void handle_ignore_submodules_arg(struct diff_options *, const char *);
void show_submodule_diff_summary(struct diff_options *o, const char *path,
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index 6ca069ce63..6dce957153 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -29,6 +29,6 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
print_config_from_gitmodules(&subrepo, argv[2]);
submodule_free(the_repository);
-
+ repo_clear(&subrepo);
return 0;
}
diff --git a/t/t0012-help.sh b/t/t0012-help.sh
index 1d273d91c2..9eae0d8356 100755
--- a/t/t0012-help.sh
+++ b/t/t0012-help.sh
@@ -2,6 +2,7 @@
test_description='help'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
configure_help () {
diff --git a/t/t1414-reflog-walk.sh b/t/t1414-reflog-walk.sh
index be6c3f472c..49d28166da 100755
--- a/t/t1414-reflog-walk.sh
+++ b/t/t1414-reflog-walk.sh
@@ -4,6 +4,7 @@ test_description='various tests of reflog walk (log -g) behavior'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'set up some reflog entries' '
diff --git a/t/t3011-common-prefixes-and-directory-traversal.sh b/t/t3011-common-prefixes-and-directory-traversal.sh
index 3da5b2b6e7..69e44c387f 100755
--- a/t/t3011-common-prefixes-and-directory-traversal.sh
+++ b/t/t3011-common-prefixes-and-directory-traversal.sh
@@ -2,6 +2,7 @@
test_description='directory traversal handling, especially with common prefixes'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t4008-diff-break-rewrite.sh b/t/t4008-diff-break-rewrite.sh
index 562aaf3a2a..b0ef0026e0 100755
--- a/t/t4008-diff-break-rewrite.sh
+++ b/t/t4008-diff-break-rewrite.sh
@@ -21,6 +21,8 @@ With -B, this should be detected as two complete rewrites.
Further, with -B and -M together, these should turn into two renames.
'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
diff --git a/t/t4022-diff-rewrite.sh b/t/t4022-diff-rewrite.sh
index 6fed993ea0..77bc36d5d8 100755
--- a/t/t4022-diff-rewrite.sh
+++ b/t/t4022-diff-rewrite.sh
@@ -2,6 +2,7 @@
test_description='rewrite diff'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff-data.sh
diff --git a/t/t4023-diff-rename-typechange.sh b/t/t4023-diff-rename-typechange.sh
index 787605ce3f..e6f4fe441e 100755
--- a/t/t4023-diff-rename-typechange.sh
+++ b/t/t4023-diff-rename-typechange.sh
@@ -2,6 +2,7 @@
test_description='typechange rename detection'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh
diff --git a/t/t4031-diff-rewrite-binary.sh b/t/t4031-diff-rewrite-binary.sh
index c4394a27b5..1b8cd3e4c9 100755
--- a/t/t4031-diff-rewrite-binary.sh
+++ b/t/t4031-diff-rewrite-binary.sh
@@ -2,6 +2,7 @@
test_description='rewrite diff on binary file'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# We must be large enough to meet the MINIMUM_BREAK_SIZE
diff --git a/t/t4056-diff-order.sh b/t/t4056-diff-order.sh
index aec1d9d1b4..32c5fcb9a2 100755
--- a/t/t4056-diff-order.sh
+++ b/t/t4056-diff-order.sh
@@ -5,6 +5,7 @@ test_description='diff order & rotate'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
create_files () {
diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh
index 605faea0c7..8e0f283c2b 100755
--- a/t/t4204-patch-id.sh
+++ b/t/t4204-patch-id.sh
@@ -5,6 +5,7 @@ test_description='git patch-id'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index a6de7c5764..7044c7d7c6 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -2,6 +2,7 @@
test_description='exercise basic bitmap functionality'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-bitmap.sh
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index 832b92619c..6eaa692f33 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='exercise basic multi-pack bitmap functionality'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "${TEST_DIRECTORY}/lib-bitmap.sh"
diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh
index fc5fedbe9b..445739d06c 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/t6004-rev-list-path-optim.sh b/t/t6004-rev-list-path-optim.sh
index cd4f420e2a..5416241ede 100755
--- a/t/t6004-rev-list-path-optim.sh
+++ b/t/t6004-rev-list-path-optim.sh
@@ -16,6 +16,7 @@ test_description='git rev-list trivial path optimization test
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh
index 738da23628..1aabab6956 100755
--- a/t/t6019-rev-list-ancestry-path.sh
+++ b/t/t6019-rev-list-ancestry-path.sh
@@ -29,6 +29,7 @@ test_description='--ancestry-path'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_merge () {
diff --git a/t/t6111-rev-list-treesame.sh b/t/t6111-rev-list-treesame.sh
index 90ff141640..f63bc8d3da 100755
--- a/t/t6111-rev-list-treesame.sh
+++ b/t/t6111-rev-list-treesame.sh
@@ -16,6 +16,7 @@ test_description='TREESAME and limiting'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
note () {
diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
index 2f9bea9793..64145a05b1 100755
--- a/t/t7061-wtstatus-ignore.sh
+++ b/t/t7061-wtstatus-ignore.sh
@@ -2,6 +2,7 @@
test_description='git-status ignored files'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
cat >expected <<\EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 297c6c3b5c..0f0c86f9cb 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -12,6 +12,7 @@ submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 8d7b234beb..9f68893261 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -12,6 +12,7 @@ that are currently checked out.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
index d6040e0a33..7e1afa9ce4 100755
--- a/t/t7408-submodule-reference.sh
+++ b/t/t7408-submodule-reference.sh
@@ -4,6 +4,8 @@
#
test_description='test clone --reference'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
base_dir=$(pwd)
diff --git a/t/t7411-submodule-config.sh b/t/t7411-submodule-config.sh
index 31271f8e0a..af0de496e0 100755
--- a/t/t7411-submodule-config.sh
+++ b/t/t7411-submodule-config.sh
@@ -10,6 +10,7 @@ from the database and from the worktree works.
'
TEST_NO_CREATE_REPO=1
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7420-submodule-set-url.sh b/t/t7420-submodule-set-url.sh
index bf7f15ee79..d7fe910bbe 100755
--- a/t/t7420-submodule-set-url.sh
+++ b/t/t7420-submodule-set-url.sh
@@ -10,6 +10,7 @@ as expected.
'
TEST_NO_CREATE_REPO=1
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7521-ignored-mode.sh b/t/t7521-ignored-mode.sh
index a88b02b06e..edce10f998 100755
--- a/t/t7521-ignored-mode.sh
+++ b/t/t7521-ignored-mode.sh
@@ -2,6 +2,7 @@
test_description='git status ignored modes'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup initial commit and ignore file' '
diff --git a/t/t7524-commit-summary.sh b/t/t7524-commit-summary.sh
index 47b2f1dc22..a8fceb6a47 100755
--- a/t/t7524-commit-summary.sh
+++ b/t/t7524-commit-summary.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='git commit summary'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh
index a94387a75f..7fd8c086af 100755
--- a/t/t7601-merge-pull-config.sh
+++ b/t/t7601-merge-pull-config.sh
@@ -4,6 +4,7 @@ test_description='git merge
Testing pull.* configuration parsing and other things.'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index be1188e736..c4c3d1a15d 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"
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index cc917b257e..f67b9345b8 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -11,6 +11,7 @@ Testing basic diff tool invocation
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
difftool_test_setup ()
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 167fe66150..55ed630e77 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -7,6 +7,7 @@ submodules.
'
TEST_CREATE_REPO_NO_TEMPLATE=1
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index abae7a9754..c62c42848a 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -2,6 +2,7 @@
test_description='git maintenance builtin'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
GIT_TEST_COMMIT_GRAPH=0
diff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c
index 4f75392952..7b023c1bfc 100644
--- a/trace2/tr2_tls.c
+++ b/trace2/tr2_tls.c
@@ -152,11 +152,19 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)
return us - tr2tls_us_start_process;
}
+static void tr2tls_key_destructor(void *payload)
+{
+ struct tr2tls_thread_ctx *ctx = payload;
+ free((char *)ctx->thread_name);
+ free(ctx->array_us_start);
+ free(ctx);
+}
+
void tr2tls_init(void)
{
tr2tls_start_process_clock();
- pthread_key_create(&tr2tls_key, NULL);
+ pthread_key_create(&tr2tls_key, tr2tls_key_destructor);
init_recursive_mutex(&tr2tls_mutex);
tr2tls_thread_main =