From patchwork Wed Dec 28 18:00:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083092 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 B1D36C3DA7A for ; Wed, 28 Dec 2022 18:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233526AbiL1SAb (ORCPT ); Wed, 28 Dec 2022 13:00:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233286AbiL1SA3 (ORCPT ); Wed, 28 Dec 2022 13:00:29 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E83167C0 for ; Wed, 28 Dec 2022 10:00:28 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so11761135wms.2 for ; Wed, 28 Dec 2022 10:00:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sdlEcxOUw1jyf5oaBIycdEUx/2wXFAHa8mBn0HR/ovk=; b=pSeA3ubh5Hq+4UU/bydqGaoEMvHvuSb/hk0Y0CeMKlDJZLbcT2O9MrBR6ETXWmCWHm zIFad5qPHYvE1of29gjl1izAFPX9tH7oZMdNdXZRYOtra01ChQcyczkuY88sFdklITc+ fB3sYBPvFRPaQyciRIj7wwh7bph11gX8aRn0lwYSqYaKUGWQtByT6UE1OoGGZ8u2EJec Nk7Rmd8gRBAfx9dW8gc1vlLjfgFrdDPvWkWAQhGqwrhfa3Dy/ClhN8K0hyXfkkOLKl49 RQHCKTA6YvpGwJFpOfc1yy3FZn4Egd1MuHXaeHUWencJAvWgF8veh0JSvMn4EUHLxFsF z1PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sdlEcxOUw1jyf5oaBIycdEUx/2wXFAHa8mBn0HR/ovk=; b=gUec8eZD9qXJGkudR4QHMfxSAZ/60RiQ4nKaLAtRqyHwBNRzqWy8Vt4jV7ywLnkopx TtFD/CqRBZ0zL479fSSukBNON3+pwhAtiuWYKN2nXzgSLw+C8dfg1rGqN1ueqJE8jYkw MCVSipFK8dMJbmGqPYbJTtB1snLBLXhKCJAl4VUhov8cob6MkmA3UlirrTyaI7vuLm99 n122p6WW1AQ7co9K9DGQTjrkVYYSAfl2UZcfe2jEymXZG/qUXdPc4bnOL4cf2POaLxWg Au6OKCnktxQ6YFOGbbGxvm8LJRRVNkW6NMIyHzSI9Xqanw5MAVVSIIMoe5A+udH24Mky 8o7A== X-Gm-Message-State: AFqh2kqz8aQeRCReZQTlZF4BfttZj8TpzN1CMKJaaHJ3ystzVfPI1pyV uitYE/yQ1I0vX5nDIvjVsm4B9YsqQeBakQ== X-Google-Smtp-Source: AMrXdXsZpxQgkUozviFtrrUOyDGKG9fn1WRHSCfuCxO1UJccI9M6lYhpYwwj+gqAKGMHUEIQ9NwvgA== X-Received: by 2002:a05:600c:4e48:b0:3cf:69f4:bfd4 with SMTP id e8-20020a05600c4e4800b003cf69f4bfd4mr18799616wmq.7.1672250426991; Wed, 28 Dec 2022 10:00:26 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:26 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 01/20] t6021: mark as passing with SANITIZE=leak Date: Wed, 28 Dec 2022 19:00:01 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This test was recently added in 8c1bc2a71a7 (revision: add new parameter to exclude hidden refs, 2022-11-17), but wasn't marked as passing with "SANITIZE=leak". Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t6021-rev-list-exclude-hidden.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t6021-rev-list-exclude-hidden.sh b/t/t6021-rev-list-exclude-hidden.sh index 32b2b094138..11c50b7c0dd 100755 --- a/t/t6021-rev-list-exclude-hidden.sh +++ b/t/t6021-rev-list-exclude-hidden.sh @@ -2,6 +2,7 @@ test_description='git rev-list --exclude-hidden test' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Wed Dec 28 18:00:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083093 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 AF3B0C4167B for ; Wed, 28 Dec 2022 18:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233736AbiL1SAd (ORCPT ); Wed, 28 Dec 2022 13:00:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233451AbiL1SAb (ORCPT ); Wed, 28 Dec 2022 13:00:31 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCF4A165B3 for ; Wed, 28 Dec 2022 10:00:29 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id fm16-20020a05600c0c1000b003d96fb976efso9557329wmb.3 for ; Wed, 28 Dec 2022 10:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ftAH89VZzPB+zk++mYHC0WWaiZhbsvYUvRj9/JJpLoI=; b=RNKJH00oMkloNQ9suHzyHSygLcdEFknf+6LI5RMk3IB6YCmZLdnHJaDneDYkwIRsDj NiMjCvmW6jXEU9J1J/xOcB8K7hqcFDtfwGUnrlCs8yBNJ/zmwX2ZRArYpg5TpSxV/LPA 8o0Jb5zOSZkZgteB2eg6pEKwRNT1qr3lmDDEOV855cyk/k0WHMQxCdZkrTT0W06+vIXO gVIW+j0BE5m6Frhh2etitbt9v2q8PziE4tF2TmPXyciY1AeqCkyUbBoNiM+IcElwqjKW H2Fqi1tcvLxPv/TfDmwRRQjCqm845tFZ4L6lhWOUR34jKxzHnrnYp8V+P5iLl1Xr/B/D zZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ftAH89VZzPB+zk++mYHC0WWaiZhbsvYUvRj9/JJpLoI=; b=09B88MWK4Dcb1GrPMgLvdHwJMa60l7SZyA1JVU28gMlV+QGcOlKLQ/i48qJ+W4Bjqj FUansqeJh/xJ18pV3P/k9km3bmWzteNLhOhDgxbCaifUenVqRY2LLNLcfn+fWJlhHKIh SkAuUzN/6xF39QStQ/Du4HtxIu9UL8nXZYVCGVDpCxFQevBslg5EuWa+yjmKVEIQfmK6 60SMAh0Jg9jm+os1Fv0xU0sTVRw1+itpLKyRWxRoInKXwKveWdp3o6qHARTpCTMDne8Z PSsZhZM/G3Vm1FncIzBpykzVHPPbMLsXv+TAtzaNrypjPBqjzaWATvF/FPMDGTCrpj6w 1FdA== X-Gm-Message-State: AFqh2konDSRPHxBOINwmqCiNpMN9SsBO/wA/pHMwwc6C8ABdS2cQBEId HJYix4vQVkoKk3Hc6rknKMVYl3/3wkFb5g== X-Google-Smtp-Source: AMrXdXtGuFJX5vHRn15l7NLZsHSdZOhVq/0gXWsYowbv0NTGlAQN28hyg+jplRT4lKCQg5fdFwiC/Q== X-Received: by 2002:a05:600c:1d2a:b0:3d3:50b9:b1a1 with SMTP id l42-20020a05600c1d2a00b003d350b9b1a1mr21408525wms.1.1672250428057; Wed, 28 Dec 2022 10:00:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:27 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 02/20] tests: mark tests as passing with SANITIZE=leak Date: Wed, 28 Dec 2022 19:00:02 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the "ab/various-leak-fixes" topic was merged in [1] only t6021 (which was fixed in the preceding commit) would fail if the tests were run in the "GIT_TEST_PASSING_SANITIZE_LEAK=check" mode, i.e. to check whether we marked all leak-free tests with "TEST_PASSES_SANITIZE_LEAK=true". Since then we've had various tests starting to pass under SANITIZE=leak. Let's mark those as passing, this is when they started to pass, narrowed down with "git bisect": - t5317-pack-objects-filter-objects.sh: In faebba436e6 (list-objects-filter: plug pattern_list leak, 2022-12-01). - t3210-pack-refs.sh, t5613-info-alternate.sh, t7403-submodule-sync.sh: In 189e97bc4ba (diff: remove parseopts member from struct diff_options, 2022-12-01). - t1408-packed-refs.sh: In ab91f6b7c42 (Merge branch 'rs/diff-parseopts', 2022-12-19). - t0023-crlf-am.sh, t4152-am-subjects.sh, t4254-am-corrupt.sh, t4256-am-format-flowed.sh, t4257-am-interactive.sh, t5403-post-checkout-hook.sh: In a658e881c13 (am: don't pass strvec to apply_parse_options(), 2022-12-13) - t1301-shared-repo.sh, t1302-repo-version.sh: In b07a819c05f (reflog: clear leftovers in reflog_expiry_cleanup(), 2022-12-13). - t1304-default-acl.sh, t1410-reflog.sh, t5330-no-lazy-fetch-with-commit-graph.sh, t5502-quickfetch.sh, t5604-clone-reference.sh, t6014-rev-list-all.sh, t7701-repack-unpack-unreachable.sh: In b0c61be3209 (Merge branch 'rs/reflog-expiry-cleanup', 2022-12-26) 1. 9ea1378d046 (Merge branch 'ab/various-leak-fixes', 2022-12-14) Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0023-crlf-am.sh | 1 + t/t1301-shared-repo.sh | 1 + t/t1302-repo-version.sh | 1 + t/t1304-default-acl.sh | 1 + t/t1408-packed-refs.sh | 1 + t/t1410-reflog.sh | 1 + t/t3210-pack-refs.sh | 1 + t/t4152-am-subjects.sh | 2 ++ t/t4254-am-corrupt.sh | 2 ++ t/t4256-am-format-flowed.sh | 1 + t/t4257-am-interactive.sh | 2 ++ t/t5317-pack-objects-filter-objects.sh | 1 + t/t5330-no-lazy-fetch-with-commit-graph.sh | 1 + t/t5403-post-checkout-hook.sh | 1 + t/t5502-quickfetch.sh | 1 + t/t5604-clone-reference.sh | 1 + t/t5613-info-alternate.sh | 2 ++ t/t6014-rev-list-all.sh | 1 + t/t7403-submodule-sync.sh | 1 + t/t7701-repack-unpack-unreachable.sh | 1 + 20 files changed, 24 insertions(+) diff --git a/t/t0023-crlf-am.sh b/t/t0023-crlf-am.sh index f9bbb91f64e..575805513a3 100755 --- a/t/t0023-crlf-am.sh +++ b/t/t0023-crlf-am.sh @@ -2,6 +2,7 @@ test_description='Test am with auto.crlf' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >patchfile <<\EOF diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh index 93a2f91f8a5..a1251f65100 100755 --- a/t/t1301-shared-repo.sh +++ b/t/t1301-shared-repo.sh @@ -8,6 +8,7 @@ test_description='Test shared repository initialization' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Remove a default ACL from the test dir if possible. diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh index 0acabb6d11b..83c327ac2c8 100755 --- a/t/t1302-repo-version.sh +++ b/t/t1302-repo-version.sh @@ -5,6 +5,7 @@ test_description='Test repository version check' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t1304-default-acl.sh b/t/t1304-default-acl.sh index c69ae41306c..31b89dd9693 100755 --- a/t/t1304-default-acl.sh +++ b/t/t1304-default-acl.sh @@ -9,6 +9,7 @@ test_description='Test repository with default ACL' # => this must come before . ./test-lib.sh umask 077 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # We need an arbitrary other user give permission to using ACLs. root diff --git a/t/t1408-packed-refs.sh b/t/t1408-packed-refs.sh index 41ba1f1d7fc..9469c79a585 100755 --- a/t/t1408-packed-refs.sh +++ b/t/t1408-packed-refs.sh @@ -5,6 +5,7 @@ test_description='packed-refs entries are covered by loose refs' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index aa59954f6c5..6c45965b1e4 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -7,6 +7,7 @@ test_description='Test prune and reflog expiration' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_have () { diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 577f32dc71f..07a0ff93def 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -12,6 +12,7 @@ semantic is still the same. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'enable reflogs' ' diff --git a/t/t4152-am-subjects.sh b/t/t4152-am-subjects.sh index 4c68245acad..9f2edba1f83 100755 --- a/t/t4152-am-subjects.sh +++ b/t/t4152-am-subjects.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test subject preservation with format-patch | am' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh make_patches() { diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh index 54be7da1611..45f1d4f95e5 100755 --- a/t/t4254-am-corrupt.sh +++ b/t/t4254-am-corrupt.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git am with corrupt input' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh make_mbox_with_nul () { diff --git a/t/t4256-am-format-flowed.sh b/t/t4256-am-format-flowed.sh index 2369c4e17ad..1015273bc82 100755 --- a/t/t4256-am-format-flowed.sh +++ b/t/t4256-am-format-flowed.sh @@ -2,6 +2,7 @@ test_description='test format=flowed support of git am' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4257-am-interactive.sh b/t/t4257-am-interactive.sh index aed8f4de3d6..f26d7fd2dbd 100755 --- a/t/t4257-am-interactive.sh +++ b/t/t4257-am-interactive.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='am --interactive tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'set up patches to apply' ' diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 5b707d911b5..b26d476c646 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -5,6 +5,7 @@ test_description='git pack-objects using object filtering' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test blob:none filter. diff --git a/t/t5330-no-lazy-fetch-with-commit-graph.sh b/t/t5330-no-lazy-fetch-with-commit-graph.sh index 2cc7fd7a476..5eb28f0512d 100755 --- a/t/t5330-no-lazy-fetch-with-commit-graph.sh +++ b/t/t5330-no-lazy-fetch-with-commit-graph.sh @@ -2,6 +2,7 @@ test_description='test for no lazy fetch with the commit-graph' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup: prepare a repository with a commit' ' diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 978f240cdac..cfaae547398 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,6 +7,7 @@ test_description='Test the post-checkout hook.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5502-quickfetch.sh b/t/t5502-quickfetch.sh index b160f8b7fb7..7b3ff21b984 100755 --- a/t/t5502-quickfetch.sh +++ b/t/t5502-quickfetch.sh @@ -5,6 +5,7 @@ test_description='test quickfetch from local' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5604-clone-reference.sh b/t/t5604-clone-reference.sh index 2734e37e880..dc86dea1333 100755 --- a/t/t5604-clone-reference.sh +++ b/t/t5604-clone-reference.sh @@ -7,6 +7,7 @@ test_description='test clone --reference' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh base_dir=$(pwd) diff --git a/t/t5613-info-alternate.sh b/t/t5613-info-alternate.sh index 895f46bb911..7708cbafa98 100755 --- a/t/t5613-info-alternate.sh +++ b/t/t5613-info-alternate.sh @@ -4,6 +4,8 @@ # test_description='test transitive info/alternate entries' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'preparing first repository' ' diff --git a/t/t6014-rev-list-all.sh b/t/t6014-rev-list-all.sh index c9bedd29cba..16b8bd1d090 100755 --- a/t/t6014-rev-list-all.sh +++ b/t/t6014-rev-list-all.sh @@ -2,6 +2,7 @@ test_description='--all includes detached HEADs' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh index ea92ef52a5e..ff09443a0a4 100755 --- a/t/t7403-submodule-sync.sh +++ b/t/t7403-submodule-sync.sh @@ -11,6 +11,7 @@ These tests exercise the "git submodule sync" subcommand. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh index b7ac4f598a8..ebb267855fe 100755 --- a/t/t7701-repack-unpack-unreachable.sh +++ b/t/t7701-repack-unpack-unreachable.sh @@ -5,6 +5,7 @@ test_description='git repack works correctly' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh fsha1= From patchwork Wed Dec 28 18:00:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083094 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 A6142C4167B for ; Wed, 28 Dec 2022 18:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233788AbiL1SAi (ORCPT ); Wed, 28 Dec 2022 13:00:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233656AbiL1SAc (ORCPT ); Wed, 28 Dec 2022 13:00:32 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33AEF167C0 for ; Wed, 28 Dec 2022 10:00:31 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id y16so15544046wrm.2 for ; Wed, 28 Dec 2022 10:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ykWqZXWyl7svJ+WNwzbKCePyys9rgWLoCf4uryIgFVk=; b=o7QIMe2CPmfRtnLIsbwkCEtvzbystEA/zwe9X6EFXOkrZjf/0gXFmloC/jAB8ikQtO RccrJdaT6s8DLKz7xBrswllvYpglGwhBVFHNA2Jn3JVFcM28tEBFAwntjKA3jSo8V7HR puu735EDbVCTP4hhHnu9p3hvdU3vASvVjRT72LG16QDq4MRD2sVala5MiHIwZ3TBFYCp 8qWmoXqD4hkE3q1ks6rYeTzrWYbZ2X0elDwuP5Tx7O59ovpE/t4aEz9K6GyP1Vzngirg gQXAOfOrgBiplyKaqQiENGay6ntoCVmPjfSx7bxNi05F9SE2IAQeRItfrFw7FCKUZxpV ytIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ykWqZXWyl7svJ+WNwzbKCePyys9rgWLoCf4uryIgFVk=; b=XGFtQRzMNglUA5eQSo7vYFcP3Q43HEyGBt4jC58sRsttWDV48pDqgimGOAwZ9R6IZv ALaIDQSlfVSJlSTQRvj0KtzTTPLSUuzLcmFHZRfzOhm0RVcota0Ra7DL8GxjZNtimEes HFEyTsEBbOtefE2bC9tTvPQ5J9I5iyLFyJFKM6mq4EwKrkIpai1/Mev7iwamVUmpucsA 2TKfcEIG9VyIy9ahx7eLOqTTIchN43IT8aWx+6PBw0uPb5nDopWsRHObpP1sVDu2//S8 BseToc9dgjxkkrRfeqr1ys7E6glZ02swBkq13P6s5+9tHl2grBbZLRmKwWq6iTuijeze 5kSw== X-Gm-Message-State: AFqh2krV26QU9BHvM/Cp/1eUBZQC8aMzoBd6taiR3Lm7JekMSHC8LZjE h4cUcUkLA3ihlgJ5TJ3/ntQmH4FtcepjOg== X-Google-Smtp-Source: AMrXdXsht7dEHH0PKOZop1C3Fps4aKI+kf+jFx8uW1Bbky0Zuto0gDZ6aMEEvMoou40bWT4+MGLaHw== X-Received: by 2002:a5d:4b81:0:b0:274:ecce:b3bf with SMTP id b1-20020a5d4b81000000b00274ecceb3bfmr11161859wrt.61.1672250429036; Wed, 28 Dec 2022 10:00:29 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:28 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 03/20] bundle.c: don't leak the "args" in the "struct child_process" Date: Wed, 28 Dec 2022 19:00:03 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a leak that's been here since 7366096de9d (bundle API: change "flags" to be "extra_index_pack_args", 2021-09-05), if can't verify the bundle we didn't call child_process_clear() to clear the "args". But rather than doing that let's verify the bundle before we start preparing the process we're going to spawn, if we get an error we don't need to push anything to the "args". Signed-off-by: Ævar Arnfjörð Bjarmason --- bundle.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bundle.c b/bundle.c index 4ef7256aa11..9ebb10a8f72 100644 --- a/bundle.c +++ b/bundle.c @@ -627,6 +627,10 @@ int unbundle(struct repository *r, struct bundle_header *header, enum verify_bundle_flags flags) { struct child_process ip = CHILD_PROCESS_INIT; + + if (verify_bundle(r, header, flags)) + return -1; + strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL); /* If there is a filter, then we need to create the promisor pack. */ @@ -638,8 +642,6 @@ int unbundle(struct repository *r, struct bundle_header *header, strvec_clear(extra_index_pack_args); } - if (verify_bundle(r, header, flags)) - return -1; ip.in = bundle_fd; ip.no_stdout = 1; ip.git_cmd = 1; From patchwork Wed Dec 28 18:00:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083095 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 85596C3DA7D for ; Wed, 28 Dec 2022 18:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233819AbiL1SAl (ORCPT ); Wed, 28 Dec 2022 13:00:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233713AbiL1SAd (ORCPT ); Wed, 28 Dec 2022 13:00:33 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20AB9167DB for ; Wed, 28 Dec 2022 10:00:32 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id i17-20020a05600c355100b003d99434b1cfso1560037wmq.1 for ; Wed, 28 Dec 2022 10:00:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eXWIagbtD2cbO2YSWei28RkhNOZXX5YB0XQXtnbi628=; b=HNZVyr7Dq7sbgpaQsf/mRGGC8oTRueCpZ/AQemifgUeJAKH8BNaU9Cn6yO2TL7tI7x NYUQFMsAspeT4M6Gem1w+ziplInm2FlWS6eNai7+yqNd56g8fig5goRisMlHNcLPkTRS iCEtYCnfycwErrxJ1aWQ3fm84ehejF+YtcyoI0ASTvlpxDknDreo3Thw3yi8S8CZ1dGN yyY5Ouj08m6NmbpsciIObXY/t3l+mMqFjsltrFRXm0FOI8kxK3AxMVfFEOr7ZqCrF0M8 RYNo1Hy0OyBwPD5RRYBoddQEk4n0zVnXJoGsTiF1+bwqLTePPI/yHxYnm7ygnSGb1imZ w7eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eXWIagbtD2cbO2YSWei28RkhNOZXX5YB0XQXtnbi628=; b=tT7RFPJNYMQytOm1X5JlEHVm9PKb631ITHo4G8QmW0k8VXbw85TaNSRAoyVrix6itS gvrua8/xuymzenUc2ZKEDjegMVA2PSNPHQ00iBNbteWa4t+vgDBZJJ4mBJQftuq9hdB5 87KYzBpVTnux4m63uevqC4Yd9749oxugXnvk5PwCj19/LhYiUk0o/PjDprCSuDyMDUE8 +FJf1vNlHiBOuJ5641dZxqH53fZ+IhLNLyGiXGEL6ibQUgsJUaH7SbSOex5NSs2qWBPD ICXJnmyeLULjwuOO7M0L+7oRpFNHWkK9+A+3gnr6uK1dFKivW5zhlohNzI641+PksyJY tDbg== X-Gm-Message-State: AFqh2kqGERhnP3Clb2F5cx9f+k+HbTxC3SB9HtYsYi7xWxgG1JW+nDeB Pa6par9o9cFxDDoCWyTzcl+/cPMydap+HQ== X-Google-Smtp-Source: AMrXdXummI7vwJWlBvJtpHtRrZnPcSL7i/61F59qG6U2xifYK+/GY6GCghjPaPiR7t56WUAd9OUmQw== X-Received: by 2002:a05:600c:1ca5:b0:3d1:d746:7bca with SMTP id k37-20020a05600c1ca500b003d1d7467bcamr18404854wms.4.1672250430308; Wed, 28 Dec 2022 10:00:30 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:29 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 04/20] commit-graph: use free() instead of UNLEAK() Date: Wed, 28 Dec 2022 19:00:04 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 0bfb48e6723 (builtin/commit-graph.c: UNLEAK variables, 2018-10-03) this was made to UNLEAK(), but we can just as easily free() the memory instead. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index e8f77f535f3..b6e5726b082 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -67,6 +67,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix) int fd; struct stat st; int flags = 0; + int ret; static struct option builtin_commit_graph_verify_options[] = { OPT_BOOL(0, "shallow", &opts.shallow, @@ -111,8 +112,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix) if (!graph) return !!open_ok; - UNLEAK(graph); - return verify_commit_graph(the_repository, graph, flags); + ret = verify_commit_graph(the_repository, graph, flags); + free(graph); + return ret; } extern int read_replace_refs; From patchwork Wed Dec 28 18:00:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083096 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 4A296C4167B for ; Wed, 28 Dec 2022 18:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233761AbiL1SAm (ORCPT ); Wed, 28 Dec 2022 13:00:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232168AbiL1SAf (ORCPT ); Wed, 28 Dec 2022 13:00:35 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0B7D17E05 for ; Wed, 28 Dec 2022 10:00:32 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id k26-20020a05600c1c9a00b003d972646a7dso8541414wms.5 for ; Wed, 28 Dec 2022 10:00:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1TISjA0apihEl3pCG1zbo4y5xSb4rixiX32mGlnAjcE=; b=AoHRWeLyFfxGZGoTm0iAidVCXnguHM1pRrKJub6+u46mpxH3bfoeZ1BOCCCehqG44+ ib5+LSQbrz9TKHbAdPoTiDlUc5GgPvGKenTMNZzPD5hanZ6XJBCYpWJsrNwmXF5uKoNX 8SWIZ4ak3iO9DXUIzsBJSKDc/IMc+3OmffZzcGcMCchlRjHWWqRW8S0UV1DwaxPe3EDW dsagkOti0jRtVYJfYumPeAuZe9TQFCfSooJJQy2pPyEjbbPQ9p5gFh9ph/QPqmtVZytO Z+d/XlQ26t4ZQkrF4Fg/RiPm15BcmeRkfdP26KvRnShMPba87OFAdNRTcfz5pKTmyxfN 0eXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1TISjA0apihEl3pCG1zbo4y5xSb4rixiX32mGlnAjcE=; b=cVKSZzmJyiRAGgcYa3vSu5NRkBzQODkYEc9jiFsWt7CFacVKxiTxgMsTxD3gtMerm+ F6w9+KxeBzKJwCKVLuxne/sQCWi5JjFva40e58T7nqF2ww0tHMvNQUiEYhSU7zdEqCKI UY+K8dW7YaawcHL5xvJ3vokrBAB9pgG72aP1eWMNmDogC+9w+Cf3FW0vu0ULTPdodywI xnqWeuASN/57HZIszIpuWzqfvME9f4vakAolr6GBcOqPjj+SC5Np5fQBx66l4NkXcpsC eHCybIq2d9/J6KMPjdeLFFzfg2HKJwKl46dADNvznNpnEI1xRYr3JaDfvMhlSihaw4Fz OBDQ== X-Gm-Message-State: AFqh2koLAAsEo6DFxz04IZUTMAANtaIjgiibKHHYs91o/oBxdwWJL71b pSNQB9x/Xg5I50+HqoZ8zZuyzHTh2KPEMQ== X-Google-Smtp-Source: AMrXdXtYzXzFUoV5ZA7ijUGnRz/TGfg9leX2OF7fqqeezT4wduEwGESw6/23takYo5EYSoxc8oCNww== X-Received: by 2002:a05:600c:1604:b0:3d5:b222:20a with SMTP id m4-20020a05600c160400b003d5b222020amr18466976wmn.32.1672250431205; Wed, 28 Dec 2022 10:00:31 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:30 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 05/20] clone: use free() instead of UNLEAK() Date: Wed, 28 Dec 2022 19:00:05 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change an UNLEAK() added in 0c4542738e6 (clone: free or UNLEAK further pointers when finished, 2021-03-14) to use a "to_free" pattern instead. In this case the "repo" can be either this absolute_pathdup() value, or in the "else if" branch seen in the context the the "argv[0]" argument to "main()". We can only free() the value in the former case, hence the "to_free" pattern. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/clone.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index f518bb2dc1f..48156a4f2c2 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -892,6 +892,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int is_bundle = 0, is_local; int reject_shallow = 0; const char *repo_name, *repo, *work_tree, *git_dir; + char *repo_to_free = NULL; char *path = NULL, *dir, *display_repo = NULL; int dest_exists, real_dest_exists = 0; const struct ref *refs, *remote_head; @@ -949,7 +950,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) path = get_repo_path(repo_name, &is_bundle); if (path) { FREE_AND_NULL(path); - repo = absolute_pathdup(repo_name); + repo = repo_to_free = absolute_pathdup(repo_name); } else if (strchr(repo_name, ':')) { repo = repo_name; display_repo = transport_anonymize_url(repo); @@ -1392,7 +1393,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) free(unborn_head); free(dir); free(path); - UNLEAK(repo); + free(repo_to_free); junk_mode = JUNK_LEAVE_ALL; transport_ls_refs_options_release(&transport_ls_refs_options); From patchwork Wed Dec 28 18:00:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083098 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 AD48FC46467 for ; Wed, 28 Dec 2022 18:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233971AbiL1SAr (ORCPT ); Wed, 28 Dec 2022 13:00:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233783AbiL1SAh (ORCPT ); Wed, 28 Dec 2022 13:00:37 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39A5718399 for ; Wed, 28 Dec 2022 10:00:33 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id co23so15540792wrb.4 for ; Wed, 28 Dec 2022 10:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=14ZREzeD+V9g9eiFMBaVSo7ewXHvb5PlTR/vuI6RjLk=; b=pCUxTZt/EPjwZnwBw3wUFyPhCV283g/fhQ8JdT+OF5qGJDvUSCOOnbt9OrYTDRa9l2 IdFVyEDKHxYSoBDdgXdcfkzogZK8B6z8ovZMzOVW5k3bsXj5joF63/TmWNgGZk2TGXLa 7NrWVAMuYDk/Vife5xrVOmCB6TeklhxclDOxkPIu9ak1t1XNYKNS5/93/M95gwaV8Jv1 Dl2/dXxmpsvlqCDwHmtbn8v/SKZ+1TzMRSFngWtJwDTUBPBqm7OqmAGZYA8WsV5AQXB4 8xad8dNC8Jd5lLIsi7yAdNXRkRRCxvHrhWoJK8+elb7aYQO5zxSysKIpDfHBvSv7FnYO VMcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=14ZREzeD+V9g9eiFMBaVSo7ewXHvb5PlTR/vuI6RjLk=; b=k155IOgh2uT+5r/qqod3GnFrpCGUm2s3bwqblIMH5059W5doOR46ftyHVaXhF42Tfm ab25n082uPsoWtTzhqX+WnZZXCF9A2dI+iVfrI5sv0KRQ5XC54sBPbr7qlftb2lwJerc NJ1/sFg7wQiCDCnWtG38OLp5y49FIU+Fpy0uhfRvEEhKGDGbdLhAoHjfLyy4LK+k9E6o 15VbGHyh7ag30ylhIcFt48GKq08cWJ0PLRuxwqZJafAsLWn/WcZA3NTl6SSMYhIoqad1 itgMJR0sA6NKiORALqOpzJ2/JM3zkBnPFWtOTm33V8gon9zTv5OETQgV4OeHowVniEN7 oP7A== X-Gm-Message-State: AFqh2krUq9whAvumlb5akMKs731CEdMD3pHacPGbYLSKdGMImtDLq9+q 329M857jFmyhkppioySP2Lg2Xk4FIQxc3A== X-Google-Smtp-Source: AMrXdXs1ysiydpnb6SUkCTQtWd1QT4kKs0ZMavs1nXgw+yLvJu5SYAuEblBfaAHooBUcjtlmr5xVWQ== X-Received: by 2002:adf:f285:0:b0:270:57d:d1c9 with SMTP id k5-20020adff285000000b00270057dd1c9mr14303655wro.39.1672250432103; Wed, 28 Dec 2022 10:00:32 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:31 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 06/20] archive.c: call clear_pathspec() in write_archive() Date: Wed, 28 Dec 2022 19:00:06 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Plug a leak in the "struct archiver_args", and clear_pathspec() the "pathspec" member that the "parse_pathspec_arg()" call in this function populates. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 1 + t/t5001-archive-attr.sh | 1 + t/t5004-archive-corner-cases.sh | 2 ++ 3 files changed, 4 insertions(+) diff --git a/archive.c b/archive.c index 941495f5d78..a2d813e50db 100644 --- a/archive.c +++ b/archive.c @@ -710,6 +710,7 @@ int write_archive(int argc, const char **argv, const char *prefix, string_list_clear_func(&args.extra_files, extra_file_info_clear); free(args.refname); + clear_pathspec(&args.pathspec); return rc; } diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index 2f6eef5e372..04d300eeda7 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -3,6 +3,7 @@ test_description='git archive attribute tests' TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SUBSTFORMAT='%H (%h)%n' diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index ae508e21623..9f2c6da80e8 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test corner cases of git-archive' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # the 10knuls.tar file is used to test for an empty git generated tar From patchwork Wed Dec 28 18:00:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083097 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 9C300C3DA7D for ; Wed, 28 Dec 2022 18:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233775AbiL1SAp (ORCPT ); Wed, 28 Dec 2022 13:00:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233799AbiL1SAk (ORCPT ); Wed, 28 Dec 2022 13:00:40 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F4EE183A4 for ; Wed, 28 Dec 2022 10:00:34 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id w1so3414833wrt.8 for ; Wed, 28 Dec 2022 10:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nkt+Ewn/CwKksgG92QRo1+qNvbPT205QpPEYAwwn+2o=; b=Xhl1nHi2MxwDINagZ7OMdIRwtEZZOZ0UUEUKChHuYatZyXUUa8snmxr4EuKLBh7zY/ v3RRFmg3v68nIIeczUP3mzAFFSj4Jafoeed++RThKKAUVsNkczwuSA1NEraay+MrbXfU rhfLx/cJuGRnaTS2K/v2MN5SfYpZcVGYvYVoxdkeEFU3XwOfnY9PN2828rOguUQKOTx4 7epRiMRzhkGQLxHAd1KaXGORHHw/vE+V/uZE+3E8bxLVMpGjuGJjXSv3kYBhuloczCfh mwFF+Hy9uv0SHzTud/MhQLb1T0yFZcnC5DIBbUyPYFtZLb7LFPW+yXmxFS1vaOnPn8sT fv0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nkt+Ewn/CwKksgG92QRo1+qNvbPT205QpPEYAwwn+2o=; b=XWTLy1x2JqmurjbI8HgtLvT2nh7My843nqrNWuVHeBS5IoUvTHXRMKUrXtn7mJxkmY QEG0Sn/NEwVNwLiZO8BSCpB3i/oUI2ZDodal6kUXrGENurD8snWUXvdlEs1MaM2Zgv0T fBWFDFYaZBrzyQMbOWJWiYykVmRNgYRp28wy2FfNuJz+drWj5CzIGE5Wixnyl8vlGLzf rNs1J6annRwHnoaqe/3tRIqQawxx0Bo9/sCByrSM+6ZLthAN2IT4EUdZ635JO54zhPOS iKnS/GX4WjcK466jl7d5nkIROr0NUF7kghaXYjR//JqpF+rtQ3YRpltbfd/bg/LpfR1Q Cryg== X-Gm-Message-State: AFqh2kqy8eCenBuLERjA9ijBnCHm/pl0UqI7laVrqYecoSl0IuQ7uCQn zKr77dDRXlxvQ0ueXr2hqGsHcuZUUcF2QQ== X-Google-Smtp-Source: AMrXdXu1WbxYX3EdXiCTYNI5shCkwlje2xsvp8jNNywuD/IAYeKHvJOagg5132Pp7N31XeP3joFXSw== X-Received: by 2002:a05:6000:181:b0:276:c52a:e3a0 with SMTP id p1-20020a056000018100b00276c52ae3a0mr9525913wrx.65.1672250433101; Wed, 28 Dec 2022 10:00:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:32 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 07/20] stash: fix a "struct pathspec" leak Date: Wed, 28 Dec 2022 19:00:07 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Call clear_pathspec() on the pathspec initialized in push_stash(). Initializing that structure in this way is already done by a few other callers, and now we have: $ git grep -e 'struct pathspec.* = { 0 }' -e memset.pathspec add-interactive.c: struct pathspec ps_selected = { 0 }; builtin/sparse-checkout.c: struct pathspec p = { 0 }; builtin/stash.c: struct pathspec ps = { 0 }; pathspec.c: memset(pathspec, 0, sizeof(*pathspec)); wt-status.c: struct pathspec ps = { 0 }; Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/stash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index bb0fd861434..e82fb69c2b3 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1708,7 +1708,7 @@ static int push_stash(int argc, const char **argv, const char *prefix, int pathspec_file_nul = 0; const char *stash_msg = NULL; const char *pathspec_from_file = NULL; - struct pathspec ps; + struct pathspec ps = { 0 }; struct option options[] = { OPT_BOOL('k', "keep-index", &keep_index, N_("keep index")), @@ -1727,6 +1727,7 @@ static int push_stash(int argc, const char **argv, const char *prefix, OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), OPT_END() }; + int ret; if (argc) { force_assume = !strcmp(argv[0], "-p"); @@ -1766,8 +1767,10 @@ static int push_stash(int argc, const char **argv, const char *prefix, die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file"); } - return do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode, - include_untracked, only_staged); + ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode, + include_untracked, only_staged); + clear_pathspec(&ps); + return ret; } static int push_stash_unassumed(int argc, const char **argv, const char *prefix) From patchwork Wed Dec 28 18:00:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083099 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 8D160C4167B for ; Wed, 28 Dec 2022 18:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234195AbiL1SA6 (ORCPT ); Wed, 28 Dec 2022 13:00:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233818AbiL1SAl (ORCPT ); Wed, 28 Dec 2022 13:00:41 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2911F183B3 for ; Wed, 28 Dec 2022 10:00:35 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id t15so6697256wro.9 for ; Wed, 28 Dec 2022 10:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AzAZSaACoe/whop57XlBvgLBVC5IEyXOdcawpn/kwJ8=; b=K92cuGpOm8ZKGJBWeD+XGbMUyNIhLDWv0JahIib8nX90h+U7gn0yLpKsJltmdlAq2u 6guRiUcbC639uwG07uP7QbdU9J50nehWjTtSqJF4bSZGFD6QDyvTKV7mgu2A49ZA9Urd 4epaDjZHvoPEYUHP0HUl7ktS/GsWwk8B2WOi/8t3NZRXRr5HyEkdkL2lO+dXpWqzpleF LfsLlsJhZa30XyWYofS3nGdE32/MN1VcJ3adLpwWn1nm++gQ4j+8jO4wXp0arKj9i25Y ftQJv+Ob5pzTx97Zh/0OejR9tsANa3e1RG3vKYTq1T1SGcWjK8SgyjOw5VWOsTpQuEwn 4y9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AzAZSaACoe/whop57XlBvgLBVC5IEyXOdcawpn/kwJ8=; b=Tzs9ILlAIpxaMrYIMzuFnkxyQSxYVJZOrY4b/Oz+kBUDdllY4vvv8ZH/0aNJSm5wWX 3dsrVEukfsyFve1/2MZ/PID1NyN02MgA/XUL4UZPZKpNgHgo/iVNk/ugG0NC8fQDxs6A /hIRdJV1bYLzkxjvu1x5AKPzpvyL1paZu7JIPq8Z3dVW6UDnSN6G448TPhKkIim6lhCn gANmWeXUNFYRAZpeoMWrvpG3nY2yxiO2afyaa+CLG2XQ/y8nrXL7d+iapZa+0hn5olAr IcaDa3/wAPYg2tLjnhchY709Bssd8DTYMn3adNTep/l3Y/k0F8p2KGlf/YV5lvQGUD/w LoAw== X-Gm-Message-State: AFqh2kqSvYaNDJJuZ1oEm5DNOkdQIyzTM5hcMfl+oNJ0kwgEAPCruN4K fBqFsCVF6Ujxp70x0oOKlXXXdP/f12CVAA== X-Google-Smtp-Source: AMrXdXu1Btvo/IB1ljwiodfGG9YNHxN61Fqv8p0OW2sMM2n9e95QIWZuEiqK8P1O3Bi+i1dwa0QmBQ== X-Received: by 2002:adf:fc07:0:b0:288:ebd8:dc1f with SMTP id i7-20020adffc07000000b00288ebd8dc1fmr1377057wrr.55.1672250434037; Wed, 28 Dec 2022 10:00:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:33 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 08/20] reset: fix cmd_reset() leaks with a clear_pathspec() call Date: Wed, 28 Dec 2022 19:00:08 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add clear_pathspec() calls to cmd_reset(), including to the codepaths where we'd return early. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reset.c | 11 ++++++++--- t/t7105-reset-patch.sh | 2 ++ t/t7106-reset-unborn-branch.sh | 2 ++ t/t7107-reset-pathspec-file.sh | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/builtin/reset.c b/builtin/reset.c index fea20a9ba0b..e9c10618cd3 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -390,7 +390,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type != NONE) die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}"); trace2_cmd_mode("patch-interactive"); - return run_add_interactive(rev, "--patch=reset", &pathspec); + update_ref_status = run_add_interactive(rev, "--patch=reset", &pathspec); + goto cleanup; } /* git reset tree [--] paths... can be used to @@ -439,8 +440,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix) LOCK_DIE_ON_ERROR); if (reset_type == MIXED) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; - if (read_from_tree(&pathspec, &oid, intent_to_add)) - return 1; + if (read_from_tree(&pathspec, &oid, intent_to_add)) { + update_ref_status = 1; + goto cleanup; + } the_index.updated_skipworktree = 1; if (!no_refresh && get_git_work_tree()) { uint64_t t_begin, t_delta_in_ms; @@ -488,5 +491,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) discard_index(&the_index); +cleanup: + clear_pathspec(&pathspec); return update_ref_status; } diff --git a/t/t7105-reset-patch.sh b/t/t7105-reset-patch.sh index fc2a6cf5c7a..9b46da7aaa7 100755 --- a/t/t7105-reset-patch.sh +++ b/t/t7105-reset-patch.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git reset --patch' + +TEST_PASSES_SANITIZE_LEAK=true . ./lib-patch-mode.sh test_expect_success PERL 'setup' ' diff --git a/t/t7106-reset-unborn-branch.sh b/t/t7106-reset-unborn-branch.sh index ecb85c3b823..a0b67a0b843 100755 --- a/t/t7106-reset-unborn-branch.sh +++ b/t/t7106-reset-unborn-branch.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git reset should work on unborn branch' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t7107-reset-pathspec-file.sh b/t/t7107-reset-pathspec-file.sh index 523efbecde1..af5ea406db3 100755 --- a/t/t7107-reset-pathspec-file.sh +++ b/t/t7107-reset-pathspec-file.sh @@ -2,6 +2,7 @@ test_description='reset --pathspec-from-file' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_tick From patchwork Wed Dec 28 18:00:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083101 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 8F7C2C4167B for ; Wed, 28 Dec 2022 18:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233471AbiL1SBF (ORCPT ); Wed, 28 Dec 2022 13:01:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234059AbiL1SAu (ORCPT ); Wed, 28 Dec 2022 13:00:50 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66FB117E0B for ; Wed, 28 Dec 2022 10:00:36 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id h16so15507047wrz.12 for ; Wed, 28 Dec 2022 10:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E3QeGqHa71pgnG1kSKNIxgX5r/JJaCU+EVs4SGQYKTs=; b=g3XSJPqOQHxk4kw1kV1qfNJ/G/NHuWwCwKhBciSsSCI/onwWgYWzRC98xf4x/naWUB vebSdcK4Iz6nYifMwH3Jrf9dr4VBzremcvHcQLVES3gk+8yMWiJUwwo83q45cVOsNmaA J3rUp1F/a6Y1XwpRrvZ8r2jQG/pAjGZN03O/hd6tr1vGql5iJwW0n0Wyu274ZxXbFU9Q v8aqPqBPkzYep4tN8n0SUlGNiqe56qSGzwgOXtgnlY6theceYXx/pJv1yS3D/o9O1q63 fA5rqtgG4KuVKvscsqcjQvFfsD2pDAYFIy8d6rKbfUvdPLoDX4svkhFGMmWoeXLmA4HQ UNXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E3QeGqHa71pgnG1kSKNIxgX5r/JJaCU+EVs4SGQYKTs=; b=tttYrrcDjMe5CaoGN2z3XkLOqgFVNS/sU+VvEqnjfq3/fupBpetmfFhKZM7fS6X7cX GhUWD4LrCNKI7HI1Z/rec3xWgreADI3rhMBWPXCqUmzNEDEN/TUqLz8eDPEPom07owRg yHNkSPCVHhDGRHSezgDnbhdC2wOu1J5exkm9U2+sv+XnIucEZ2zRJIoAfayVjjncHGSA HvOe1S8/qnFlmMZ0bMWdorMaj7snjWimD2eAkqYYmeuKgKEVjBhothCknJ536zcu0JrI RRU6z/yCCEpLJISVCpBVCT1bI15Usis/iRRYoZKh1DTH00WAwhcpY2Z4KCtDiuoa/iJv fWMg== X-Gm-Message-State: AFqh2koE8L6AMbRWXtf+JSDuXb/LOaG4Vb6ZFNtTVwGbrYqoFRl9Nw73 gv2YD83+NyjDpYCz5MUmAjZsQbDuD6XOdw== X-Google-Smtp-Source: AMrXdXttj8WAWzVf9ougs65TUuuaIoNVDm3AdxwJO0KjfBtaHCu7kyilyq05iv8+2febduGRjNNJLQ== X-Received: by 2002:a5d:6888:0:b0:27e:315e:d282 with SMTP id h8-20020a5d6888000000b0027e315ed282mr5891393wru.49.1672250434962; Wed, 28 Dec 2022 10:00:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:34 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 09/20] name-rev: don't xstrdup() an already dup'd string Date: Wed, 28 Dec 2022 19:00:09 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When "add_to_tip_table()" is called with a non-zero "shorten_unambiguous" we always return an xstrdup()'d string, which we'd then xstrdup() again, leaking memory. See [1] and [2] for how this leak came about. 1. 98c5c4ad015 (name-rev: allow to specify a subpath for --refs option, 2013-06-18) 2. b23e0b9353e (name-rev: allow converting the exact object name at the tip of a ref, 2013-07-07) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/name-rev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 15535e914a6..24f4438eb01 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -313,7 +313,8 @@ static void add_to_tip_table(const struct object_id *oid, const char *refname, ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc); oidcpy(&tip_table.table[tip_table.nr].oid, oid); - tip_table.table[tip_table.nr].refname = xstrdup(refname); + tip_table.table[tip_table.nr].refname = shorten_unambiguous ? refname : + xstrdup(refname); tip_table.table[tip_table.nr].commit = commit; tip_table.table[tip_table.nr].taggerdate = taggerdate; tip_table.table[tip_table.nr].from_tag = from_tag; From patchwork Wed Dec 28 18:00:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083102 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 C2366C4167B for ; Wed, 28 Dec 2022 18:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234059AbiL1SBJ (ORCPT ); Wed, 28 Dec 2022 13:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234169AbiL1SAu (ORCPT ); Wed, 28 Dec 2022 13:00:50 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C162D186A9 for ; Wed, 28 Dec 2022 10:00:37 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id bx10so15563737wrb.0 for ; Wed, 28 Dec 2022 10:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BiLXVM8TDBUa8BcMOQ5eWP5wWaS+mhqokEYEB9t0d2E=; b=Ut8TADzOkFX0LuRNYXBVhJN0yo+2yhz0aGG0ssegobA2iJV1U6vBDWgFgRhMHxqSip 6QyHNNy8aq0Qr9hPPFMXc4cNln5Wel8wG37Xyvsi5zHNK6lPQ3hcQRujx/DB7bKu4jqB ZW35erHSImGy7vJhj+jSgTa7ZfTZ6zAv+26tG/ZgF+/13BY0ajtOoBt+VNIAOQAOD0/K HK9sr7rWMJEqsmId7zTydotcvBOoUCAJkCZ6DyGe6qaC79A+EIO+4s1EK/nU/Ak4N4er QmW5QTOlfHnGucqnLX+Zets34hFVQN+zQ0zqp0hjjLfLibIXbIGQONH8lhR9e02dP8Zw q9iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BiLXVM8TDBUa8BcMOQ5eWP5wWaS+mhqokEYEB9t0d2E=; b=QHDNICnZl5pRDchYaCmVuMxPiHJHxB4kliAnC2ich4ermyUtERwoC4ixJLkHnDpwtx MOAqQuGwMcooLX7icI+D2ID/yv14qiVGSfHTS0H/930OtL7tXaIPQNs+t0L0rB5Xf24n plKxdi0mt3qf/stt86vsVEFuXksNNuyqNPNTGtynANswd15UZusB9REQlxYiPGV3f33/ 2iS1lSQroALZyPLhrdTu6OGRf1tICcz2XEJzlzgqIKCGyiEoArVS8/Qu9ME0o7IpX0dZ +MyCR8g+k9LohAl+KuDa8NWOCvgrhzYUBI3oooeNou3BnrBqPQLOPfylMgtc5a0W5lXD yJwg== X-Gm-Message-State: AFqh2krv7lRHczCUKHS1zp6sFFKUvnnoKYc1rokZg1nxgwNXnwE0oJ41 uatHVTFr3WVcdzB//JOhXLZzSF7bxlUmOQ== X-Google-Smtp-Source: AMrXdXu+NO+32NSnK82zhwY5Tm/FXbSTEi4a0sBpZcNUkuP1swjRczKp3SSvK8fzhgjKwfuZaBiUQA== X-Received: by 2002:adf:cd8c:0:b0:271:9e7d:adbf with SMTP id q12-20020adfcd8c000000b002719e7dadbfmr18968321wrj.65.1672250435947; Wed, 28 Dec 2022 10:00:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:35 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 10/20] repack: fix leaks on error with "goto cleanup" Date: Wed, 28 Dec 2022 19:00:10 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change cmd_repack() to "goto cleanup" rather than "return ret" on error, when we returned we'd potentially skip cleaning up the string_lists and other data we'd allocated in this function. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/repack.c | 13 +++++++------ t/t6011-rev-list-with-bad-commit.sh | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index c1402ad038f..f6493795318 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -948,7 +948,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) ret = start_command(&cmd); if (ret) - return ret; + goto cleanup; if (geometry) { FILE *in = xfdopen(cmd.in, "w"); @@ -977,7 +977,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) fclose(out); ret = finish_command(&cmd); if (ret) - return ret; + goto cleanup; if (!names.nr && !po_args.quiet) printf_ln(_("Nothing new to pack.")); @@ -1007,7 +1007,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) &existing_nonkept_packs, &existing_kept_packs); if (ret) - return ret; + goto cleanup; if (delete_redundant && expire_to) { /* @@ -1039,7 +1039,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) &existing_nonkept_packs, &existing_kept_packs); if (ret) - return ret; + goto cleanup; } } @@ -1115,7 +1115,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) string_list_clear(&include, 0); if (ret) - return ret; + goto cleanup; } reprepare_packed_git(the_repository); @@ -1172,10 +1172,11 @@ int cmd_repack(int argc, const char **argv, const char *prefix) write_midx_file(get_object_directory(), NULL, NULL, flags); } +cleanup: string_list_clear(&names, 1); string_list_clear(&existing_nonkept_packs, 0); string_list_clear(&existing_kept_packs, 0); clear_pack_geometry(geometry); - return 0; + return ret; } diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh index bad02cf5b83..b2e422cf0f7 100755 --- a/t/t6011-rev-list-with-bad-commit.sh +++ b/t/t6011-rev-list-with-bad-commit.sh @@ -2,6 +2,7 @@ test_description='git rev-list should notice bad commits' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Note: From patchwork Wed Dec 28 18:00:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083103 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 72EDDC4167B for ; Wed, 28 Dec 2022 18:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234428AbiL1SBP (ORCPT ); Wed, 28 Dec 2022 13:01:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234081AbiL1SAu (ORCPT ); Wed, 28 Dec 2022 13:00:50 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1CA11869E for ; Wed, 28 Dec 2022 10:00:37 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id w1so3414956wrt.8 for ; Wed, 28 Dec 2022 10:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IAc2JEZYYZQHlHVtPzhQl3aiRKZwIYWHgqs1G5PNvTo=; b=TNYoy1WibrKLEvO33G5JuqNX4n892qIzBe7XDw00Jbhc+G/BSvr8/xhWJXa3jfQLiD TnG4xzvwvdYvSjZgkbKhAfXhltniCZzS4zeb3R2INfkn8tAQf5u2R/jZy/DuXPaEDI6F QvG7+HLE29rbu9srunnbMbr4/aQZzGTyw/599UnXQw83FcGAukT/z71WL6tODVV73r/h bFyY9XL3z/SErtRoZePGlfj8OkTSwP3AKxpreoKCTtjf19Z2unhq24G8mAIt8pCqa6fO Q1RiLyasoF1wg3Ec55oLQhERVQqhETJKj531lmGO3Wbkt9YEJ5JeTMJMYLMOrcj8vPKf vToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IAc2JEZYYZQHlHVtPzhQl3aiRKZwIYWHgqs1G5PNvTo=; b=urNSxIDVHRvXPJV7dRJSFuJzFZ/YCI0togKd01EQ/ZVskJdsYG+HcRYymIxkCOuQKI 3wKyfoZaBY1tTvuCUkBaGXNYK7P9uT9sow6q3k4uExhAuItCWH17t1VlE1FOe30NuIMG AVY7uI5vWebnzYZS0yMHb18unpVoZ0KKKs3A8f/4xlyXq5jkYAomq3ynC30LtDYDCfa5 dv9PitD/TurmtIgOeLpJ66cW94W5No64NfcK7U8O9ktcw0HLVM/K1mNqGX42rarDKviK gSAWKGqKKC5gKpLTo72IWQHsYf9GRr6Eruf/vC3xNUbpkk/YmTkkNgUk76CcLfq4cgWq /jEQ== X-Gm-Message-State: AFqh2kryVicukHZTkBbFM0Z/zLhU92uDMYueUzzAf26TKD5lCHk245Nc Blxpwc7/6skXJXXGrORgoavidNjo83vZMg== X-Google-Smtp-Source: AMrXdXvI8BkDjkSbEJIXcKuTMFCyqiqXtkY5WBBqb2l0nkLRaqeSiAlReUwo6K8zF9CqnfPTAm4o/g== X-Received: by 2002:a5d:5045:0:b0:27b:b974:2c01 with SMTP id h5-20020a5d5045000000b0027bb9742c01mr9493978wrt.71.1672250436862; Wed, 28 Dec 2022 10:00:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:36 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 11/20] worktree: fix a trivial leak in prune_worktrees() Date: Wed, 28 Dec 2022 19:00:11 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We were leaking both the "struct strbuf" in prune_worktrees(), as well as the "path" we got from should_prune_worktree(). Since these were the only two uses of the "struct string_list" let's change it to a "DUP" and push these to it with "string_list_append_nodup()". For the string_list_append_nodup() we could also string_list_append() the main_path.buf, and then strbuf_release(&main_path) right away. But doing it this way avoids an allocation, as we already have the "struct strbuf" prepared for appending to "kept". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/worktree.c | 6 +++--- t/t2401-worktree-prune.sh | 1 + t/t2406-worktree-repair.sh | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index 591d659faea..865ce9be22b 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -173,7 +173,7 @@ static void prune_worktrees(void) { struct strbuf reason = STRBUF_INIT; struct strbuf main_path = STRBUF_INIT; - struct string_list kept = STRING_LIST_INIT_NODUP; + struct string_list kept = STRING_LIST_INIT_DUP; DIR *dir = opendir(git_path("worktrees")); struct dirent *d; if (!dir) @@ -184,14 +184,14 @@ static void prune_worktrees(void) if (should_prune_worktree(d->d_name, &reason, &path, expire)) prune_worktree(d->d_name, reason.buf); else if (path) - string_list_append(&kept, path)->util = xstrdup(d->d_name); + string_list_append_nodup(&kept, path)->util = xstrdup(d->d_name); } closedir(dir); strbuf_add_absolute_path(&main_path, get_git_common_dir()); /* massage main worktree absolute path to match 'gitdir' content */ strbuf_strip_suffix(&main_path, "/."); - string_list_append(&kept, strbuf_detach(&main_path, NULL)); + string_list_append_nodup(&kept, strbuf_detach(&main_path, NULL)); prune_dups(&kept); string_list_clear(&kept, 1); diff --git a/t/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh index 3d28c7f06b2..568a47ec426 100755 --- a/t/t2401-worktree-prune.sh +++ b/t/t2401-worktree-prune.sh @@ -5,6 +5,7 @@ test_description='prune $GIT_DIR/worktrees' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success initialize ' diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh index 5c44453e1c1..8970780efcc 100755 --- a/t/t2406-worktree-repair.sh +++ b/t/t2406-worktree-repair.sh @@ -2,6 +2,7 @@ test_description='test git worktree repair' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' From patchwork Wed Dec 28 18:00:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083100 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 D79ADC4167B for ; Wed, 28 Dec 2022 18:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234241AbiL1SBA (ORCPT ); Wed, 28 Dec 2022 13:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234056AbiL1SAt (ORCPT ); Wed, 28 Dec 2022 13:00:49 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DAC4186B5 for ; Wed, 28 Dec 2022 10:00:38 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id d4so7536943wrw.6 for ; Wed, 28 Dec 2022 10:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T7cSFu4wamPHRmI3bGL0Hkg3f3NMwKBCd3DUSSku+Ys=; b=eG4pDaLYipaEzTJ7q9Pbtht69sOhB/FVlCP36IcheBvy/zdgTuqaQv+cA+foYDz10+ m3JhBXdEA8fad6Y3NPhGWtmDTRoJXwb1oyuI82YDBw3omWQPttlAWnZC5oLeALGoTpbn 5mW+WQHM67nP/06qQA6aNHB383kwpa0/XmtNAycN3wFdgzxHqkvwwrFC6T6RBt++d5SC M1Mv0Rtgyu2LzWXJyM1OytSSQPFmkoC30Qafymga6HGREX4fk2F2UjVJ21jCfhVj02eG Ab7Pp4OGc+5o0BQpjS24MmhKa+Rwym06FZewVkuDw5Valn0MpSwIRv23R7zh6fJLG9ir LSWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T7cSFu4wamPHRmI3bGL0Hkg3f3NMwKBCd3DUSSku+Ys=; b=uWbtZtLXoasy36ivlEHfTs60WJ0EIu51zXVy92f8T1R5Pt1BpoEP3iCWvVcXObNHf/ W5eFJSB6yAa3sVLZ8FjcwDXoaXu3M5yUsCBU4teZG9pjd35iOOsUMHo5WaLLhRZP3qQ9 H3sTNracS1B9GT18r9vBy0d2iox5bTcNUZ6O8Q4QjKZv/69mgHNc9+9TIAbeanL9hV6/ ejFlP9ylR4qsq5660JzS2Do4fijHGD3uAKKMX9JCAP0Z991KxJ5XnSk1GC8rAo9OLVAc bmk0ZpHXvNYcqI2YajtEGvO88jh+gT04ZlR+Me3DtER3eAgPCw8F7prHqjuhoXZ2aRW2 rKHg== X-Gm-Message-State: AFqh2kp0rlq7++Ldp24midUtMu+2UGHbnFOompsOtvqMUwa/JkY2R8Va fOvJndHjOVMvuAXPsCRUwadcq3XIP/8jWw== X-Google-Smtp-Source: AMrXdXvaDUXtSxIc6egahxWoKQQ6/PPwyd2dm5SpV+bOr41Q0ilH4XKrSlDXE0daKbhd58FU4MKPKQ== X-Received: by 2002:a5d:550e:0:b0:274:c846:4201 with SMTP id b14-20020a5d550e000000b00274c8464201mr10538618wrv.68.1672250437755; Wed, 28 Dec 2022 10:00:37 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:37 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 12/20] http-backend.c: fix cmd_main() memory leak, refactor reg{exec,free}() Date: Wed, 28 Dec 2022 19:00:12 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak that's been with us ever since 2f4038ab337 (Git-aware CGI to provide dumb HTTP transport, 2009-10-30). In this case we're not calling regerror() after a failed regexec(), and don't otherwise use "re" afterwards. We can therefore simplify this code by calling regfree() right after the regexec(). An alternative fix would be to add a regfree() to both the "return" and "break" path in this for-loop. Signed-off-by: Ævar Arnfjörð Bjarmason --- http-backend.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/http-backend.c b/http-backend.c index 6eb3b2fe51c..9bb63c458b1 100644 --- a/http-backend.c +++ b/http-backend.c @@ -759,10 +759,14 @@ int cmd_main(int argc, const char **argv) struct service_cmd *c = &services[i]; regex_t re; regmatch_t out[1]; + int ret; if (regcomp(&re, c->pattern, REG_EXTENDED)) die("Bogus regex in service table: %s", c->pattern); - if (!regexec(&re, dir, 1, out, 0)) { + ret = regexec(&re, dir, 1, out, 0); + regfree(&re); + + if (!ret) { size_t n; if (strcmp(method, c->method)) @@ -774,7 +778,6 @@ int cmd_main(int argc, const char **argv) dir[out[0].rm_so] = 0; break; } - regfree(&re); } if (!cmd) From patchwork Wed Dec 28 18:00:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083104 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 BAA26C3DA7D for ; Wed, 28 Dec 2022 18:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234890AbiL1SBT (ORCPT ); Wed, 28 Dec 2022 13:01:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234248AbiL1SAv (ORCPT ); Wed, 28 Dec 2022 13:00:51 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E7C0178BB for ; Wed, 28 Dec 2022 10:00:40 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id n3so14786411wrc.5 for ; Wed, 28 Dec 2022 10:00:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=24AYxfGOKt0kvEpasKToBFMori2rehTHt7xakRSaeNM=; b=H2kZSFta6rFTvn90DR/vGCaBPQZ5Unx5lJR5/Fg04THXcprFz6ZHhpD2kGOn9xqydo 1AQxQFZ+DsvcoYxFAQNtyIqXXAZY3TTkHWM7Ge3ZRV28QRtiQaLhxrTA80uybkEyrPHr nMFvLWshpkXtl+1p7ZEO22QfCoEzwvzJdaEgSdM5+iQsnhdiL552ZkP8u0lUwW1JA9Vg DhDS29vqPR44tgNL5Bs+ZbnCIovHfMwV/O6qvzifK0vhQNWTIF7thJL2fevasbJIx2zs p7x8ULeyqLdLxa4TibM1OimkwiEYGkHR1AxjCMTFW0zFH8MoeCZe004JnaYBggMM4lUQ mu7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=24AYxfGOKt0kvEpasKToBFMori2rehTHt7xakRSaeNM=; b=ORSczpCnENmPFKp9zQM+6Un6Age/G+EqmuIKvVZGVE0eP6e1ps3dQ6xyt/b286fkPk 6tcyh+27dbg5+GfeHhBKnKTKGdjZqu5V4XUxG37rTgUuFHEisv8qTAyZl9RJQ9ZzOHaf 44yT8S3oNgaGlESmPTTh6pImPL90XCPchpT7cPpyHyMVXBK4jnCwsox0ubPy4KDdanDr NGA2nJBMOJvGlCMi6IAOCzDT8E3J+aQrv6YS00e/tTL2mfN3zNsj5sU1M8lKNuak8ySH jL62TD0OQwsfJpgn76bwpFxnP5mJkBoveihgNtrFDgkCc9aPp6FVrim7pRjPA3KFNbrV 9O2w== X-Gm-Message-State: AFqh2kpZZoTSUvzK/oYpVE97C2dwJH6CB4AQWDnTyxa99utG5xiC+/qo OCh5iBlU3vVrvzxT0TN7maNmxwaPCIHp4A== X-Google-Smtp-Source: AMrXdXusfVu1Bl+YK3bg2/t+4vhJctBZNBRSZU+tsghhBQaN3p/hO7+mY82xN1fQaFsNkgZJA9fyZQ== X-Received: by 2002:a5d:430e:0:b0:279:53e1:5178 with SMTP id h14-20020a5d430e000000b0027953e15178mr8642521wrq.45.1672250438610; Wed, 28 Dec 2022 10:00:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:37 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 13/20] commit-graph: fix a parse_options_concat() leak Date: Wed, 28 Dec 2022 19:00:13 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the parse_options_concat() was added to this file in 84e4484f128 (commit-graph: use parse_options_concat(), 2021-08-23) we wouldn't free() it if we returned early in these cases. Since "result" is 0 by default we can "goto cleanup" in both cases, and only need to set "result" if write_commit_graph_reachable() fails. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index b6e5726b082..c76faffde4b 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -269,8 +269,8 @@ static int graph_write(int argc, const char **argv, const char *prefix) if (opts.reachable) { if (write_commit_graph_reachable(odb, flags, &write_opts)) - return 1; - return 0; + result = 1; + goto cleanup; } if (opts.stdin_packs) { From patchwork Wed Dec 28 18:00:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083105 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 CDDB6C3DA7A for ; Wed, 28 Dec 2022 18:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234928AbiL1SBV (ORCPT ); Wed, 28 Dec 2022 13:01:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234330AbiL1SAv (ORCPT ); Wed, 28 Dec 2022 13:00:51 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 847B418391 for ; Wed, 28 Dec 2022 10:00:40 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id w1so3415056wrt.8 for ; Wed, 28 Dec 2022 10:00:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TEoAVPFWQj6eTEnHFPwT8ljXdYVMaWUYtcAMHRyg+Aw=; b=Tqh6eAvz0nA/Jwat8t1vV3DjX8LZLGJpyptlBTG/CYz4n7otb4EPEHUkmHSsmlUCX1 7FQ/nDv9sxfTElvveQdiaC6Q06U8ZYVH++Zn5G1t5MytHqb6VwOJ0Pq7DmvyorUDaCXV XOAx/uKgVCZ4JgZT/Bqotnzik7xM0qijxLk/SmD7oiI9b69QrvrkttbsPHyFcLp97f/P oMHh8/VTr0aj1XcGTK68j/q73Mlb/vyVJRyIHXsWvaED43qktm42RYtE5VtY+hlT1GRo xw9dxB4tFLLLC2sgzgqOrt/fP5iKhvhLcv6QeWoZNhtVKGkQyZ3uyvhu1Rc37KQGuSui Eaeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TEoAVPFWQj6eTEnHFPwT8ljXdYVMaWUYtcAMHRyg+Aw=; b=Q0stN8vBlcjxJ8rC7rzfHbtfM3TMaJ2Y4NxVe9E5ENIXYD0NK9SysYU4JD/rXue2Vu Z0yfQxl8CkShj+iglgWbVOW7dTf+CNoRd9Mq7uB1nN365lcOYHumnompBaG0GmlmkdpX esQXUX4Etl/Ovl5YmPGMq3hSBHStHuN00lpYQ2cMGyn0+b4o1cdIQWxghFxxHD5bWZ7X +I1jzDeAkyFBy1CQgTKgfSTq9vPSVJ+81TaERV6ONYgNJB8xuuRuJyhi1VAzZvk1xGlE iNBNhEXiJhC3ZEol9lXFw+TzdCky5kRxMm3i+dqzf4sR8+1hGbx7a9RtzPqLWhcqtI35 OF/Q== X-Gm-Message-State: AFqh2kqPyzkVTXZ+xLX6s/cBYIM83rfpM4mfByT2T+jH2onwdjlARfjz Y3J3HJJvLw63ktzblc+qW542lNTYkxXJew== X-Google-Smtp-Source: AMrXdXtXFOMBazJTE26wDoat7N1vojh2p30JQ8k1zOy11NVsHe9TL6Yz4XynKRpqODbloCdVD3K2lg== X-Received: by 2002:a5d:4ed1:0:b0:285:4b69:ba06 with SMTP id s17-20020a5d4ed1000000b002854b69ba06mr3526402wrv.6.1672250439772; Wed, 28 Dec 2022 10:00:39 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:39 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 14/20] show-branch: free() allocated "head" before return Date: Wed, 28 Dec 2022 19:00:14 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Stop leaking the "head" variable, which we've been leaking since it was originally added in [1], and in its current form since [2] 1. ed378ec7e85 (Make ref resolution saner, 2006-09-11) 2. d9e557a320b (show-branch: store resolved head in heap buffer, 2017-02-14). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/show-branch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/show-branch.c b/builtin/show-branch.c index c013abaf942..358ac3e519a 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -956,5 +956,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (shown_merge_point && --extra < 0) break; } + free(head); return 0; } From patchwork Wed Dec 28 18:00:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083109 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 5EE2DC4167B for ; Wed, 28 Dec 2022 18:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235076AbiL1SBq (ORCPT ); Wed, 28 Dec 2022 13:01:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234629AbiL1SAx (ORCPT ); Wed, 28 Dec 2022 13:00:53 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C31E51C7 for ; Wed, 28 Dec 2022 10:00:42 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id o5so15548828wrm.1 for ; Wed, 28 Dec 2022 10:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Me5yoomandW5HHAqMIsi2xDzzDfq8Zh88Qy9zDdhyGg=; b=lq8n8vUtKxWWa6Zvi6JPLPlIb1VHVOfyh8hrVvrwnjmNlepnWdSLYeg5oo0Q/ZJQ5Y Mq7FE0jIpzu3zcT8BpJsFq06/4KV3mjLgAbMO3PAGA+6v+ie8S3eWhTixfZQ4PdJoukw H4cDlzwDDgALa3bVciChc/B5h67u/ZaXs5xF2E3ZLAcqSZ+giIqdCaLksMe/zp9LTy3y pju6lYEMuuaxUN7uuhAwtAZDuzv1OwtOrEVL4ETwZ4b5r7Sk041mK5/yY23n2V/BERtc G+IgjE7IcdhoUPdxE0YtaeArJBdToXJa/pIUVLSiGCIzWzd9WoghLhUymGl/JudW1sx/ vCgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Me5yoomandW5HHAqMIsi2xDzzDfq8Zh88Qy9zDdhyGg=; b=Yv3WK7GQm6ntVai/S/KNA1poWxJ2+eRebouzIBmt1R7k466tFFlh0kqHcgpy1FmDA0 RONdl6HQ9E55J42pTBIK+0c3JqyDys6ph9ThPkHhddl+svjL5NVylKbwRn17ag6HyEx3 D60FRtPGFkvRfvEy2Aoqw40XIOID2wzDGma/UvO+j2c3bZKNDntHixrSHhJHMlXDFAUz 0kB03imD6rPynozwKcKBWiNq5N0sk6EUjbbnlunxMSPCNG84U2PAX6Ga7DdtQYS4sH7f FRXDPd0liuUrPeCzZ12GbrnUACR4sAU0HirmZGgKLhDUCZipmXjjSiA6B9Cw8fWz9DpR yVdg== X-Gm-Message-State: AFqh2kpYyKe9tCBAwR7D4kztfP4oyJI93E8N8FGuYcARxnjfSRMRoAma o+jINQanVkh01C+MK9WUpxnlIMIi2olA4w== X-Google-Smtp-Source: AMrXdXsOu4c5XpD2/tjKOj+hbmb4WMphIGiETcM+xS9rT0HLutdKWq0XBGoEajra/vqYeh0TCtYSdg== X-Received: by 2002:a05:6000:16cb:b0:242:1b0d:9c58 with SMTP id h11-20020a05600016cb00b002421b0d9c58mr18876068wrf.69.1672250440686; Wed, 28 Dec 2022 10:00:40 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:39 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 15/20] builtin/merge.c: always free "struct strbuf msg" Date: Wed, 28 Dec 2022 19:00:15 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Follow-up 465028e0e25 (merge: add missing strbuf_release(), 2021-10-07) and free "&msg" also when we'd "goto done" from the scope it's allocated in. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/merge.c b/builtin/merge.c index 0f093f2a4f2..8f78f326dbe 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1577,6 +1577,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) commit = remoteheads->item; if (!commit) { ret = 1; + strbuf_release(&msg); goto done; } @@ -1589,6 +1590,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) overwrite_ignore)) { apply_autostash(git_path_merge_autostash(the_repository)); ret = 1; + strbuf_release(&msg); goto done; } From patchwork Wed Dec 28 18:00:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083106 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 E4371C4167B for ; Wed, 28 Dec 2022 18:01:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234592AbiL1SBi (ORCPT ); Wed, 28 Dec 2022 13:01:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234572AbiL1SAx (ORCPT ); Wed, 28 Dec 2022 13:00:53 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C32B21EA for ; Wed, 28 Dec 2022 10:00:42 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id d4so7537085wrw.6 for ; Wed, 28 Dec 2022 10:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/lqA3yuulvDMdeQe8LLJKH1qTvxkQsuxqj8I7uFcZJQ=; b=JkgyC4c1ysJH4oxXMqZxgGaNnZd9STwfLPxSCJKLG3CU8U34c0YL7Qdie1EXcJ0/HE kgIFqTPiSNp4ebP2MNTtahK1KhGFmTbv2rAM5B0MKeJpMqWFuuE422tLrZG0sKEhcgKU msH3DUo0gtB2ISJtuvipmGEXFZ9oyI1ZnCNqKM9RmKNIvqjKdtEVY1dSaET8fBsx33Qq GVZZrMtMhkIiVbTVVMZmF+fdgCfvtTURzBki6/jtRkXlKilJfgrGCXEiRvT4yDUG0hkE oI5HIIHsKyJks2erDPsi4AlSBiDoGOyn55KmB7GvD+Ccbyo9WNd6n2uHPmLdG7lT0d1U vuqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/lqA3yuulvDMdeQe8LLJKH1qTvxkQsuxqj8I7uFcZJQ=; b=YyXXIqj4a/7O7jzSSFBPUJJLjIjYF0qW6AUC+q8aDS76gpSs/MHQ8+V+DEKCKcGRXl 8hFHuRFSE2YKz+6vX9SOUzRXdyKIfB9EsUJiurIcWxd8JlZewZn+dDn6jfDBmn1djHRa kapSGxiv7IXk/a5DdqpZlxqoObvs6mKatBJF+inNNZP1N5hK9nHXlqc1QBHbywhGEPs1 d1/ARIagrrat6rQj9pktYOHcunjTgp3VxUbVEosahcCM4mbhx77JwPCquJxXsLS4cNU8 KuWET/EvXJVHsBPOTAeB5hP5ugIChH+/dzaSIweswBbM1WChPgf7yDS7D4kLpKIGZL2q TdyA== X-Gm-Message-State: AFqh2kpeMfakOmn4jVnU/343CUwLXyTGYKDEeLnmTANflG1QSKOb1LSD xus6REakE1dxWyADVRiSShO5vmFD7fl6RA== X-Google-Smtp-Source: AMrXdXsiY7/2TUKHE+Sz8nUHEzfszvlGftRiV4xpCXOzVOpVCH4rT9zXuW1Kk7f/RX8wzd36jLubBg== X-Received: by 2002:a5d:6145:0:b0:27a:5709:7d96 with SMTP id y5-20020a5d6145000000b0027a57097d96mr8178265wrt.41.1672250441575; Wed, 28 Dec 2022 10:00:41 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:40 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 16/20] builtin/merge.c: free "&buf" on "Your local changes..." error Date: Wed, 28 Dec 2022 19:00:16 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Plug a memory leak introduced in [1], since that change didn't follow the "goto done" pattern introduced in [2] we'd leak the "&buf" memory. 1. e4cdfe84a0d (merge: abort if index does not match HEAD for trivial merges, 2022-07-23) 2. d5a35c114ab (Copy resolve_ref() return value for longer use, 2011-11-13) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 3 ++- t/t6439-merge-co-error-msgs.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index 8f78f326dbe..e29b456f92c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1623,7 +1623,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) error(_("Your local changes to the following files would be overwritten by merge:\n %s"), sb.buf); strbuf_release(&sb); - return 2; + ret = 2; + goto done; } /* See if it is really trivial. */ diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh index 52cf0c87690..0cbec57cdab 100755 --- a/t/t6439-merge-co-error-msgs.sh +++ b/t/t6439-merge-co-error-msgs.sh @@ -5,6 +5,7 @@ test_description='unpack-trees error messages' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh From patchwork Wed Dec 28 18:00:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083107 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 BB33EC4167B for ; Wed, 28 Dec 2022 18:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234676AbiL1SBk (ORCPT ); Wed, 28 Dec 2022 13:01:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234636AbiL1SAy (ORCPT ); Wed, 28 Dec 2022 13:00:54 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1762DC for ; Wed, 28 Dec 2022 10:00:43 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id h16so15507309wrz.12 for ; Wed, 28 Dec 2022 10:00:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=413D+CELXTZtussK+RVwQ2qyX4Y9wpLeV+m+KMRcll4=; b=jRWqGzAK2VjPAr7O0tO585AdjfxSjFY7RNSqbTF2rr6Wl4f/HHDmwLLhdvqZs9qf/M F4rLYYYZdp/PPczhzRvODLG/ZG0hzFw81d0C03NoXp+e3kOT75ms96xOPD2igVDMsL7i N2UZ2/iPku+CYyG84h5drI+t1tK7MHFw73TlT9jgQInxy57cB5NH43DEKq+v6nzDtvo3 hpA7n2Y5D7YuvHF7ZUJudsYQ4SFbNRRuehOv3OVmCXKAlGpQ8txhZxVhXecRAgl4WZSy mZwmj2NcyneWnZpt6zOgeQKtn1a2E0EXBWnL2MiEdwWTHjR5pNuDAcWSsxf+Dy1aV23H ALkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=413D+CELXTZtussK+RVwQ2qyX4Y9wpLeV+m+KMRcll4=; b=iJAd701SsuCtwtJAU+udRm/WNkl0Yc/KRpWr2e5QeBB6hkzAkVR/KG6MXba+8re4vb TmaXaLTTznfXOR97leySWHv7r/DycYH44viHZFu1RUIxY5hWa2hE0S4EnkzNIHPZzEie TPC04TClqSL3+Pw+EmZZKbhmpYJ/ImID81uXJkqQuhO5kjDi3qAFzZE3nRL4GK4ceSNW +o1dxAG68NutzgN+cKHtOOvCc7RaAXZC+frrPUI6SWbZ5PHlnOKijHWOtgAGcnR4USBH bJCXrk8uFXMOAIJqkibhNfX4f2ogH78KuChY8qYuOYpJQmtf5SFWO6ChiTjDjMlqiUzh dckA== X-Gm-Message-State: AFqh2kpBowTHmoh4dJtNzSyx92m//XlYFzSHTnRi1wZlNAxdCp3ZQJLK UKCGGBvQTEt+anaFerh74m8QrqjXq96Nbg== X-Google-Smtp-Source: AMrXdXtjOgRkftq6XhV9IhaB3AaKHB4b3RlhhHI1J8OwrJ2AXOF8+LtAo+GDZgF9TDLt50wS1OZkfQ== X-Received: by 2002:adf:e6d1:0:b0:27c:dcf5:ad52 with SMTP id y17-20020adfe6d1000000b0027cdcf5ad52mr8733391wrm.11.1672250442576; Wed, 28 Dec 2022 10:00:42 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:41 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 17/20] connected.c: free(new_pack) in check_connected() Date: Wed, 28 Dec 2022 19:00:17 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak that's been with us since this code was introduced in c6807a40dcd (clone: open a shortcut for connectivity check, 2013-05-26). We'd never free() the "new_pack" that we'd potentially allocate. Since it's initialized to "NULL" it's safe to call free() here unconditionally. Signed-off-by: Ævar Arnfjörð Bjarmason --- connected.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/connected.c b/connected.c index b90fd61790c..e4d404e10b2 100644 --- a/connected.c +++ b/connected.c @@ -38,7 +38,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data, if (!oid) { if (opt->err_fd) close(opt->err_fd); - return err; + goto cleanup; } if (transport && transport->smart_options && @@ -85,8 +85,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data, promisor_pack_found: ; } while ((oid = fn(cb_data)) != NULL); - free(new_pack); - return 0; + goto cleanup; } no_promisor_pack_found: @@ -123,8 +122,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data, rev_list.no_stderr = opt->quiet; if (start_command(&rev_list)) { - free(new_pack); - return error(_("Could not run 'git rev-list'")); + err = error(_("Could not run 'git rev-list'")); + goto cleanup; } sigchain_push(SIGPIPE, SIG_IGN); @@ -157,6 +156,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data, err = error_errno(_("failed to close rev-list's stdin")); sigchain_pop(SIGPIPE); + err = finish_command(&rev_list) || err; +cleanup: free(new_pack); - return finish_command(&rev_list) || err; + return err; } From patchwork Wed Dec 28 18:00:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083108 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 A92B9C46467 for ; Wed, 28 Dec 2022 18:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235101AbiL1SBt (ORCPT ); Wed, 28 Dec 2022 13:01:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbiL1SA4 (ORCPT ); Wed, 28 Dec 2022 13:00:56 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A4C09593 for ; Wed, 28 Dec 2022 10:00:45 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id y16so15544526wrm.2 for ; Wed, 28 Dec 2022 10:00:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fidQFlaoa7Dfo31jFTP7XB3GTHt0mBrPuMV3HSHbZws=; b=GNdYe05pbN8yHa4rUI6dtcc2+7wwPJt4GhuHGjS1HmzDoguiOQQKakTR1nfNCry5Bp Dm6eKtOB9i3qZHRBZ87YTrEFUSC4nacaik5600/HadT1FKy+C6TnxoH49ryUbmfQyYIq mMp9/Ju5w0VcwMfxh3bXk7Fma4p4crOjVjuGeZzxkwpE8AZ0o4P5PLKdUFa6yms43QnJ B2lwzTHHIr6r73MSKEA3H/2q90GPgqabVIkbL0scZOjpvcKMrzPZwHEThnFdRxEWwziS X4emIKWoi3lyPPqT8j5bWwCDDB65bgbE4iAN3zoBAFc2menl2nDQGQH6wg7HPf1tczhO dHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fidQFlaoa7Dfo31jFTP7XB3GTHt0mBrPuMV3HSHbZws=; b=For4FRWZFqPnIyny3A2zg251FxUG95E/SqXDk5Ktf/iN4mBZDzuWJ1aAnhygh2SoWH GHiqxJpSfUOyxOXVgnJ6pyISePMTWXHLYWCAdnsH9O5BIU2ajDCV0+QZM6nHeTfDC3gq CPMa/HufW0R/JH6pqadysKmieGqI3kyeB9LvLNxoZclrIMTWXw4AZwdluy0NS1wGRlmd KAZfdf8uA37c0vb7YMCE0CmUdGtpkCmDHOlIDd671dI6uxsEEZ0gc73dL73azTkLd4gI JbJRAlrEJiQ5KTP7NOuxxMfHl0DOgyNHima2WAPLHUkf5Z7H5oKqd5SOtz4MsH/iNNsi a7kw== X-Gm-Message-State: AFqh2kpFm2LtZjzPI7ER529huU05fZllNih44sfHWob5VupnIqyy61zs U8QmgAgpIBDX7ExLhXgdmKd6hR0uc3Yd1g== X-Google-Smtp-Source: AMrXdXtqvzHuJSQCHnWgEWGU4Z9VOqlXDT5fo25DShkSmIQ0gyecYmAxz1Av+GjcN6N/3g5kctW/Sw== X-Received: by 2002:adf:fa0b:0:b0:268:2971:465f with SMTP id m11-20020adffa0b000000b002682971465fmr15656637wrr.50.1672250443485; Wed, 28 Dec 2022 10:00:43 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:42 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 18/20] object-file.c: free the "t.tag" in check_tag() Date: Wed, 28 Dec 2022 19:00:18 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak that's been with us ever since c879daa2372 (Make hash-object more robust against malformed objects, 2011-02-05). With "HASH_FORMAT_CHECK" (used by "hash-object" and "replace") we'll parse tags into a throwaway variable on the stack, but weren't freeing the "item->tag" we might malloc() when doing so. Mark the tests that now pass in their entirety as passing under "SANITIZE=leak", which means we'll test them as part of the "linux-leaks" CI job. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 1 + t/t3800-mktag.sh | 1 + t/t5302-pack-index.sh | 2 ++ 3 files changed, 4 insertions(+) diff --git a/object-file.c b/object-file.c index c1b71c28347..36ed6c3122c 100644 --- a/object-file.c +++ b/object-file.c @@ -2331,6 +2331,7 @@ static void check_tag(const void *buf, size_t size) memset(&t, 0, sizeof(t)); if (parse_tag_buffer(the_repository, &t, buf, size)) die(_("corrupt tag")); + free(t.tag); } static int index_mem(struct index_state *istate, diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index e3cf0ffbe59..d3e428ff46e 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -4,6 +4,7 @@ test_description='git mktag: tag object verify test' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh ########################################################### diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index b0095ab41d3..54b11f81c63 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -4,6 +4,8 @@ # test_description='pack index with 64-bit offsets and object CRC' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Wed Dec 28 18:00:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083110 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 B907CC3DA7D for ; Wed, 28 Dec 2022 18:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235179AbiL1SBw (ORCPT ); Wed, 28 Dec 2022 13:01:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbiL1SA4 (ORCPT ); Wed, 28 Dec 2022 13:00:56 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E4C7DF0D for ; Wed, 28 Dec 2022 10:00:46 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id y16so15544559wrm.2 for ; Wed, 28 Dec 2022 10:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E/ZkY45OBd/IOUP/wYq7DxZvgchC9mFdrpb06aLiOI4=; b=cTnQQ7UK42Uj6KKnWHlbJle5sEsiP8JMSrZCNaCB01TwLQXz1zGffLFcfYbcVKud6m T4l4BaN3XkELKHhmWbIRXBSHBRandSEercuLAmi8QZZfWaYTcleb5x5ohaGG/0mqkx5w Dta5UnsfK+NxeUZWTANacx+VDQmkrkUfpTpS/vgVK5Xa9a3O0olinrLkWITQ408NCkAJ yLAnXaWf5b6ZiQJ1KKyOQLRiIFH/tF5rnIyqzlyYjfgUrI4IXS8M7pp5TbcVhXFojwmA +UNidcqEPhu2JZDAus/D41xKPzKK9lFs78X+2YR2Ao0EFQIXUMPjMJ0XhBRFUsb8LLGj pASw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E/ZkY45OBd/IOUP/wYq7DxZvgchC9mFdrpb06aLiOI4=; b=tWhEeYx94h8diV5W86ZKCMf7FCeJO/0XFNIT5e937L6WpuDFJzEkO3BVVrxyHE7zDp P2sWhNjt6MjlpmOcCWygEaUJxAPYvfQHn71Z9yTgnCgVkRu8ry3IwwGZAfEeK/eiGfWe Zud10bVz5aoTkcq1HfQAh0Rb6zEaFarHL83ll6gLtm84Kmu2mAXA6q2LqHUXr4QRCITV 7wuVBlQnm+6uxMUL/Q1RWqsYcPv75XGAc6djABxJYNVjuYHfZ6XVyNsxbl0ppbSZ9YmT seb7ZIxMw0121yDmNJm6OR7ukAuZeHPlb5wsM+c0ajgq2BeotXkQxbvHHSTw/JggKcoe sjYA== X-Gm-Message-State: AFqh2kr80JSfSYuLceY2C5ws3iwNaypiVMuro5X7BMJT2GB/hDV/aBpN sYJZbJ9XoC+FXisQ3BE56T9U7FqR+NQCNQ== X-Google-Smtp-Source: AMrXdXtR1tSdvRLFj+ROtBvKKgJyaxselYccsJYSodfq7x2nyHpqUCOTlx1yD1P4kGtXOudsQ3p6pA== X-Received: by 2002:adf:eb4f:0:b0:242:659c:dc7 with SMTP id u15-20020adfeb4f000000b00242659c0dc7mr15067334wrn.61.1672250444391; Wed, 28 Dec 2022 10:00:44 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:43 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 19/20] grep.c: make it easier to extend free_grep_patterns() Date: Wed, 28 Dec 2022 19:00:19 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Before db84376f981 (grep.c: remove "extended" in favor of "pattern_expression", fix segfault, 2022-10-11) the pattern here was: if (!x) return; free(y); But after the cleanup in db84376f981 (which was a narrow segfault fix, and thus avoided refactoring this) we ended up with: if (!x) return; free(x); Let's instead do: if (x) free(x); This doesn't matter for now, but makes the free_grep_patterns() easier to reason about, as we don't have to wonder why we're doing an early "return" if and when we add free()-ing of any members that come after "pattern_expression" in the "struct grep_opt". Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/grep.c b/grep.c index 06eed694936..ca75514f8f6 100644 --- a/grep.c +++ b/grep.c @@ -791,9 +791,8 @@ void free_grep_patterns(struct grep_opt *opt) free(p); } - if (!opt->pattern_expression) - return; - free_pattern_expr(opt->pattern_expression); + if (opt->pattern_expression) + free_pattern_expr(opt->pattern_expression); } static const char *end_of_line(const char *cp, unsigned long *left) From patchwork Wed Dec 28 18:00:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13083111 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 C9C57C3DA7A for ; Wed, 28 Dec 2022 18:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235220AbiL1SBy (ORCPT ); Wed, 28 Dec 2022 13:01:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233783AbiL1SA4 (ORCPT ); Wed, 28 Dec 2022 13:00:56 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20984E0D for ; Wed, 28 Dec 2022 10:00:47 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id ay2-20020a05600c1e0200b003d22e3e796dso11786817wmb.0 for ; Wed, 28 Dec 2022 10:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vxc1r2VMMf1AcPqEB+7kqDSs6wiBRkSxcD1PYJY90Zk=; b=JNp9MXZ6C+rJkve5pAHvlmIeUbxndEmnHaRulSs5m18Gj32QVXpUcW/vIebOGr9JH7 tUi7klJ+vNxfhbRXQD6Ln6Q7sLmYCBOWxBDytkXjwf5bYphgGLfCYiVCHU1zco3ziiSC nHgkyMtqY90LD2/qZl2EfahJX3Hs8STafNbXUAx/wNUAUJDQmOeH0vb0N9MXEgqNMCod bPQ5cqfkJ5+Iy6biPy0x8EP+g6woF7X67jMj4BCjEbgbuQA/FJKTaNE4ahxS69rBnMYd +RNTMwlBtpXpSjn5UiWYP/e8vRsgyqcT//7hEsyRPfhq+jGR/qB1L5/8zjerbkA2n7dt mPTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vxc1r2VMMf1AcPqEB+7kqDSs6wiBRkSxcD1PYJY90Zk=; b=m8So+XzwuyiSkd4LWGnAxbSwXp81DUq2FjPxdMNcRSvBMO5kv9x4fGg/3yXawkxcci ucQk3Ng01cWtVuLYCaq07jzdixA2MYULYytb85acXNOzpCngP/RxtdcuzleAg85P971/ 75AUQX2H7BJ8w8bkAMuGBHOm6TOwEHGhBHao5IBSO8ZKEP+OtQb62iPKI/IYpO8A+USE otg7fLzWnYeLqzeWCv/wtbzWRW6vfq7wfVVd6MCJb/u/CjAgH5tm1tglQ1R2uakB8XYN izwXekq7vPV1Bqf+0jVWepCpMz2aaZmkGclqmf0r9l4EqMJJhYFKJyphO2XBpXXIeVf+ zfig== X-Gm-Message-State: AFqh2kq1FbNTptFNQ6L6RPzH6Yxfkg7jtQLbOaGHXkUIJdHqZpp3QFJm MZSdSMJ8O0NyFlwRcfAuVbNN1eu2+nxDRw== X-Google-Smtp-Source: AMrXdXvQkFACPYor25PXmA/4DVKI/czDfpnXZFNQySZE2m3fELUeYPoEj2FyNkytuqEJy8lp8ZlUNw== X-Received: by 2002:a05:600c:601e:b0:3c6:e61e:ae71 with SMTP id az30-20020a05600c601e00b003c6e61eae71mr23439436wmb.1.1672250445313; Wed, 28 Dec 2022 10:00:45 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002428c4fb16asm16022480wrq.10.2022.12.28.10.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 10:00:44 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 20/20] grep API: plug memory leaks by freeing "header_list" Date: Wed, 28 Dec 2022 19:00:20 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.gb0033028ca9 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the "header_list" struct member was added in [1] it wasn't made to free the list using loop added for the adjacent "pattern_list" member, see [2] for when we started freeing it. Let's start doing o by splitting up the loop in free_grep_patterns() into a utility function. This makes e.g. this command leak-free when run on git.git: ./git -P log -1 --color=always --author=A origin/master 1. 80235ba79ef ("log --author=me --grep=it" should find intersection, not union, 2010-01-17) 2. b48fb5b6a95 (grep: free expressions and patterns when done., 2006-09-27) Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/grep.c b/grep.c index ca75514f8f6..c908535e0d8 100644 --- a/grep.c +++ b/grep.c @@ -769,11 +769,11 @@ static void free_pattern_expr(struct grep_expr *x) free(x); } -void free_grep_patterns(struct grep_opt *opt) +static void free_grep_pat(struct grep_pat *pattern) { struct grep_pat *p, *n; - for (p = opt->pattern_list; p; p = n) { + for (p = pattern; p; p = n) { n = p->next; switch (p->token) { case GREP_PATTERN: /* atom */ @@ -790,6 +790,12 @@ void free_grep_patterns(struct grep_opt *opt) } free(p); } +} + +void free_grep_patterns(struct grep_opt *opt) +{ + free_grep_pat(opt->pattern_list); + free_grep_pat(opt->header_list); if (opt->pattern_expression) free_pattern_expr(opt->pattern_expression);