@@ -10,9 +10,12 @@
int cmd_annotate(int argc UNUSED, const char **argv, const char *prefix)
{
struct strvec args = STRVEC_INIT;
+ int ret;
strvec_pushl(&args, argv[0], "-c", NULL);
strvec_pushv(&args, &argv[1]);
- return cmd_blame(args.nr, args.v, prefix);
+ ret = cmd_blame(args.nr, args.v, prefix);
+ strvec_clear(&args);
+ return ret;
}
@@ -597,9 +597,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
if (contains) {
struct string_list_item *item;
- struct strvec args;
+ struct strvec args = STRVEC_INIT;
+ int ret;
- strvec_init(&args);
strvec_pushl(&args, "name-rev",
"--peel-tag", "--name-only", "--no-undefined",
NULL);
@@ -616,7 +616,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
strvec_pushv(&args, argv);
else
strvec_push(&args, "HEAD");
- return cmd_name_rev(args.nr, args.v, prefix);
+ ret = cmd_name_rev(args.nr, args.v, prefix);
+ strvec_clear(&args);
+ return ret;
}
hashmap_init(&names, commit_name_neq, NULL, 0);
@@ -961,6 +961,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
ret = diff_result_code(&rev.diffopt, 0);
cleanup:
strvec_clear(&stash_args);
+ strvec_clear(&revision_args);
free_stash_info(&info);
release_revisions(&rev);
if (do_usage)
@@ -1838,6 +1839,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
OPT_SUBCOMMAND_F("save", &fn, save_stash, PARSE_OPT_NOCOMPLETE),
OPT_END()
};
+ int ret;
git_config(git_stash_config, NULL);
@@ -1861,5 +1863,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
/* Assume 'stash push' */
strvec_push(&args, "push");
strvec_pushv(&args, argv);
- return !!push_stash(args.nr, args.v, prefix, 1);
+ ret = !!push_stash(args.nr, args.v, prefix, 1);
+ strvec_clear(&args);
+ return ret;
}
@@ -21,6 +21,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
{
struct strvec sent_argv = STRVEC_INIT;
const char *arg_cmd = "argument ";
+ int ret;
if (argc != 2 || !strcmp(argv[1], "-h"))
usage(upload_archive_usage);
@@ -45,8 +46,10 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
}
/* parse all options sent by the client */
- return write_archive(sent_argv.nr, sent_argv.v, prefix,
- the_repository, NULL, 1);
+ ret = write_archive(sent_argv.nr, sent_argv.v, prefix,
+ the_repository, NULL, 1);
+ strvec_clear(&sent_argv);
+ return ret;
}
__attribute__((format (printf, 1, 2)))
Fix or partially fix memory leaks that happened because a strvec_clear() was missing. The "partially" will be addressed in a subsequent commit, we'll still leak in cases where the function we're calling munges our "v" member. In the case of "builtin/describe.c" let's change it to use the macro initializer rather than the strvec_init() while we're at it. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/annotate.c | 5 ++++- builtin/describe.c | 8 +++++--- builtin/stash.c | 6 +++++- builtin/upload-archive.c | 7 +++++-- 4 files changed, 19 insertions(+), 7 deletions(-)