summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-10-29 15:43:13 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-10-29 15:43:13 -0700
commit192a3fa31dbb3bb5dbcc64b6587a2763839d784b (patch)
tree1bbcb177359e702323458b4d1c52dc51ce9a9cb4
parentMerge branch 'ab/plug-handle-path-exclude-leak' (diff)
parentreflog: free() ref given to us by dwim_log() (diff)
downloadtgif-192a3fa31dbb3bb5dbcc64b6587a2763839d784b.tar.xz
Merge branch 'ab/plug-random-leaks'
Leakfix. * ab/plug-random-leaks: reflog: free() ref given to us by dwim_log() submodule--helper: fix small memory leaks clone: fix a memory leak of the "git_dir" variable grep: fix a "path_list" memory leak grep: use object_array_clear() in cmd_grep() grep: prefer "struct grep_opt" over its "void *" equivalent
-rw-r--r--builtin/clone.c4
-rw-r--r--builtin/grep.c14
-rw-r--r--builtin/reflog.c1
-rw-r--r--builtin/submodule--helper.c2
-rwxr-xr-xt/t7811-grep-open.sh3
5 files changed, 16 insertions, 8 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 559acf9e03..fb377b2765 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1040,8 +1040,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
INIT_DB_QUIET);
- if (real_git_dir)
+ if (real_git_dir) {
+ free((char *)git_dir);
git_dir = real_git_dir;
+ }
/*
* additional config can be injected with -c, make sure it's included
diff --git a/builtin/grep.c b/builtin/grep.c
index 8af5249a7b..9e34a820ad 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -199,8 +199,8 @@ static void *run(void *arg)
grep_source_clear_data(&w->source);
work_done(w);
}
- free_grep_patterns(arg);
- free(arg);
+ free_grep_patterns(opt);
+ free(opt);
return (void*) (intptr_t) hit;
}
@@ -401,7 +401,7 @@ static void append_path(struct grep_opt *opt, const void *data, size_t len)
if (len == 1 && *(const char *)data == '\0')
return;
- string_list_append(path_list, xstrndup(data, len));
+ string_list_append_nodup(path_list, xstrndup(data, len));
}
static void run_pager(struct grep_opt *opt, const char *prefix)
@@ -839,7 +839,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
struct grep_opt opt;
struct object_array list = OBJECT_ARRAY_INIT;
struct pathspec pathspec;
- struct string_list path_list = STRING_LIST_INIT_NODUP;
+ struct string_list path_list = STRING_LIST_INIT_DUP;
int i;
int dummy;
int use_index = 1;
@@ -1159,8 +1159,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
strbuf_addf(&buf, "+/%s%s",
strcmp("less", pager) ? "" : "*",
opt.pattern_list->pattern);
- string_list_append(&path_list,
- strbuf_detach(&buf, NULL));
+ string_list_append_nodup(&path_list,
+ strbuf_detach(&buf, NULL));
}
}
@@ -1195,7 +1195,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (hit && show_in_pager)
run_pager(&opt, prefix);
clear_pathspec(&pathspec);
+ string_list_clear(&path_list, 0);
free_grep_patterns(&opt);
+ object_array_clear(&list);
free_repos();
return !hit;
}
diff --git a/builtin/reflog.c b/builtin/reflog.c
index bd4c669918..175c83e7cc 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -653,6 +653,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
should_expire_reflog_ent,
reflog_expiry_cleanup,
&cb);
+ free(ref);
}
return status;
}
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6298cbdd4e..a157656a48 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -3220,6 +3220,7 @@ static void die_on_index_match(const char *path, int force)
}
free(ps_matched);
}
+ clear_pathspec(&ps);
}
static void die_on_repo_without_commits(const char *path)
@@ -3231,6 +3232,7 @@ static void die_on_repo_without_commits(const char *path)
if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
die(_("'%s' does not have a commit checked out"), path);
}
+ strbuf_release(&sb);
}
static int module_add(int argc, const char **argv, const char *prefix)
diff --git a/t/t7811-grep-open.sh b/t/t7811-grep-open.sh
index a98785da79..1dd07141a7 100755
--- a/t/t7811-grep-open.sh
+++ b/t/t7811-grep-open.sh
@@ -3,6 +3,7 @@
test_description='git grep --open-files-in-pager
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-pager.sh
unset PAGER GIT_PAGER
@@ -114,8 +115,8 @@ test_expect_success 'modified file' '
unrelated
EOF
+ test_when_finished "git reset --hard" &&
echo "enum grep_pat_token" >unrelated &&
- test_when_finished "git checkout HEAD unrelated" &&
GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
test_cmp expect actual &&
test_must_be_empty out