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
This commit is contained in:
commit
192a3fa31d
@ -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(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
|
||||||
INIT_DB_QUIET);
|
INIT_DB_QUIET);
|
||||||
|
|
||||||
if (real_git_dir)
|
if (real_git_dir) {
|
||||||
|
free((char *)git_dir);
|
||||||
git_dir = real_git_dir;
|
git_dir = real_git_dir;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* additional config can be injected with -c, make sure it's included
|
* additional config can be injected with -c, make sure it's included
|
||||||
|
@ -199,8 +199,8 @@ static void *run(void *arg)
|
|||||||
grep_source_clear_data(&w->source);
|
grep_source_clear_data(&w->source);
|
||||||
work_done(w);
|
work_done(w);
|
||||||
}
|
}
|
||||||
free_grep_patterns(arg);
|
free_grep_patterns(opt);
|
||||||
free(arg);
|
free(opt);
|
||||||
|
|
||||||
return (void*) (intptr_t) hit;
|
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')
|
if (len == 1 && *(const char *)data == '\0')
|
||||||
return;
|
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)
|
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 grep_opt opt;
|
||||||
struct object_array list = OBJECT_ARRAY_INIT;
|
struct object_array list = OBJECT_ARRAY_INIT;
|
||||||
struct pathspec pathspec;
|
struct pathspec pathspec;
|
||||||
struct string_list path_list = STRING_LIST_INIT_NODUP;
|
struct string_list path_list = STRING_LIST_INIT_DUP;
|
||||||
int i;
|
int i;
|
||||||
int dummy;
|
int dummy;
|
||||||
int use_index = 1;
|
int use_index = 1;
|
||||||
@ -1159,8 +1159,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
|||||||
strbuf_addf(&buf, "+/%s%s",
|
strbuf_addf(&buf, "+/%s%s",
|
||||||
strcmp("less", pager) ? "" : "*",
|
strcmp("less", pager) ? "" : "*",
|
||||||
opt.pattern_list->pattern);
|
opt.pattern_list->pattern);
|
||||||
string_list_append(&path_list,
|
string_list_append_nodup(&path_list,
|
||||||
strbuf_detach(&buf, NULL));
|
strbuf_detach(&buf, NULL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1195,7 +1195,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
|||||||
if (hit && show_in_pager)
|
if (hit && show_in_pager)
|
||||||
run_pager(&opt, prefix);
|
run_pager(&opt, prefix);
|
||||||
clear_pathspec(&pathspec);
|
clear_pathspec(&pathspec);
|
||||||
|
string_list_clear(&path_list, 0);
|
||||||
free_grep_patterns(&opt);
|
free_grep_patterns(&opt);
|
||||||
|
object_array_clear(&list);
|
||||||
free_repos();
|
free_repos();
|
||||||
return !hit;
|
return !hit;
|
||||||
}
|
}
|
||||||
|
@ -653,6 +653,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
|
|||||||
should_expire_reflog_ent,
|
should_expire_reflog_ent,
|
||||||
reflog_expiry_cleanup,
|
reflog_expiry_cleanup,
|
||||||
&cb);
|
&cb);
|
||||||
|
free(ref);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -3220,6 +3220,7 @@ static void die_on_index_match(const char *path, int force)
|
|||||||
}
|
}
|
||||||
free(ps_matched);
|
free(ps_matched);
|
||||||
}
|
}
|
||||||
|
clear_pathspec(&ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void die_on_repo_without_commits(const char *path)
|
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)
|
if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
|
||||||
die(_("'%s' does not have a commit checked out"), path);
|
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)
|
static int module_add(int argc, const char **argv, const char *prefix)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
test_description='git grep --open-files-in-pager
|
test_description='git grep --open-files-in-pager
|
||||||
'
|
'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
. "$TEST_DIRECTORY"/lib-pager.sh
|
. "$TEST_DIRECTORY"/lib-pager.sh
|
||||||
unset PAGER GIT_PAGER
|
unset PAGER GIT_PAGER
|
||||||
@ -114,8 +115,8 @@ test_expect_success 'modified file' '
|
|||||||
unrelated
|
unrelated
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_when_finished "git reset --hard" &&
|
||||||
echo "enum grep_pat_token" >unrelated &&
|
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 &&
|
GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
|
||||||
test_cmp expect actual &&
|
test_cmp expect actual &&
|
||||||
test_must_be_empty out
|
test_must_be_empty out
|
||||||
|
Loading…
Reference in New Issue
Block a user