From patchwork Tue Sep 6 12:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12967416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C92DECAAA1 for ; Tue, 6 Sep 2022 12:32:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237896AbiIFMcj (ORCPT ); Tue, 6 Sep 2022 08:32:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239157AbiIFMcF (ORCPT ); Tue, 6 Sep 2022 08:32:05 -0400 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9288B1034 for ; Tue, 6 Sep 2022 05:31:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662467489; bh=kM20vDkHXj0A8A20XH6Fh9R/T97HPaB4jGXyd2XIUoc=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=CtelHR45IXIMET08xJ1Doka3SIP9U0naCDiwg/F6d//ZUmMCyIWmCJ6TmDPOM8sBP saxHL+EoQwAn8CMYganXQYtx2tVMDw7J/aGFf/HPCnKVppdq9vDVCuAUNRZumV9pzo r4AaU9X0+v9FCIUsHhveL6XQKouXIauQK8a4Ma1g= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([91.47.144.123]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MJFdB-1ooZvW0ZVz-00KrcA; Tue, 06 Sep 2022 14:31:29 +0200 Message-ID: Date: Tue, 6 Sep 2022 14:31:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 1/2] diff-no-index: release strbuf on queue error To: Junio C Hamano Cc: git@vger.kernel.org, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Johannes Schindelin References: <181c029b-8b36-4b04-30f9-97a3f252bfbc@web.de> Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:HeIGmh+jrnuZqCkpQYdnQ4C1qxARqWbFAwNcG3NrBoYEVEgKZGf C0apDwt1iqWfTbo429UVIBIfjGAp/HMbOMpmGG80f9reDYN1hiKKKQAKYHBjWIT8LQXl4Ba TeVwK1sByYZU+gv3hVzgEM8TKAtAEYw7ZnpZeSa5JLHYG1DjOXt6D6W2RTR00ZkICnioRhU mxfW8le2J4L0qFr8mIiow== X-UI-Out-Filterresults: notjunk:1;V03:K0:5XNbyRz1Ar4=:qXGQaAz/6J/ZsMp7k13pOh 3zZ6hLGQmYoJBrfqAHpPbcY668vZkZcPkjhzRYa+7gmMcutelxG7liHj0IBiZnlTSepSw6LBC Hv/MEgJX63YirsHVW+ZM0CP0CunSUqNc+mKALk9TlJT/4fl+Z+FWYIjuw5vuEalAuOcim6JtN Sh+Vyy44JDQOcizNJA9pNhI7z1ze7xFC7kNhIpHbIoJgrlkU2V9mfxK1D8jck1LUOosKjsgc0 yI+1qLNHrZ6vVn01o62jfI37NxeVHkdoclaf+LL86RB98jITZdZJIEgXQC3RZa6eCBPUPPwFq HFOIQuCW73V7b+Cy9n2qEwRddkRGP0b7z53ofBkUK836f7j5xeVK6Jn+vuJk+KRjNyAk8zoyX jP2xnJDHIiHLzX6woRFJVAadAKX1Wv5MBp+LF+FM6fOT8j6sL0LEnnTEU+ke+vKLp4qdNYbtw LJwoJP1iPW5hf3RYXtVxY19aAwlYi6A5dMvud0jBrkb2tZOT9312V4H5i8Kp+ytXxUddeLa5l 9vbioHOSUY5bD19krNulZv6moH3JLjFZpx8ZajoI6SaEpy/cBwxkgwAV8vsEI1x9T4LH7kgpX e3M3DtxuGeN5jm/P/sIHHpu7g6IlZYYyRvTbkH/5xqqZ0gRh+j+p2YJBS5ex1SbTRH78lXyj7 3Jxm8aDVu/hX1PdH8cFsXfZfdTZpAtnI8p9nZ+FZduKhPqYu1udsI4R3LdViZUWwjrJD/yie+ cF9FLTRwZOpIY0dPh4fsLvoMb7Baop8+39mcjPZQ+a7DlbESmGy/S3ZJxTKHscoDKMUqLg3yi /XwrDdcHg7B241uxz5ZUBsl09N95CuMCBMBeAAGVl97L4C5qWmh86n9pCa7Pu91NlHIeMMGE3 +hr3GTXQxC0Shw9xdNoivc2SAh51KDaXXQq/V/NdFRn8TzoFasI8uk+1VvSqlG8o6PVmBXJrA o2eaWyMMo1VOUtw+4lvBRZ/wUsKjhU7c5vsHRo3wvQlOTeg99Qvpi37/FFzgfzG3RKKBOSNd7 HPJRf07Y+JC7laorEvSZGg7o9m+ccp3yVvC+qs6dSf+dpTl3flaqtwvjWLk6kbsk5zs4Q/Ak6 WTG4phV0PjkdmAT1kBaUPbI2fRAIW7qiLEWD5iCZ9JwstnSRA65qcheA4HN6PbxMCiwGK37tp MMftg= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The strbuf is small and we are about to exit, so we could leave its cleanup to the OS. If we release it explicitly at all, however, then we should do it on early exit as well. Move it to a new cleanup section at the end and make sure all execution paths go through it. Signed-off-by: René Scharfe --- diff-no-index.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- 2.37.2 diff --git a/diff-no-index.c b/diff-no-index.c index 9a8b09346b..a3683d8a04 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -243,6 +243,7 @@ int diff_no_index(struct rev_info *revs, int argc, const char **argv) { int i, no_index; + int ret = 1; const char *paths[2]; struct strbuf replacement = STRBUF_INIT; const char *prefix = revs->prefix; @@ -295,16 +296,18 @@ int diff_no_index(struct rev_info *revs, revs->diffopt.flags.exit_with_status = 1; if (queue_diff(&revs->diffopt, paths[0], paths[1])) - return 1; + goto out; diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/"); diffcore_std(&revs->diffopt); diff_flush(&revs->diffopt); - strbuf_release(&replacement); - /* * The return code for --no-index imitates diff(1): * 0 = no changes, 1 = changes, else error */ - return diff_result_code(&revs->diffopt, 0); + ret = diff_result_code(&revs->diffopt, 0); + +out: + strbuf_release(&replacement); + return ret; } From patchwork Tue Sep 6 12:31:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12967417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81E2EECAAA1 for ; Tue, 6 Sep 2022 12:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239818AbiIFMcn (ORCPT ); Tue, 6 Sep 2022 08:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239511AbiIFMcG (ORCPT ); Tue, 6 Sep 2022 08:32:06 -0400 Received: from mout.web.de (mout.web.de [212.227.17.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED3451FB for ; Tue, 6 Sep 2022 05:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662467493; bh=BQRAUcy25RphMFO07Vg4abgTq5JiRW/WzWKtmOuffvs=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=cQJWhSVRJdgS1eTjybUdq9bk/pChe2AAbNxGQRFjYBobKXJZKwS4t3gi7u3xKNdlD +9ywwCi8CTF4CnAJODAHcLgSIikoRfAlJssVnF+qaFAGLGEUV/5R7xZy4UAx7F2AVn ej08hjY7upGmQ+LSsvbXtyzLK0Y849S2TKkfdN7Q= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([91.47.144.123]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Mv3Yg-1pMXtk3WDo-00qucy; Tue, 06 Sep 2022 14:31:32 +0200 Message-ID: Date: Tue, 6 Sep 2022 14:31:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 2/2] diff-no-index: release prefixed filenames Content-Language: en-US To: Junio C Hamano Cc: git@vger.kernel.org, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Johannes Schindelin References: <181c029b-8b36-4b04-30f9-97a3f252bfbc@web.de> From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:PzDmdmkeTB4fsQHZJG5r+TN09IEOhsKSajp43e4IUS0U3uMgv/2 HQwyEom1uGnSAu6ir3skaWuN41pRFPYKugR7vJJx/mG4ZDXRgt/7DozVP3IiaCjK6HdVGpq CeoFhSIEpSmrewGgljcch4RWDel80+/bdeSGjoD4YMj3pGaWgFySV0JdbuZ/mgT1k35tdlx PHJLelkRc2AfKA6sTzaVw== X-UI-Out-Filterresults: notjunk:1;V03:K0:yI9jWqpmB88=:hjmhfJEDzMSf0n1X3ZJ15I 1ecDTVrBmwErTxEcYDYezPHVUJ5Q/5Cdkxgt4Slf/bI6I1BFcZFV1wSUAbMCBNm5yzP1BPm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hfmQQocqfcGh9f5Y2RlKQHrU1hCINNYl6OZBXo1 si220= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Callers of prefix_filename() are responsible for freeing its result. Remember them and release them to appease leak checkers. Signed-off-by: René Scharfe --- diff-no-index.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.37.2 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]); strbuf_release(&replacement); return ret; } From patchwork Wed Sep 7 11:45:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12968924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57EDDC6FA83 for ; Wed, 7 Sep 2022 11:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbiIGLpy (ORCPT ); Wed, 7 Sep 2022 07:45:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbiIGLpw (ORCPT ); Wed, 7 Sep 2022 07:45:52 -0400 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D622E6E2E7 for ; Wed, 7 Sep 2022 04:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662551143; bh=7XzwFojnr5T8h7EPPJemK8wTgtw7mPlcb1gZr+LhE64=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=eDPmCQ5g8xFy494ocp42Ika6gYbPqCo55NIs7/DQX3+dFExbGRaQBDqS+N6OCyKwK aOIhTu3OFZpkGpkDCaXhr5dF6FU0abz3TPynClbHrF9K6eilk3izk7PVLy4xGEkT2h beP86aBpBsEZ8o7ISZ1cRcCnost+j7pzghowLwFk= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([91.47.158.123]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Mkmzl-1pDWNE1bTT-00lrGX; Wed, 07 Sep 2022 13:45:43 +0200 Message-ID: <9ea33608-3a6c-c0ef-9bb3-4bb535009aeb@web.de> Date: Wed, 7 Sep 2022 13:45:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH v2 3/2] diff-no-index: simplify argv index calculation Content-Language: en-US To: Junio C Hamano Cc: git@vger.kernel.org, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Johannes Schindelin References: <181c029b-8b36-4b04-30f9-97a3f252bfbc@web.de> From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:N+tjUduiY5v+Np9a+jIbG0YIyAE/smGv9iCXyNja/O25h2Tsmxg BvPFWBB4yG9amcoiSByDPNyR5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JI+obegA 72hmpAoCqRG5HJV5h938v/4HmuTR3JBM0L+WmfLfA3XoZtMnDWfBLPEZO26h2sW1LXIlxeUED meX3eSQC5zCFvPDW/t7nxIZz34JREppTnG+x8MdwOFwlvVMZGn+DVXieCNN/tKa2q8/ObqnXY RvPhJ0XDfgGrzyG3gul/J5QIpXelGt8pXTp7/DAT+177JuMavQNpYGn9ypW3dIkqFqe2zo5B3 h1X0OAKv6MNbCdLKHUA/wTlyoxwVrzvlTnMr8iLMBBe3pAm3G9zkPI8smSTX/iwgpHBBmvWKX nWxS8= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since 16bb3d714d (diff --no-index: use parse_options() instead of diff_opt_parse(), 2019-03-24) argc must be 2 if we reach the loop, i.e. argc - 2 == 0. Remove that inconsequential term. Signed-off-by: René Scharfe --- Bonus patch "while at it", would have saved me from going "huh?". Generated using -U8 for easier review. diff-no-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.37.2 diff --git a/diff-no-index.c b/diff-no-index.c index a18f6c3c63..18edbdf4b5 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -262,17 +262,17 @@ int diff_no_index(struct rev_info *revs, if (argc != 2) { if (implicit_no_index) warning(_("Not a git repository. Use --no-index to " "compare two paths outside a working tree")); usage_with_options(diff_no_index_usage, options); } FREE_AND_NULL(options); for (i = 0; i < 2; i++) { - const char *p = argv[argc - 2 + i]; + const char *p = argv[i]; if (!strcmp(p, "-")) /* * stdin should be spelled as "-"; if you have * path that is "-", spell it as "./-". */ p = file_from_standard_input; else if (prefix) p = to_free[i] = prefix_filename(prefix, p);