From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "René Scharfe" <l.s.r@web.de>
Cc: "Junio C Hamano" <gitster@pobox.com>,
git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH 2/2] diff-no-index: release prefixed filenames
Date: Wed, 7 Sep 2022 12:03:51 +0200 (CEST) [thread overview]
Message-ID: <n575rrn9-5p4o-r40o-snsq-197p242q10p5@tzk.qr> (raw)
In-Reply-To: <df5f8305-79d5-2c12-bdf0-961428c0bdd1@web.de>
[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]
Hi René,
On Tue, 6 Sep 2022, René Scharfe wrote:
> diff --git a/diff-no-index.c b/diff-no-index.c
> index a3683d8a04..35809f26d7 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -245,6 +245,7 @@ int diff_no_index(struct rev_info *revs,
> int i, no_index;
> int ret = 1;
> const char *paths[2];
> + char *to_free[2] = { 0 };
> struct strbuf replacement = STRBUF_INIT;
> const char *prefix = revs->prefix;
> struct option no_index_options[] = {
> @@ -274,7 +275,7 @@ int diff_no_index(struct rev_info *revs,
> */
> p = file_from_standard_input;
> else if (prefix)
> - p = prefix_filename(prefix, p);
> + p = to_free[i] = prefix_filename(prefix, p);
> paths[i] = p;
> }
>
> @@ -308,6 +309,8 @@ int diff_no_index(struct rev_info *revs,
> ret = diff_result_code(&revs->diffopt, 0);
>
> out:
> + for (i = 0; i < 2; i++)
> + free(to_free[i]);
Heh. That's long-hand for
free(to_free[0]);
free(to_free[1]);
If you do want to have that loop, please replace the hard-coded 2 by
`ARRAY_SIZE(to_free)`.
Otherwise, both patches look fine to me.
Thanks!
Dscho
> strbuf_release(&replacement);
> return ret;
> }
> --
> 2.37.2
>
next prev parent reply other threads:[~2022-09-07 10:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-02 21:27 [PATCH] unleak paths allocated in "diff --no-index" Junio C Hamano
2022-09-02 23:49 ` [PATCH v2] diff --no-index: unleak paths[] elements Junio C Hamano
2022-09-03 6:00 ` René Scharfe
2022-09-05 20:26 ` Junio C Hamano
2022-09-06 12:31 ` [PATCH 1/2] diff-no-index: release strbuf on queue error René Scharfe
2022-09-07 6:01 ` René Scharfe
2022-09-06 12:31 ` [PATCH 2/2] diff-no-index: release prefixed filenames René Scharfe
2022-09-07 10:03 ` Johannes Schindelin [this message]
2022-09-07 11:19 ` René Scharfe
2022-09-07 11:36 ` [PATCH v2 1/2] diff-no-index: release strbuf on queue error René Scharfe
2022-09-07 11:37 ` [PATCH v2 2/2] diff-no-index: release prefixed filenames René Scharfe
2022-09-07 11:45 ` [PATCH v2 3/2] diff-no-index: simplify argv index calculation René Scharfe
2022-09-07 19:37 ` Junio C Hamano
2022-09-05 10:03 ` [PATCH v2] diff --no-index: unleak paths[] elements Johannes Schindelin
2022-09-05 11:01 ` Ævar Arnfjörð Bjarmason
2022-09-07 10:06 ` Johannes Schindelin
2022-09-07 12:31 ` Ævar Arnfjörð Bjarmason
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=n575rrn9-5p4o-r40o-snsq-197p242q10p5@tzk.qr \
--to=johannes.schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/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).