From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [RFC PATCH v2 1/4] tag: use a "goto cleanup" pattern, leak less memory
Date: Wed, 20 Oct 2021 07:37:03 -0700 [thread overview]
Message-ID: <xmqqwnm7rcds.fsf@gitster.g> (raw)
In-Reply-To: <RFC-patch-v2-1.4-fc776c3f1cd-20211020T131627Z-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Wed, 20 Oct 2021 15:24:33 +0200")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Change cmd_tag() to free its "struct string_list"'s instead of using
string_list -> strbuf
> an UNLEAK() pattern. This changes code added in 886e1084d78 (builtin/:
> add UNLEAKs, 2017-10-01).
>
> As shown in the context of the deceleration of the "struct
deceleration?
> msg_arg" (which I'm changing to use a designated initializer while at
> it, and to show the context in this change), that struct is just a
> thin wrapper around an int and "struct strbuf".
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> builtin/tag.c | 28 ++++++++++++++++------------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/builtin/tag.c b/builtin/tag.c
> index 6535ed27ee9..ad6c9855914 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -432,7 +432,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> int annotate = 0, force = 0;
> int cmdmode = 0, create_tag_object = 0;
> const char *msgfile = NULL, *keyid = NULL;
> - struct msg_arg msg = { 0, STRBUF_INIT };
> + struct msg_arg msg = { .buf = STRBUF_INIT };
> struct ref_transaction *transaction;
> struct strbuf err = STRBUF_INIT;
> struct ref_filter filter;
> @@ -482,6 +482,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
> OPT_END()
> };
> + int ret = 0;
>
> setup_ref_filter_porcelain_msg();
>
> @@ -529,7 +530,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
> filter.ignore_case = icase;
> if (cmdmode == 'l') {
> - int ret;
> if (column_active(colopts)) {
> struct column_options copts;
> memset(&copts, 0, sizeof(copts));
> @@ -540,7 +540,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> ret = list_tags(&filter, sorting, &format);
> if (column_active(colopts))
> stop_column_filter();
> - return ret;
> + goto cleanup;
> }
> if (filter.lines != -1)
> die(_("-n option is only allowed in list mode"));
> @@ -552,12 +552,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> die(_("--points-at option is only allowed in list mode"));
> if (filter.reachable_from || filter.unreachable_from)
> die(_("--merged and --no-merged options are only allowed in list mode"));
> - if (cmdmode == 'd')
> - return delete_tags(argv);
> + if (cmdmode == 'd') {
> + ret = delete_tags(argv);
> + goto cleanup;
> + }
> if (cmdmode == 'v') {
> if (format.format && verify_ref_format(&format))
> usage_with_options(git_tag_usage, options);
> - return for_each_tag_name(argv, verify_tag, &format);
> + ret = for_each_tag_name(argv, verify_tag, &format);
> + goto cleanup;
> }
>
> if (msg.given || msgfile) {
> @@ -626,10 +629,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> printf(_("Updated tag '%s' (was %s)\n"), tag,
> find_unique_abbrev(&prev, DEFAULT_ABBREV));
>
> - UNLEAK(buf);
> - UNLEAK(ref);
> - UNLEAK(reflog_msg);
> - UNLEAK(msg);
> - UNLEAK(err);
> - return 0;
> +cleanup:
> + strbuf_release(&buf);
> + strbuf_release(&ref);
> + strbuf_release(&reflog_msg);
> + strbuf_release(&msg.buf);
> + strbuf_release(&err);
> + return ret;
> }
next prev parent reply other threads:[~2021-10-20 14:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-18 18:32 [PATCH] for-each-ref: delay parsing of --sort=<atom> options Junio C Hamano
2021-10-19 22:18 ` Jeff King
2021-10-20 2:20 ` Jeff King
2021-10-20 12:30 ` Ævar Arnfjörð Bjarmason
2021-10-20 13:24 ` [RFC PATCH v2 0/4] for-each-ref: delay parsing of --sort=<atom> options + linux-leaks fixes Ævar Arnfjörð Bjarmason
2021-10-20 13:24 ` [RFC PATCH v2 1/4] tag: use a "goto cleanup" pattern, leak less memory Ævar Arnfjörð Bjarmason
2021-10-20 14:37 ` Junio C Hamano [this message]
2021-10-20 13:24 ` [RFC PATCH v2 2/4] ref-filter API user: add and use a ref_sorting_release() Ævar Arnfjörð Bjarmason
2021-10-20 14:39 ` Junio C Hamano
2021-10-20 13:24 ` [RFC PATCH v2 3/4] for-each-ref: delay parsing of --sort=<atom> options Ævar Arnfjörð Bjarmason
2021-10-20 13:24 ` [RFC PATCH v2 4/4] branch: use ref_sorting_release() Ævar Arnfjörð Bjarmason
2021-10-20 14:43 ` [RFC PATCH v2 0/4] for-each-ref: delay parsing of --sort=<atom> options + linux-leaks fixes Junio C Hamano
2021-10-20 18:27 ` [PATCH 0/3] ref-filter: add a ref_sorting_release() Ævar Arnfjörð Bjarmason
2021-10-20 18:27 ` [PATCH 1/3] tag: use a "goto cleanup" pattern, leak less memory Ævar Arnfjörð Bjarmason
2021-10-20 18:27 ` [PATCH 2/3] ref-filter API user: add and use a ref_sorting_release() Ævar Arnfjörð Bjarmason
2021-10-20 18:27 ` [PATCH 3/3] branch: use ref_sorting_release() Ævar Arnfjörð Bjarmason
2021-10-20 13:58 ` [PATCH] for-each-ref: delay parsing of --sort=<atom> options Junio C Hamano
2021-10-20 20:48 ` Jeff King
2021-10-20 21:32 ` Junio C Hamano
2021-10-21 14:54 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqwnm7rcds.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).