From patchwork Thu Sep 16 08:55:22 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: 12498339 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 270CFC433F5 for ; Thu, 16 Sep 2021 08:55:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0731161164 for ; Thu, 16 Sep 2021 08:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235324AbhIPI5C (ORCPT ); Thu, 16 Sep 2021 04:57:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233839AbhIPI5A (ORCPT ); Thu, 16 Sep 2021 04:57:00 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD30C061574 for ; Thu, 16 Sep 2021 01:55:39 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id t190so6568579qke.7 for ; Thu, 16 Sep 2021 01:55:39 -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=P8qFk+5eGsb5mDAcpZ4ce4gr8ywWeMkfcrfikA4I4bU=; b=Y1W3lErkMZf4kNRjWHAXbOhmKd1HpGudfy8WLg25ygpbNbZLfU0FYYAkSQIsp4jbJb i0SwNk2lf6hPPB8dY7qXqeAJEgybPdZOyzx9quJmVdmXpi8eUfpG8Y8dWOzxmJgD9QAz 7HdIp2jDQKmvH27AFHRkhcZqzCfE2WSCiFypoc5I+vcAPtnKp1nNOkn0AmLWuZEmxjdB lox6o+f5hS44ggZzNFLWY1VW/2cPl8FH2PVvQ3g/Z9fZKM4yKasAcpJv99RapoJpGr+X wl3XJNgDakkUmfDrKCHE8BDh2UoNSh6/p4pBDtJ+R8sKssOi0Us3+36sWpk8DeGPmncI HErA== 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=P8qFk+5eGsb5mDAcpZ4ce4gr8ywWeMkfcrfikA4I4bU=; b=K4f5KWlkS7ej4dbcyTKNuIB5u2HP9/M0LAaphsRknMuNEOF17paS2mImg0SAdh6x6q AdrcGcBGkveiNFl6iSdLchavaP0GIMPT+t9DwW+Zh8bpaWu4g3pON6hYmEwl8qdBkbME O+d2MaGJ5kxJ6uO0DI+HVfgAK+ZRJjMFveeFNLQI14YdK8YZtz4NqQolWcu6HnuZnFW0 LCo2Q+cpNpA2MowPb8r0PN1axkbDm6mxVNrWYc26xDRlJTk08SZGs+JLlPdjTvpdNCMK FNXzYUdZNTBe63uNVSJ1RkaYWkt4XBmyQsLMbimfYYTsriHelRVYPn/bRMfovn92K4RJ dH7w== X-Gm-Message-State: AOAM531lb62C2qSLZc4iBgMLXMEK+HTzARvZGrCBBit4tbWpVSC6O+dJ wLCaVXFRsjL3YJE+5KbQxIOFMFwq6zI= X-Google-Smtp-Source: ABdhPJybbXLvaMFV4WSw33pnJBSBTdRF6E5aV8CVUxk7s/+a66gaJrVXCWvZbvDDyU+yFmd59sKhJw== X-Received: by 2002:ae9:c011:: with SMTP id u17mr4021988qkk.365.1631782538856; Thu, 16 Sep 2021 01:55:38 -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 e22sm1663868qtm.10.2021.09.16.01.55.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Sep 2021 01:55:38 -0700 (PDT) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: me@ttaylorr.com, gitster@pobox.com, =?utf-8?q?Carlo_Marcelo_Arenas_Bel?= =?utf-8?q?=C3=B3n?= Subject: [PATCH v2 1/2] tree-diff: fix leak when not HAVE_ALLOCA_H Date: Thu, 16 Sep 2021 01:55:22 -0700 Message-Id: <20210916085523.68581-2-carenas@gmail.com> X-Mailer: git-send-email 2.33.0.481.g26d3bed244 In-Reply-To: <20210916085523.68581-1-carenas@gmail.com> References: <20210916023706.55760-1-carenas@gmail.com> <20210916085523.68581-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_H (ex: macOS and other BSD). Add the missing free call, xalloca_free(), which is a noop if we allocated memory in the stack frame, but a real free() if we allocated in the heap instead, and while at it, change the expression to match in both macros for ease of readability. This avoids a leak reported by LSAN while running t0000 but that wouldn't fail the test (which is fixed in the next patch): SUMMARY: LeakSanitizer: 1034 byte(s) leaked in 15 allocation(s). Signed-off-by: Carlo Marcelo Arenas Belón --- v2: includes an improved commit message, thanks to Taylor 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 08:55:23 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: 12498341 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 EC2ABC433FE for ; Thu, 16 Sep 2021 08:55:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5FA56120D for ; Thu, 16 Sep 2021 08:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235334AbhIPI5D (ORCPT ); Thu, 16 Sep 2021 04:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235298AbhIPI5B (ORCPT ); Thu, 16 Sep 2021 04:57:01 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC98BC061574 for ; Thu, 16 Sep 2021 01:55:40 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id t190so6568611qke.7 for ; Thu, 16 Sep 2021 01:55:40 -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=dyqCeu1PwLlkm0Rowq8Q0dtkwo/thkQcID4VsnWH0xk=; b=hj2Lx4jWUOmp23LDpkj/sqQPH7SnJ8Xvb2b2Ib4PGDycgGbnLw7aYtpeTYe8qfxG7z rpzI3iLvJOQhogJCovae8Yqj3+5XmSpmcUL/HCqHJkw28BLPve6Z2G78uhNx8qSUC3SU GOYZ66rvSIok0znkK1fWwFON6y26nr/XFXqjGnf4Ij5Rs4i38pUn50bALGHWDJgTlYvo TW/m/ehYZTS1i7VFrPupxknbfCVWewD45mgL59554nzaDttIhJjZ4th0Cu2YEXIl99og lhpmggFiMZI/mH2gwpwPeZEvf0yYkzkLFUuUfa9hgWIX87zCjxVjfCYFsGzI6MbkCq/f dCrw== 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=dyqCeu1PwLlkm0Rowq8Q0dtkwo/thkQcID4VsnWH0xk=; b=N/mVWvHwMlYbaoeZTpOn1bJcfy2W/Y5Wu9lJvBJsQOCsh09JDdvdn2J3NcaFdlW/9c 44FHEnNYFdealcgEPm7yKQeH+FvTyw3RzVjLzVBcKJS2HlQxuZSPaQ+vWlTDHxULxHkK q3H98m0fdlWj+HbgU9gQpXfxcb/VMdhIJo9ZlGS8zEGwRptRv2M2AfRwUbq3Of3LcFyX rm7fBCpD+yCKPsbkJv5F8j4V0A6Kahz8Y8lEy+vJqlhB4rrS68oG5DF1NFRaijxEC0ll MJhEM23+TOucO9RJlIsi0Z+kYBVQsbR2DJTnJdPUsdIXhKt4F9sSJyvGREECBMBIJpe2 aJ2A== X-Gm-Message-State: AOAM532XIwd9ucdfEy+C+upZj4msAKxf8PSmJAKUgbC3ZrB1qX+7qoA9 +JtfrM8zRgdzrXidkizquznDKsTSj7w= X-Google-Smtp-Source: ABdhPJxOUKQ249mRLrLA3Sos74CkmWcWRdYELwLga7qkm2Ax+ZTqzBCiU+Ldo88FPrW/HfINw1PU0g== X-Received: by 2002:a05:620a:bc5:: with SMTP id s5mr3961717qki.47.1631782539938; Thu, 16 Sep 2021 01:55:39 -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 e22sm1663868qtm.10.2021.09.16.01.55.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Sep 2021 01:55:39 -0700 (PDT) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: me@ttaylorr.com, gitster@pobox.com, =?utf-8?q?Carlo_Marcelo_Arenas_Bel?= =?utf-8?q?=C3=B3n?= Subject: [PATCH v2 2/2] t0000: avoid masking git exit value through pipes Date: Thu, 16 Sep 2021 01:55:23 -0700 Message-Id: <20210916085523.68581-3-carenas@gmail.com> X-Mailer: git-send-email 2.33.0.481.g26d3bed244 In-Reply-To: <20210916085523.68581-1-carenas@gmail.com> References: <20210916023706.55760-1-carenas@gmail.com> <20210916085523.68581-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 tests for commit-tree that mask the return exit from git as described in a378fee5b07 (Documentation: add shell guidelines, 2018-10-05). Fix the tests, to avoid pipes by using a temporary file instead. Signed-off-by: Carlo Marcelo Arenas Belón --- v2: * avoid changing some of the code as suggested by Taylor * no need for pipes or stdin redirection as suggested by Junio t/t0000-basic.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)y diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index cb87768513..5c342de713 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -1271,28 +1271,29 @@ 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") && + git show --pretty=raw $commit0 >out && + tree=$(sed -n -e "s/^tree //p" -e "/^author /q" out) && 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") && + git show --pretty=raw $commit1 >out && + parent=$(sed -n -e "s/^parent //p" -e "/^author /q" out) && 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 | - sed -n -e "s/^parent //p" -e "/^author /q" | - sort -u) && + git show --pretty=raw $commit2 >out && + cat >match.sed <<-\EOF && + s/^parent //p + /^author /q + EOF + parent=$(sed -n -f match.sed out | sort -u) && test "z$commit0" = "z$parent" && - numparent=$(git show --pretty=raw $commit2 | - sed -n -e "s/^parent //p" -e "/^author /q" | - wc -l) && - test $numparent = 1 + git show --pretty=raw $commit2 >out && + test_stdout_line_count = 1 sed -n -f match.sed out ' test_expect_success 'update-index D/F conflict' '