From 542627a4f79ffe1c21e759508ee3c6c4f1211be6 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:32 +0200 Subject: [PATCH 01/34] am: release strbufs after use in detect_patch_format() Don't reset the strbufs l2 and l3 before use as if they were static, but release them at the end instead. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/am.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index c369dd1dce..3c50b03faa 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -671,9 +671,7 @@ static int detect_patch_format(const char **paths) goto done; } - strbuf_reset(&l2); strbuf_getline(&l2, fp); - strbuf_reset(&l3); strbuf_getline(&l3, fp); /* @@ -696,6 +694,8 @@ static int detect_patch_format(const char **paths) done: fclose(fp); strbuf_release(&l1); + strbuf_release(&l2); + strbuf_release(&l3); return ret; } From b36474ff6b4c7d0a4939b7551c576ef3de7e4719 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:33 +0200 Subject: [PATCH 02/34] am: release strbuf on error return in hg_patch_to_mail() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/am.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 3c50b03faa..3d38b3fe9f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -881,6 +881,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr) { struct strbuf sb = STRBUF_INIT; + int rc = 0; while (!strbuf_getline_lf(&sb, in)) { const char *str; @@ -894,19 +895,27 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr) errno = 0; timestamp = parse_timestamp(str, &end, 10); - if (errno) - return error(_("invalid timestamp")); + if (errno) { + rc = error(_("invalid timestamp")); + goto exit; + } - if (!skip_prefix(end, " ", &str)) - return error(_("invalid Date line")); + if (!skip_prefix(end, " ", &str)) { + rc = error(_("invalid Date line")); + goto exit; + } errno = 0; tz = strtol(str, &end, 10); - if (errno) - return error(_("invalid timezone offset")); + if (errno) { + rc = error(_("invalid timezone offset")); + goto exit; + } - if (*end) - return error(_("invalid Date line")); + if (*end) { + rc = error(_("invalid Date line")); + goto exit; + } /* * mercurial's timezone is in seconds west of UTC, @@ -931,9 +940,9 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr) fwrite(sb.buf, 1, sb.len, out); strbuf_reset(&sb); } - +exit: strbuf_release(&sb); - return 0; + return rc; } /** From 28ac7aa79b9e7865124aec0eb552a1e3cc9ecdd7 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:34 +0200 Subject: [PATCH 03/34] am: release strbuf after use in safe_to_abort() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/am.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/am.c b/builtin/am.c index 3d38b3fe9f..d7513f5375 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2105,6 +2105,7 @@ static int safe_to_abort(const struct am_state *state) die(_("could not parse %s"), am_path(state, "abort-safety")); } else oidclr(&abort_safety); + strbuf_release(&sb); if (get_oid("HEAD", &head)) oidclr(&head); From 861e65557f14a0d93af780c71d82f194404dd563 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:35 +0200 Subject: [PATCH 04/34] check-ref-format: release strbuf after use in check_ref_format_branch() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/check-ref-format.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index eac499450f..6c40ff110b 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -45,6 +45,7 @@ static int check_ref_format_branch(const char *arg) if (strbuf_check_branch_ref(&sb, arg)) die("'%s' is not a valid branch name", arg); printf("%s\n", sb.buf + 11); + strbuf_release(&sb); return 0; } From 25a8f80a8482d74225587fb2f667a8f296a58c48 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:36 +0200 Subject: [PATCH 05/34] clean: release strbuf after use in remove_dirs() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/clean.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index 21a7a32994..733b6d3745 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -167,7 +167,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, } *dir_gone = 0; - return 0; + goto out; } dir = opendir(path->buf); @@ -181,7 +181,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; } - return res; + ret = res; + goto out; } strbuf_complete(path, '/'); @@ -249,6 +250,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, for (i = 0; i < dels.nr; i++) printf(dry_run ? _(msg_would_remove) : _(msg_remove), dels.items[i].string); } +out: + strbuf_release("ed); string_list_clear(&dels, 0); return ret; } From 9c18b5488eb78d293578a4914fc8646a0e40460a Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:37 +0200 Subject: [PATCH 06/34] clone: release strbuf after use in remove_junk() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/clone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/clone.c b/builtin/clone.c index 8d11b570a1..dbddd98f80 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -507,8 +507,8 @@ static void remove_junk(void) if (junk_work_tree) { strbuf_addstr(&sb, junk_work_tree); remove_dir_recursively(&sb, 0); - strbuf_reset(&sb); } + strbuf_release(&sb); } static void remove_junk_on_signal(int signo) From e505146dac276cc051eca199f9dc7ca88bef5f18 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:38 +0200 Subject: [PATCH 07/34] commit: release strbuf on error return in commit_tree_extended() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- commit.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commit.c b/commit.c index 8b28415939..51f969fcbc 100644 --- a/commit.c +++ b/commit.c @@ -1564,10 +1564,13 @@ int commit_tree_extended(const char *msg, size_t msg_len, if (encoding_is_utf8 && !verify_utf8(&buffer)) fprintf(stderr, _(commit_utf8_warn)); - if (sign_commit && do_sign_commit(&buffer, sign_commit)) - return -1; + if (sign_commit && do_sign_commit(&buffer, sign_commit)) { + result = -1; + goto out; + } result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret); +out: strbuf_release(&buffer); return result; } From f13992917b97766a29ecd05caea7f74431fb30a6 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:39 +0200 Subject: [PATCH 08/34] connect: release strbuf on error return in git_connect() Reduce the scope of the variable cmd and release it before returning early. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- connect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connect.c b/connect.c index 49b28b83be..df56c0cbff 100644 --- a/connect.c +++ b/connect.c @@ -778,7 +778,6 @@ struct child_process *git_connect(int fd[2], const char *url, char *hostandport, *path; struct child_process *conn = &no_fork; enum protocol protocol; - struct strbuf cmd = STRBUF_INIT; /* Without this we cannot rely on waitpid() to tell * what happened to our children. @@ -826,6 +825,8 @@ struct child_process *git_connect(int fd[2], const char *url, target_host, 0); free(target_host); } else { + struct strbuf cmd = STRBUF_INIT; + conn = xmalloc(sizeof(*conn)); child_process_init(conn); @@ -862,6 +863,7 @@ struct child_process *git_connect(int fd[2], const char *url, free(hostandport); free(path); free(conn); + strbuf_release(&cmd); return NULL; } From f31f1d395131f84acbee14f42af8f702bca14468 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:40 +0200 Subject: [PATCH 09/34] convert: release strbuf on error return in filter_buffer_or_fd() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- convert.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/convert.c b/convert.c index c5f0b21037..4a0ed8d3cb 100644 --- a/convert.c +++ b/convert.c @@ -423,8 +423,10 @@ static int filter_buffer_or_fd(int in, int out, void *data) child_process.in = -1; child_process.out = out; - if (start_command(&child_process)) + if (start_command(&child_process)) { + strbuf_release(&cmd); return error("cannot fork to run external filter '%s'", params->cmd); + } sigchain_push(SIGPIPE, SIG_IGN); From fa842d843d4ed336cc21ba45d2d13ff83c63b22f Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:41 +0200 Subject: [PATCH 10/34] diff: release strbuf after use in diff_summary() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- diff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/diff.c b/diff.c index 3d3e553a98..4148ba6980 100644 --- a/diff.c +++ b/diff.c @@ -5314,6 +5314,7 @@ static void diff_summary(struct diff_options *opt, struct diff_filepair *p) strbuf_addf(&sb, " (%d%%)\n", similarity_index(p)); emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY, sb.buf, sb.len, 0); + strbuf_release(&sb); } show_mode_change(opt, p, !p->score); break; From 348eda249ebe1d91c832749e8bb3a0e7b7112b43 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:42 +0200 Subject: [PATCH 11/34] diff: release strbuf after use in show_rename_copy() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- diff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/diff.c b/diff.c index 4148ba6980..33c65f492d 100644 --- a/diff.c +++ b/diff.c @@ -5289,6 +5289,7 @@ static void show_rename_copy(struct diff_options *opt, const char *renamecopy, emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY, sb.buf, sb.len, 0); show_mode_change(opt, p, 0); + strbuf_release(&sb); } static void diff_summary(struct diff_options *opt, struct diff_filepair *p) From 5a612017eb7865de10dc21f3d3f8856e8205456e Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:43 +0200 Subject: [PATCH 12/34] diff: release strbuf after use in show_stats() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- diff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/diff.c b/diff.c index 33c65f492d..64cdcf2331 100644 --- a/diff.c +++ b/diff.c @@ -2583,6 +2583,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) } print_stat_summary_inserts_deletes(options, total_files, adds, dels); + strbuf_release(&out); } static void show_shortstats(struct diffstat_t *data, struct diff_options *options) From a981a9f0e7fb0d2a65fc3c4532fdfc38cc275c48 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:44 +0200 Subject: [PATCH 13/34] help: release strbuf on error return in exec_man_konqueror() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/help.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/help.c b/builtin/help.c index 334a8494ab..991a8bb16c 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -152,6 +152,7 @@ static void exec_man_konqueror(const char *path, const char *page) strbuf_addf(&man_page, "man:%s(1)", page); execlp(path, filename, "newTab", man_page.buf, (char *)NULL); warning_errno(_("failed to exec '%s'"), path); + strbuf_release(&man_page); } } From 7246218667635252395debc8eff2304592cbd587 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:45 +0200 Subject: [PATCH 14/34] help: release strbuf on error return in exec_man_man() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/help.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/help.c b/builtin/help.c index 991a8bb16c..12fb48933e 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -170,6 +170,7 @@ static void exec_man_cmd(const char *cmd, const char *page) strbuf_addf(&shell_cmd, "%s %s", cmd, page); execl(SHELL_PATH, SHELL_PATH, "-c", shell_cmd.buf, (char *)NULL); warning(_("failed to exec '%s'"), cmd); + strbuf_release(&shell_cmd); } static void add_man_viewer(const char *name) From bad0e2c6a89b52b0d6b2ebae6e290b6d4e6f799c Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:46 +0200 Subject: [PATCH 15/34] help: release strbuf on error return in exec_woman_emacs() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/help.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/help.c b/builtin/help.c index 12fb48933e..b3f60a8f30 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -131,6 +131,7 @@ static void exec_woman_emacs(const char *path, const char *page) strbuf_addf(&man_page, "(woman \"%s\")", page); execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL); warning_errno(_("failed to exec '%s'"), path); + strbuf_release(&man_page); } } From 11fa5e2a81cc921b55a4a91f2e5f39d423f18467 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:47 +0200 Subject: [PATCH 16/34] mailinfo: release strbuf after use in handle_from() Clean up at the end and jump there instead of returning early. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- mailinfo.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mailinfo.c b/mailinfo.c index bd574cb752..b1f5159546 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -149,16 +149,14 @@ static void handle_from(struct mailinfo *mi, const struct strbuf *from) at = strchr(f.buf, '@'); if (!at) { parse_bogus_from(mi, from); - return; + goto out; } /* * If we already have one email, don't take any confusing lines */ - if (mi->email.len && strchr(at + 1, '@')) { - strbuf_release(&f); - return; - } + if (mi->email.len && strchr(at + 1, '@')) + goto out; /* Pick up the string around '@', possibly delimited with <> * pair; that is the email part. @@ -198,6 +196,7 @@ static void handle_from(struct mailinfo *mi, const struct strbuf *from) } get_sane_name(&mi->name, &f, &mi->email); +out: strbuf_release(&f); } From 400cd6bf22cbd3f0d8e555aa2f1e4751869960bf Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:48 +0200 Subject: [PATCH 17/34] mailinfo: release strbuf on error return in handle_boundary() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- mailinfo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mailinfo.c b/mailinfo.c index b1f5159546..f2387a3267 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -928,6 +928,7 @@ again: error("Detected mismatched boundaries, can't recover"); mi->input_error = -1; mi->content_top = mi->content; + strbuf_release(&newline); return 0; } handle_filter(mi, &newline); From 150888e2733fa932949dad88af1b049193ef096f Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:49 +0200 Subject: [PATCH 18/34] merge: release strbuf after use in save_state() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/merge.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 7df3fe3927..4f8418246b 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -253,6 +253,7 @@ static int save_state(struct object_id *stash) struct child_process cp = CHILD_PROCESS_INIT; struct strbuf buffer = STRBUF_INIT; const char *argv[] = {"stash", "create", NULL}; + int rc = -1; cp.argv = argv; cp.out = -1; @@ -266,11 +267,14 @@ static int save_state(struct object_id *stash) if (finish_command(&cp) || len < 0) die(_("stash failed")); else if (!len) /* no changes */ - return -1; + goto out; strbuf_setlen(&buffer, buffer.len-1); if (get_oid(buffer.buf, stash)) die(_("not a valid object: %s"), buffer.buf); - return 0; + rc = 0; +out: + strbuf_release(&buffer); + return rc; } static void read_empty(unsigned const char *sha1, int verbose) From 814c4b374710c297e8538916814483b2098593c4 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:50 +0200 Subject: [PATCH 19/34] merge: release strbuf after use in write_merge_heads() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/merge.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/merge.c b/builtin/merge.c index 4f8418246b..7bc3fe4b6d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -938,6 +938,7 @@ static void write_merge_heads(struct commit_list *remoteheads) if (fast_forward == FF_NO) strbuf_addstr(&buf, "no-ff"); write_file_buf(git_path_merge_mode(), buf.buf, buf.len); + strbuf_release(&buf); } static void write_merge_state(struct commit_list *remoteheads) From 1f3992f4be09d47dd45af253743ac233c21f7986 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:57:30 +0200 Subject: [PATCH 20/34] notes: release strbuf after use in notes_copy_from_stdin() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/notes.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/notes.c b/builtin/notes.c index 4303848e04..8e54f2d146 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -328,6 +328,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd) } else { finish_copy_notes_for_rewrite(c, msg); } + strbuf_release(&buf); return ret; } From aeb014f6aecab6c72490dbe00fd9518b2c75db11 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:58:12 +0200 Subject: [PATCH 21/34] refs: release strbuf on error return in write_pseudoref() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- refs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs.c b/refs.c index b0106b8162..d8dc86b1f5 100644 --- a/refs.c +++ b/refs.c @@ -612,7 +612,7 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1, if (fd < 0) { strbuf_addf(err, "could not open '%s' for writing: %s", filename, strerror(errno)); - return -1; + goto done; } if (old_sha1) { From e2581b7221f52c30432dfc1a8934abd82b610e7c Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:00:25 +0200 Subject: [PATCH 22/34] remote: release strbuf after use in read_remote_branches() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/remote.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/remote.c b/builtin/remote.c index a995ea86c1..d0bf999abf 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -571,6 +571,7 @@ static int read_remote_branches(const char *refname, else item->util = NULL; } + strbuf_release(&buf); return 0; } From b95c8ce8f3696bd11b38894bb775da17921cc3b8 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:00:26 +0200 Subject: [PATCH 23/34] remote: release strbuf after use in migrate_file() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/remote.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/remote.c b/builtin/remote.c index d0bf999abf..0a56d7da66 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -596,6 +596,7 @@ static int migrate_file(struct remote *remote) unlink_or_warn(git_path("remotes/%s", remote->name)); else if (remote->origin == REMOTE_BRANCHES) unlink_or_warn(git_path("branches/%s", remote->name)); + strbuf_release(&buf); return 0; } From 85af9f7a027dc5880fd88d65414df2dc6c6f9366 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:00:27 +0200 Subject: [PATCH 24/34] remote: release strbuf after use in set_url() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/remote.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 0a56d7da66..33ba739332 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1565,9 +1565,7 @@ static int set_url(int argc, const char **argv) "^$", 0); else git_config_set(name_buf.buf, newurl); - strbuf_release(&name_buf); - - return 0; + goto out; } /* Old URL specified. Demand that one matches. */ @@ -1590,6 +1588,8 @@ static int set_url(int argc, const char **argv) git_config_set_multivar(name_buf.buf, newurl, oldurl, 0); else git_config_set_multivar(name_buf.buf, NULL, oldurl, 1); +out: + strbuf_release(&name_buf); return 0; } From 872d651f528443efa5586a2d81a7629448545f61 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:00:28 +0200 Subject: [PATCH 25/34] send-pack: release strbuf on error return in send_pack() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- send-pack.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/send-pack.c b/send-pack.c index 11d6f3d983..b865f662e4 100644 --- a/send-pack.c +++ b/send-pack.c @@ -492,8 +492,11 @@ int send_pack(struct send_pack_args *args, * we were to send it and we're trying to send the refs * atomically, abort the whole operation. */ - if (use_atomic) + if (use_atomic) { + strbuf_release(&req_buf); + strbuf_release(&cap_buf); return atomic_push_failure(args, remote_refs, ref); + } /* Fallthrough for non atomic case. */ default: continue; From ea8e029785f87dc167491ebbc7ea3e924a72b5c4 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:00:29 +0200 Subject: [PATCH 26/34] sha1_file: release strbuf on error return in index_path() strbuf_readlink() already frees the buffer for us on error. Clean up if write_sha1_file() fails as well instead of returning early. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- sha1_file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index f56bb5cae7..7d9c9aed2f 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1820,6 +1820,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne { int fd; struct strbuf sb = STRBUF_INIT; + int rc = 0; switch (st->st_mode & S_IFMT) { case S_IFREG: @@ -1836,8 +1837,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne if (!(flags & HASH_WRITE_OBJECT)) hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash); else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash)) - return error("%s: failed to insert into database", - path); + rc = error("%s: failed to insert into database", path); strbuf_release(&sb); break; case S_IFDIR: @@ -1845,7 +1845,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne default: return error("%s: unsupported file type", path); } - return 0; + return rc; } int read_pack_header(int fd, struct pack_header *header) From 557d3185ee22ec44bb6965467b14a76d9c33e571 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:00:30 +0200 Subject: [PATCH 27/34] shortlog: release strbuf after use in insert_one_record() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/shortlog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 43c4799ea9..48af16c681 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -72,6 +72,7 @@ static void insert_one_record(struct shortlog *log, strbuf_addf(&namemailbuf, " <%.*s>", (int)maillen, mailbuf); item = string_list_insert(&log->list, namemailbuf.buf); + strbuf_release(&namemailbuf); if (log->summary) item->util = (void *)(UTIL_TO_INT(item) + 1); From ed3f9a12d10c3a8aa3eace86e4d8139e723c2087 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:14 +0200 Subject: [PATCH 28/34] sequencer: release strbuf after use in save_head() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- sequencer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index fcceabb80f..60636ce54b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1565,6 +1565,7 @@ static int save_head(const char *head) static struct lock_file head_lock; struct strbuf buf = STRBUF_INIT; int fd; + ssize_t written; fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0); if (fd < 0) { @@ -1572,7 +1573,9 @@ static int save_head(const char *head) return error_errno(_("could not lock HEAD")); } strbuf_addf(&buf, "%s\n", head); - if (write_in_full(fd, buf.buf, buf.len) < 0) { + written = write_in_full(fd, buf.buf, buf.len); + strbuf_release(&buf); + if (written < 0) { rollback_lock_file(&head_lock); return error_errno(_("could not write to '%s'"), git_path_head_file()); From 4168be8e39bd75084a8d49eda4390a5b5a1e68a6 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:15 +0200 Subject: [PATCH 29/34] transport-helper: release strbuf after use in process_connect_service() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- transport-helper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/transport-helper.c b/transport-helper.c index 8f68d69a86..519a244583 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -604,6 +604,7 @@ static int process_connect_service(struct transport *transport, cmdbuf.buf); exit: + strbuf_release(&cmdbuf); fclose(input); return ret; } From 460c7eb2bf5540384dfc18ace59abec6fa3aa009 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:15 +0200 Subject: [PATCH 30/34] userdiff: release strbuf after use in userdiff_get_textconv() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- userdiff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/userdiff.c b/userdiff.c index 2c1502f719..6321103ce2 100644 --- a/userdiff.c +++ b/userdiff.c @@ -293,6 +293,7 @@ struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver) strbuf_addf(&name, "textconv/%s", driver->name); notes_cache_init(c, name.buf, driver->textconv); driver->textconv_cache = c; + strbuf_release(&name); } return driver; From 9a012bf32a3b21648ab96f2bd234a563c22e0ae7 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:16 +0200 Subject: [PATCH 31/34] utf8: release strbuf on error return in strbuf_utf8_replace() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- utf8.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utf8.c b/utf8.c index 0c8e011a58..47a42047c8 100644 --- a/utf8.c +++ b/utf8.c @@ -381,7 +381,7 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width, old = src; n = utf8_width((const char**)&src, NULL); if (!src) /* broken utf-8, do nothing */ - return; + goto out; if (n && w >= pos && w < pos + width) { if (subst) { memcpy(dst, subst, subst_len); @@ -397,6 +397,7 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width, } strbuf_setlen(&sb_dst, dst - sb_dst.buf); strbuf_swap(sb_src, &sb_dst); +out: strbuf_release(&sb_dst); } From 9f00492161f5f5ff90395c3b3e11137a87a1562d Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:17 +0200 Subject: [PATCH 32/34] vcs-svn: release strbuf after use in end_revision() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- vcs-svn/svndump.c | 1 + 1 file changed, 1 insertion(+) diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index ec6b350611..08d136b8cc 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -318,6 +318,7 @@ static void end_revision(const char *note_ref) strbuf_addf(&mark, ":%"PRIu32, rev_ctx.revision); fast_export_note(mark.buf, "inline"); fast_export_buf_to_data(&rev_ctx.note); + strbuf_release(&mark); } } From 6f49541ddbcb91a7bd5948f204f56bf5742dd75d Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:17 +0200 Subject: [PATCH 33/34] wt-status: release strbuf after use in read_rebase_todolist() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- wt-status.c | 1 + 1 file changed, 1 insertion(+) diff --git a/wt-status.c b/wt-status.c index 77c27c5113..cafafb5ecd 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1193,6 +1193,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines) string_list_append(lines, line.buf); } fclose(f); + strbuf_release(&line); return 0; } From b6ec3071774fb4eab406e76c29cbf1a5f27929a8 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 20:20:18 +0200 Subject: [PATCH 34/34] wt-status: release strbuf after use in wt_longstatus_print_tracking() If format_tracking_info() returns 0, then it didn't touch its strbuf parameter, so it's OK to exit early in that case. Clean up sb in the other case. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- wt-status.c | 1 + 1 file changed, 1 insertion(+) diff --git a/wt-status.c b/wt-status.c index cafafb5ecd..ac972acbab 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1026,6 +1026,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s) comment_line_char); else fputs("\n", s->fp); + strbuf_release(&sb); } static int has_unmerged(struct wt_status *s)