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_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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user