From patchwork Thu Sep 16 02:37:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 12498025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9017C433EF for ; Thu, 16 Sep 2021 02:37:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7A856103E for ; Thu, 16 Sep 2021 02:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233933AbhIPCjJ (ORCPT ); Wed, 15 Sep 2021 22:39:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbhIPCjI (ORCPT ); Wed, 15 Sep 2021 22:39:08 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E55C061574 for ; Wed, 15 Sep 2021 19:37:49 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id g11so4327250qtk.5 for ; Wed, 15 Sep 2021 19:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9ua8jrO+dITR1I0mn8T/k3xhRd5xui+AA9CNpsIZaoQ=; b=oxEaQlFZuDTmKpoVzYXWD5FWLB3oE86oSpwkbe0GukJQ4pWbYgGvBjjGCn3ZzI9y4A Mj7b34j+A1l9Xn2156aKA5sxjz1buAZxUHpSEwRcRfRLdNWmMKBDV6PISr/ifdLm7QIA OWr6xLdnSxudZbgDxQ1oJw5paC7dFmR+G42LNoVix+e86o+xM+cwmeN3KplbOk4elrVn q1sFshu5RKh/7x/bWGT5Rd5k/cDHgcPRXUlGwdr3+htR0taEtcLYbx1w13erJUQWOQTE 89srRch/VSLSp2PGQx866vF8qFNCEfnhxmRKgbnb3BEZ2uMdfWHI/jSGlPiyGp0H9qqS vK1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9ua8jrO+dITR1I0mn8T/k3xhRd5xui+AA9CNpsIZaoQ=; b=f9Z2VHe2HheZgM25OqHE9MgTtsssQiNdTidlsoaKjrqnKypI+vKoWvvsLaH5Ov0DZS +VOjE6fHZj7Q/6Gj28YqEql9LG8WU/ZvyCEJ/pxyxIz0aI+A3jH3ZIQuROCAl75+CSwS 81GfdNkmrKYGUmdqxznR/Rzl2GhMrgUxQXAQFaLU7KxZpWNlQ90GDsw1dPo9vM4l9uHj 9hYDTjM75bnVo2wXZCjs+V85+THdS1M00b2DIFoyrEKk0me5afDrFujUBMJdPy/KBtAe KQ2Nn97JfcrOjry36chChDvCZsPTWUwBtWWfaxADVI+Icz1rIzuja4ZPpztICF2CF2PR eRug== X-Gm-Message-State: AOAM531UBmwx6KbPnaHEV74FU6rNbIiLzn+PSt4qZzE32R9pFruq0/fz Va5NLACGrRSUG37/5vay+Q3m9WzVT6s= X-Google-Smtp-Source: ABdhPJynhNeut5hWt4yQbmOwtulNVmFBFwjUL8z0rvNxKNb8hb2RNKRYVp3alJ1Y64IxVo4V0ZMFVA== X-Received: by 2002:aed:204b:: with SMTP id 69mr3061775qta.24.1631759868113; Wed, 15 Sep 2021 19:37:48 -0700 (PDT) Received: from carlos-mbp.lan (104-1-92-200.lightspeed.sntcca.sbcglobal.net. [104.1.92.200]) by smtp.gmail.com with ESMTPSA id w20sm1498753qkj.116.2021.09.15.19.37.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Sep 2021 19:37:47 -0700 (PDT) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, =?utf-8?q?Carlo_Marcelo_Arenas_Bel?= =?utf-8?q?=C3=B3n?= Subject: [PATCH 1/2] tree-diff: fix leak when not HAVE_ALLOCA Date: Wed, 15 Sep 2021 19:37:05 -0700 Message-Id: <20210916023706.55760-2-carenas@gmail.com> X-Mailer: git-send-email 2.33.0.481.g26d3bed244 In-Reply-To: <20210916023706.55760-1-carenas@gmail.com> References: <20210916023706.55760-1-carenas@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org b8ba412bf7 (tree-diff: avoid alloca for large allocations, 2016-06-07) adds a way to route some bigger allocations out of the stack and free them through the addition of two conveniently named macros, but leaves the calls to free the xalloca part, which could be also in the heap, if the system doesn't HAVE_ALLOCA (ex: macOS). Add the missing free call, and while at it, change the expression to match in both macros for easy of readability. This avoids a leak reported by LSAN as while running t0000 but that wouldn't fail the test (which will be fixed next) : SUMMARY: LeakSanitizer: 1034 byte(s) leaked in 15 allocation(s). Signed-off-by: Carlo Marcelo Arenas Belón --- tree-diff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tree-diff.c b/tree-diff.c index 1572615bd9..437c98a70e 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -21,7 +21,9 @@ ALLOC_ARRAY((x), nr); \ } while(0) #define FAST_ARRAY_FREE(x, nr) do { \ - if ((nr) > 2) \ + if ((nr) <= 2) \ + xalloca_free((x)); \ + else \ free((x)); \ } while(0) From patchwork Thu Sep 16 02:37:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 12498027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B14FC433F5 for ; Thu, 16 Sep 2021 02:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 702FF6103E for ; Thu, 16 Sep 2021 02:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233902AbhIPCjL (ORCPT ); Wed, 15 Sep 2021 22:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233964AbhIPCjK (ORCPT ); Wed, 15 Sep 2021 22:39:10 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1860BC061574 for ; Wed, 15 Sep 2021 19:37:50 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id b14so4382418qtb.0 for ; Wed, 15 Sep 2021 19:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6X1vyjN/6Fi9vlMm0MHrXECtd1qMD5xC0rBYa6v+mRw=; b=RbJx8DJwxfh2wn2kr1c8wZt7oVJPMZyDVplK9MtJ6Evp5yQwxWRXaPWLJOhEr7rgqm ZFTpL4EsRdi/LolnCWL073P8Wg5T2RPRWf3ni8juc3b5yuLOQVxZMF/PQtIrmdlW7wKd x9BgRurHE1T9x3/+tNp7XkS+noV/9i5VJEnUnYnOVtW0gSsw5xBUrx09Qcub33Z6aB9r 2w7qKMbACr9dMJnJ2gUOIHzR3AYAt1yyRveSvigjMiiM7kQGbP5qaFfyUftiASAUfVHb 8Q3mR9lm7c7eUDwf3a866YaA5fYWvZe3Ov01Eq0hb96Rx8Ev34kXG8NcsciuNWNBlMNW owUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6X1vyjN/6Fi9vlMm0MHrXECtd1qMD5xC0rBYa6v+mRw=; b=zH5Xs0hIV9rha3P+ZX+ugezf3QVa4FOpa81QyXBo8ZKnykqYvQPKlJWRMY0t/td/EA r4ZSrRFA+HihR4Np6fGAT80OFaCk9X041f4H515CupfsIqY4hK3BMSBTC2VZfhmL+RWa GCAf1IkFgnZambkiSCByAOfih0XWPR3FG8Od1NKdjPG/0szYlsuFNUUOeNxz711iYaGd lAiFdzu0gSHDw/0vuWh7flyICDfJD0qZ/wTASu1YDAjSaqIld1BZVSWftCFbdhtR3meP G/bSB/n2rzi68Ankwle5qkKtMno4PxzHHqiE8UcQHrSH3ezNpoalkUK1zKJukrIFW9/7 GFBA== X-Gm-Message-State: AOAM531UPqqeeNq2Txem1rJW1QPmcT7sD9fMLHPugGhdF1wqcjaRUMVW n0YnPZ3U9t3V95x1I2XN0onNkxmF4ZI= X-Google-Smtp-Source: ABdhPJx0fcuF/2nPq33G5be95Mw6/GckqIuqcathU7vdwCooVzVRZKb8NoDIyiWJYl1399SMrpsL5w== X-Received: by 2002:a05:622a:c3:: with SMTP id p3mr2965344qtw.7.1631759869100; Wed, 15 Sep 2021 19:37:49 -0700 (PDT) Received: from carlos-mbp.lan (104-1-92-200.lightspeed.sntcca.sbcglobal.net. [104.1.92.200]) by smtp.gmail.com with ESMTPSA id w20sm1498753qkj.116.2021.09.15.19.37.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Sep 2021 19:37:48 -0700 (PDT) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, =?utf-8?q?Carlo_Marcelo_Arenas_Bel?= =?utf-8?q?=C3=B3n?= Subject: [PATCH 2/2] t0000: avoid masking git exit value through pipes Date: Wed, 15 Sep 2021 19:37:06 -0700 Message-Id: <20210916023706.55760-3-carenas@gmail.com> X-Mailer: git-send-email 2.33.0.481.g26d3bed244 In-Reply-To: <20210916023706.55760-1-carenas@gmail.com> References: <20210916023706.55760-1-carenas@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 9af0b8dbe2 (t0000-basic: more commit-tree tests., 2006-04-26) adds tets for commit-tree that mask the return exit from git as described in a378fee5b07. Fix the tests, to avoid pipes by using instead a temporary file. Signed-off-by: Carlo Marcelo Arenas Belón --- t/t0000-basic.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index cb87768513..545ff5af13 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -1270,26 +1270,31 @@ test_expect_success 'no diff after checkout and git update-index --refresh' ' P=$(test_oid root) test_expect_success 'git commit-tree records the correct tree in a commit' ' - commit0=$(echo NO | git commit-tree $P) && - tree=$(git show --pretty=raw $commit0 | - sed -n -e "s/^tree //p" -e "/^author /q") && + echo NO | git commit-tree $P >out && + commit0=$(cat out) && + git show --pretty=raw $commit0 >out && + tree=$(cat out | sed -n -e "s/^tree //p" -e "/^author /q") && test "z$tree" = "z$P" ' test_expect_success 'git commit-tree records the correct parent in a commit' ' - commit1=$(echo NO | git commit-tree $P -p $commit0) && - parent=$(git show --pretty=raw $commit1 | - sed -n -e "s/^parent //p" -e "/^author /q") && + echo NO | git commit-tree $P -p $commit0 >out && + commit1=$(cat out) && + git show --pretty=raw $commit1 >out && + parent=$(cat out | sed -n -e "s/^parent //p" -e "/^author /q") && test "z$commit0" = "z$parent" ' test_expect_success 'git commit-tree omits duplicated parent in a commit' ' - commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && - parent=$(git show --pretty=raw $commit2 | + echo NO | git commit-tree $P -p $commit0 -p $commit0 >out && + commit2=$(cat out) && + git show --pretty=raw $commit2 >out && + parent=$(cat out | sed -n -e "s/^parent //p" -e "/^author /q" | sort -u) && test "z$commit0" = "z$parent" && - numparent=$(git show --pretty=raw $commit2 | + git show --pretty=raw $commit2 >out && + numparent=$(cat out | sed -n -e "s/^parent //p" -e "/^author /q" | wc -l) && test $numparent = 1