git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood@talktalk.net>
To: Stefan Beller <sbeller@google.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH 3/5] diff --color-moved-ws: fix a memory leak
Date: Tue,  2 Oct 2018 18:55:12 +0100	[thread overview]
Message-ID: <20181002175514.31495-3-phillip.wood@talktalk.net> (raw)
In-Reply-To: <20181002175514.31495-1-phillip.wood@talktalk.net>

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Don't duplicate the indentation string if we're not going to use it.
This was found with asan.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 diff.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/diff.c b/diff.c
index 0096bdc339..efadd05c90 100644
--- a/diff.c
+++ b/diff.c
@@ -785,11 +785,15 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a,
 	const struct emitted_diff_symbol *longer =  a->len > b->len ? a : b;
 	const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a;
 	int d = longer->len - shorter->len;
+	int ret = !strncmp(longer->line + d, shorter->line, shorter->len);
+
+	if (!ret)
+		return ret;
 
 	out->string = xmemdupz(longer->line, d);
 	out->current_longer = (a == longer);
 
-	return !strncmp(longer->line + d, shorter->line, shorter->len);
+	return ret;
 }
 
 static int cmp_in_block_with_wsd(const struct diff_options *o,
-- 
2.19.0


  parent reply	other threads:[~2018-10-02 17:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02 17:55 [PATCH 1/5] diff --color-moved-ws: fix double free crash Phillip Wood
2018-10-02 17:55 ` [PATCH 2/5] diff --color-moved-ws: fix out of bounds string access Phillip Wood
2018-10-02 18:58   ` Stefan Beller
2018-10-03  9:40     ` Phillip Wood
2018-10-02 17:55 ` Phillip Wood [this message]
2018-10-02 19:08   ` [PATCH 3/5] diff --color-moved-ws: fix a memory leak Stefan Beller
2018-10-03  9:42     ` Phillip Wood
2018-10-03  9:54   ` Martin Ågren
2018-10-02 17:55 ` [PATCH 4/5] diff --color-moved-ws: fix another " Phillip Wood
2018-10-02 19:08   ` Stefan Beller
2018-10-02 17:55 ` [PATCH 5/5] diff --color-moved: fix a " Phillip Wood
2018-10-02 19:11   ` Stefan Beller
2018-10-02 18:49 ` [PATCH 1/5] diff --color-moved-ws: fix double free crash Stefan Beller
2018-10-03  9:38   ` Phillip Wood
2018-10-04 10:07 ` [PATCH v2 0/5] " Phillip Wood
2018-10-04 10:07   ` [PATCH v2 1/5] " Phillip Wood
2018-10-04 10:07   ` [PATCH v2 2/5] diff --color-moved-ws: fix out of bounds string access Phillip Wood
2018-10-04 10:07   ` [PATCH v2 3/5] diff --color-moved-ws: fix a memory leak Phillip Wood
2018-10-04 10:07   ` [PATCH v2 4/5] diff --color-moved-ws: fix another " Phillip Wood
2018-10-04 10:07   ` [PATCH v2 5/5] diff --color-moved: fix a " Phillip Wood
2018-10-04 19:42     ` Stefan Beller

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181002175514.31495-3-phillip.wood@talktalk.net \
    --to=phillip.wood@talktalk.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=sbeller@google.com \
    --subject='Re: [PATCH 3/5] diff --color-moved-ws: fix a memory leak' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox