From: Junio C Hamano <gitster@pobox.com>
To: Olga Telezhnaya <olyatelezhnaya@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] ref-filter: free item->value and item->value->s
Date: Thu, 11 Oct 2018 10:19:22 +0900 [thread overview]
Message-ID: <xmqqzhvli8kl.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <0102016657e7d087-be1f65a3-be3e-4b15-95f1-7570d258c70d-000000@eu-west-1.amazonses.com> (Olga Telezhnaya's message of "Tue, 9 Oct 2018 08:18:21 +0000")
Olga Telezhnaya <olyatelezhnaya@gmail.com> writes:
> Release item->value.
> Initialize item->value->s dynamically and then release its resources.
> Release some local variables.
Again, "why" is lacking.
> @@ -1373,36 +1379,31 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
> }
> } else if (atom->u.remote_ref.option == RR_TRACKSHORT) {
> if (stat_tracking_info(branch, &num_ours, &num_theirs,
> - NULL, AHEAD_BEHIND_FULL) < 0)
> + NULL, AHEAD_BEHIND_FULL) < 0) {
> + *s = xstrdup("");
> return;
It is a bit sad that we need to sprinkle xstrdup() all over the
place, but I do not offhand think of a better alternative to ensure
that it is safe to blindly free the .s field.
> - if (explicit)
> - *s = xstrdup(remote);
> - else
> - *s = "";
> + *s = explicit ? xstrdup(remote) : xstrdup("");
Next time, please avoid mixing this kind of unrelated changes with
the main theme (i.e. "the original had allocated and static pieces
of memory pointed by the same variable, which made it impossible to
blindly free it, so make sure everything is allocated"). It makes
it harder to let reviewers' eyes coast over the patch.
I say "Next time" because the change is already written this time,
and I already spent time to see it was an OK change. By the way,
*s = xstrdup(explicit ? remote : "");
is probably shorter.
> @@ -1562,10 +1566,11 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
> if (!refname)
> continue;
> }
> + free((char *)v->s); // we will definitely re-init it on the next line
No // comment, please.
> static void free_array_item(struct ref_array_item *item)
> {
> free((char *)item->symref);
> + if (item->value) {
> + free((char *)item->value->s);
> + free(item->value);
> + }
> free(item);
> }
OK.
next prev parent reply other threads:[~2018-10-11 1:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-09 8:12 [PATCH 0/3] ref-filter: reduce memory leaks Оля Тележная
2018-10-09 8:18 ` [PATCH 1/3] ref-filter: free memory from used_atom Olga Telezhnaya
2018-10-09 8:18 ` [PATCH 2/3] ls-remote: release memory instead of UNLEAK Olga Telezhnaya
2018-10-11 1:20 ` Junio C Hamano
2018-10-09 8:18 ` [PATCH 3/3] ref-filter: free item->value and item->value->s Olga Telezhnaya
2018-10-11 1:19 ` Junio C Hamano [this message]
2018-10-12 19:09 ` Jeff King
2018-10-11 1:03 ` [PATCH 1/3] ref-filter: free memory from used_atom Junio C Hamano
2018-10-12 2:35 ` Junio C Hamano
2018-10-18 6:33 ` Jeff King
2018-10-18 6:50 ` Junio C Hamano
2018-10-18 7:26 ` Оля Тележная
2018-10-18 7:28 ` [PATCH v2 " Olga Telezhnaya
2018-10-18 7:28 ` [PATCH v2 2/3] ls-remote: release memory instead of UNLEAK Olga Telezhnaya
2018-10-18 7:28 ` [PATCH v2 3/3] ref-filter: free item->value and item->value->s Olga Telezhnaya
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=xmqqzhvli8kl.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=olyatelezhnaya@gmail.com \
/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).