From patchwork Tue Oct 2 17:55:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10623959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 502163B73 for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F85D2834A for ; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34258283A5; Tue, 2 Oct 2018 17:55:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7B0F283A8 for ; Tue, 2 Oct 2018 17:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727559AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:9532 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726818AbeJCAkL (ORCPT ); Tue, 2 Oct 2018 20:40:11 -0400 Received: from lindisfarne.localdomain ([92.28.142.68]) by smtp.talktalk.net with SMTP id 7OtMgc0MNVlGZ7OtTgNKnt; Tue, 02 Oct 2018 18:55:36 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1538502936; bh=5zAfwI85mKH1DQVg46djY86Rm2IFkR5AsFrC/Re7aLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=WZSnPVkd67Z206xGm2AMHye/55wgkfY/IwRK2gQKIm9wHB4M/TGqOUK/Jln6U3tLq Pd/reo9yEzRBiFqF5tZQcJR0H6RrWEhGc4abzNoL7PxzobQJPqwgZTUVZvcFNOqAZS zKndxhZAZNbDm7ZOn1d7rm+mQpts9V7mCBhoUmE0= X-Originating-IP: [92.28.142.68] X-Spam: 0 X-OAuthority: v=2.3 cv=JcuSU3CV c=1 sm=1 tr=0 a=UGDAwvN9cmeZh0o4udnnNw==:117 a=UGDAwvN9cmeZh0o4udnnNw==:17 a=evINK-nbAAAA:8 a=EaTrdlfBmmo0FKB1FiUA:9 a=CgHqBV2zeH8inHE3:21 a=9uuab78wC2ypK9ax:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Stefan Beller Cc: Git Mailing List , Junio C Hamano , Phillip Wood Subject: [PATCH 3/5] diff --color-moved-ws: fix a memory leak Date: Tue, 2 Oct 2018 18:55:12 +0100 Message-Id: <20181002175514.31495-3-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002175514.31495-1-phillip.wood@talktalk.net> References: <20181002175514.31495-1-phillip.wood@talktalk.net> MIME-Version: 1.0 Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfFMBIxGeQbHF1R5SaElQS4Sbh0TL5VhT8X9MtReA7c4mU4pTQXiJjUK1BEk/33ZUFV9znylhkUV3QufOzLVVahoFvlqFArhOww2wT87/eC7Z7DYYtgOa KBbnyzBuxv6CvT8zaQaByqXfqkmsgf4zgQ0n7PPZ1GwqY3tN7D0q9NwdpRviuUODf7lP7PPczhVwn/YLlB7KefMnBbqEOjXZ/zvUMqAPW1SCNRYomkE5gVqM /x6FG/HdzaER83bGgQnaP5AH5TUL3GU8PMqPMPEtJYAeS96bgrioloSQrtXtSVDm Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood Don't duplicate the indentation string if we're not going to use it. This was found with asan. Signed-off-by: Phillip Wood --- 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,