From patchwork Tue Jan 10 05:43:21 2023 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: 13094676 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 CC03FC46467 for ; Tue, 10 Jan 2023 05:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbjAJFoF (ORCPT ); Tue, 10 Jan 2023 00:44:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbjAJFn4 (ORCPT ); Tue, 10 Jan 2023 00:43:56 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E5C641030 for ; Mon, 9 Jan 2023 21:43:53 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id fy8so25712994ejc.13 for ; Mon, 09 Jan 2023 21:43:53 -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=eUFNrE5ScwRZvZyjH826mqXEiUIPSBGT0JzARFu1/xU=; b=GG0HTMrRc39a39GzR8eCKnjOCp9Kmh1ZdMMx+znMUqv9jJH2Kiw6sxBKdk1TRMTyhK +D1djbV1gIak7ev+guGmZSgjmt1L2o792TeFuNm6/bQ8s9RnRO/+AGFYYkR1VAvOOXrp JwZjvgGgRL6oTw77RVq2nMz17rD55JpXcT3ovHbQS57DQhSRKhyVhuvzzUImCs+FCRLB aC11Z9i6JuYEup7nXS770z9U1MbK3ztEEB3OAVPo5Zvs8n3kMgP1QNL9P9LImj467occ Aks0Am7EYRcDrFzvaygaXwH+jhxr0p/h0Cg8lQSOMQiqFl+peFAmI4+UbZ6gi0u3xpj8 fVVg== 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=eUFNrE5ScwRZvZyjH826mqXEiUIPSBGT0JzARFu1/xU=; b=ZAoLzm5ysiWpZs/zThIPtt5SUJArQBLVRhcxbHQStIIewIe2pqOoOGSHWq7HfbcKZ2 zu8owiAt1UI1imaTl2r+qLU+1xPVSIgEnkZq+uWGflavFwrzBiUbnLAvVGHQF53MUhz4 Bkblsda8iQAiBt9wBK4NNSxWjhSFEhdOBpWKYBZM15ObVhAt4MGHXLsqwJJ6gms6I7M/ jw1EZs+v99UxmadURw2DbATG3uiiOT3iDz7+rNsNC6bfQyNEHvh+tzQh9nrzcDKORLiu yolhvW9Z/9bgYqvFaD5dbQ5O1sZipgSdemGFAKKk0p6q87elCFpaRgudXAHinVmvlc/d SElA== X-Gm-Message-State: AFqh2kr0kFFDA2mULC8CibHJ5EsTOqroRcTevqMKAbXZ/NyearXK6EKT j40AJsOTdLRqIyKSucQILvaM9O6xsTE= X-Google-Smtp-Source: AMrXdXtlwjTPPECdn51xQNlRR/m1A1Ej2n1CpTLQ0ttWmPTy2JDLnUhAY2GnYLR3Dx9vw4UvLwBbng== X-Received: by 2002:a17:907:b686:b0:7c1:7c3a:ffba with SMTP id vm6-20020a170907b68600b007c17c3affbamr63209222ejc.35.1673329431438; Mon, 09 Jan 2023 21:43:51 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:50 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 01/19] tests: mark tests as passing with SANITIZE=leak Date: Tue, 10 Jan 2023 06:43:21 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 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/t6021-rev-list-exclude-hidden.sh | 1 + t/t7403-submodule-sync.sh | 1 + t/t7701-repack-unpack-unreachable.sh | 1 + 21 files changed, 25 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 7cf80bf66a6..70389fa2ebb 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/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' ' 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 Tue Jan 10 05:43:22 2023 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: 13094677 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 0CBFBC46467 for ; Tue, 10 Jan 2023 05:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbjAJFoI (ORCPT ); Tue, 10 Jan 2023 00:44:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjAJFn6 (ORCPT ); Tue, 10 Jan 2023 00:43:58 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28CA64086E for ; Mon, 9 Jan 2023 21:43:54 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id fc4so25754120ejc.12 for ; Mon, 09 Jan 2023 21:43:54 -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=qhpPSlZRt+9Dk9IbtAhfUAJEh5ZEsKE012pUm8RaR+4=; b=hCmEgwZvWdWJ/quSxgYECFHVmdnYQ99167AOvWV5Uvvn1w6nWye44JCzn6A0Tn5V5v mCW4isq+UMlmzNA5TQn+csKcQkU1s0tbBtIKurZGRetCkP7Gdvc1W+OhckiAM1XaeeCo /Nj6V75DtXLw6LPeEoexXrBksgOe7X2r+HMxhlxDGxyNGrRGdlGkM7DVt48eAMw8vL0+ ZHFWk3K6/FG/FhbEG1YdZLlK919ZDmPG3ZQHUh2AWNtrqH4GraZAgQI9mQ8gu+/j4Ok5 2eQp0qEGuvgsPdRttZWf6JgaP6bOaWpN55WPjDd7mxbNuFDg9tXoodTr/yduRmbWPykX lKJw== 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=qhpPSlZRt+9Dk9IbtAhfUAJEh5ZEsKE012pUm8RaR+4=; b=8LdkyMD90rCHq1CeIwen5Z3iLUZbW9KhzQ1YyDrzW5KrZl9wHjcRvm6Prwrg6n2aUd 8e5POlkwF2pdHMUIDzK30p8acg1doj6w+NPQDsRE5aDMWAsbPJrBNZBPD5f2UrPTtvcc smGItPxiFcnvzqhy3NSFykA+O46qjXNYBb1NWNhZwpT2sOG8jWPOv9SsQ0d0fW+5HgYK qNQZIaPu/l2Jpp3t2LmshVOkh3yS6pC9pv7n6l6vKddAYP+eSEtG7E7haITHQvUBY/0n KOE7IHrcy8hf9KX0q22+/Gx6IKIilVNlgGYEMlXu4LR8rC6p0L3TXejYYXIf9sTl66lJ s2cw== X-Gm-Message-State: AFqh2koSmnbWrWr9Vecz7Ky68VPnjQQOnzTnhK16dfb0kzIb0l4Rx1em 2lzbKW6cE5zxiahUewKa360ZNC0ALNhgGg== X-Google-Smtp-Source: AMrXdXsZNeQivxAHtnp4dj6QOmmHlS2y+djDWlXP8cnVNzkMTq0m/RW7jEeCon2Y4l4BTlGpxBAQ6A== X-Received: by 2002:a17:906:6d47:b0:7c0:c312:acaa with SMTP id a7-20020a1709066d4700b007c0c312acaamr55552133ejt.49.1673329432351; Mon, 09 Jan 2023 21:43:52 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:51 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 02/19] bundle.c: don't leak the "args" in the "struct child_process" Date: Tue, 10 Jan 2023 06:43:22 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 Tue Jan 10 05:43:23 2023 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: 13094678 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 D038AC54EBE for ; Tue, 10 Jan 2023 05:44:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbjAJFoR (ORCPT ); Tue, 10 Jan 2023 00:44:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjAJFoA (ORCPT ); Tue, 10 Jan 2023 00:44:00 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0174101A for ; Mon, 9 Jan 2023 21:43:55 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id fy8so25713098ejc.13 for ; Mon, 09 Jan 2023 21:43:54 -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=orc6TrvkTPrWftmX63U4k1quqb1g2tUq7Rkvv4qxuWk=; b=Kz24v13749qaMTa5D6FAFLMcbvDw7dyXtV9VSEqcsauHDg+Fi5goQBhZLjV2f6RxCx /disbL1vNze6NkdkJEBENL3IOr+7sZAnGpCjN3umkDlTR2XQsc4o+wBe2CjPvfLcByoy SRjt3CxomQZD+tMKWX8SEOpvIPKy9PJyxt+btUZsCEcHhTjncMTq5ujnjebm34yQ/Jc7 OM3fEnMIixhT228BSjemYnKbpvN9BOcDDFW41hfHtnkN64X9VzPBPL6zUcJcF0mh7w0x VFwcuxw6OJufDDrO/6sRLhR1nN4ujRSg+bf+sSI3VraJdPWHZvW91jsSthd3iqVJENkY 56AA== 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=orc6TrvkTPrWftmX63U4k1quqb1g2tUq7Rkvv4qxuWk=; b=yPMqcIoUyuFFo8r+az9UR7BMTUdao5zokfCxItHsZHgx2dn/S9SOwJVjCc9IKZn69w zHNJ5G3LB8JALVCotCM8BAiAub6WGBGYJmoa9GucQViAM6AjTbu+wQ21+w9bKKH6XG6Q 2kKiz4ALyP4eDKGre7jyTDNDad261Xc6LRkaBdfbrSRvmqAiGb1KcFirmuH2TNlfxpTJ PWnpzOI/cCWhamq6DOgWdXuppBy8U/3Bd9WmIaAdC3gDR60Dcs09Km2hkNql820BCqDu KYyJpuSXEN8NI+DnyGonUj205ECM54oIhr5qxE1Ts0gCbzjJhH0uZ49ACOTjUNYoKOv7 Hw8Q== X-Gm-Message-State: AFqh2kqkwNt46lYk4U1bmiBscaJuZN9SDavrGhHZy/aSTdZIGm7JuEM+ TEasPE8nHHyrpV2mRk4hSIFRZ4rogv2Bmg== X-Google-Smtp-Source: AMrXdXv4NCVhORSaFVFTDLxPG8FhumiOtwVvTOPuyKIF2etJBDNI+sVhfpPmWP/9HjRhBXnsH6x4MA== X-Received: by 2002:a17:907:8c82:b0:7c0:f7b2:b19a with SMTP id td2-20020a1709078c8200b007c0f7b2b19amr62610196ejc.27.1673329433308; Mon, 09 Jan 2023 21:43:53 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:52 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 03/19] commit-graph: use free_commit_graph() instead of UNLEAK() Date: Tue, 10 Jan 2023 06:43:23 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 invoke the free_commit_graph() function added in c3756d5b7fc (commit-graph: add free_commit_graph, 2018-07-11) 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..0102ac8540e 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_commit_graph(graph); + return ret; } extern int read_replace_refs; From patchwork Tue Jan 10 05:43:24 2023 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: 13094679 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 98205C54EBE for ; Tue, 10 Jan 2023 05:44:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjAJFoe (ORCPT ); Tue, 10 Jan 2023 00:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjAJFoC (ORCPT ); Tue, 10 Jan 2023 00:44:02 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 840B141A74 for ; Mon, 9 Jan 2023 21:43:55 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id u19so25731686ejm.8 for ; Mon, 09 Jan 2023 21:43:55 -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=YKhtK2c5/tdNHpixWjcaMzOzyk29rV3lIHqroZpbqOw=; b=FFHUPbvWfkGmE3tQ3Dyf1DMSTAJEl1K0TANZ1zDcPeNe0qD6PQGz+vbyFDeaYBj0uB 4cikkX7jimHUxT13Ga4Pxh7IRBgPVEiqlVcBFuWiytm6m2ya3XkNerIa+fYrtrs0bA7H WYCoZIYnp2lqFLKvJc38f5VVIOMRo450v7Q/6Pk5DzEn3dxl6UmkNg3ne+iujQ7FfPkP /eZXb8G1t1Z2vdKQDnRtF/scPjPiWXdB6vCpfGkVOeIKgjOOObjMq/0/9rTGM3392ObY RDR2DfhayXPeu4ldmz43IdGDyx4S8WAunsUwkv6sjMACglCbQWWTq18NFUSVQorUSi/0 lang== 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=YKhtK2c5/tdNHpixWjcaMzOzyk29rV3lIHqroZpbqOw=; b=dG6utfGHmVbJuigGZGGNIl9Uz1Dv5ja+r7gqx4Pv9Ss7yDKmwSisoxB6XmAlOQ5I4x 9B92ANNHN3pIdv8Q3CgPTbyCkkBlszrcSQHoRMfMvYOQz6CK9BQbkAvU7eWTtwfsHdaf mfAQvT6lZT0YtKDfJiPjcgQjpCXuFvdghqQLBDpHszB7ZY255h6Md0JoewOlQrfD7YDH +xdtxKK4efNMNidP6m4SWtVmEDFXGN0biqk4odIsiLiifKwDZogbBJ/moCTcyFs6viu9 T6kmhOO4IeCosk5kPGckE99/yq5Dy645OIVdXMuPhuab4hkM+ZsrYEpuEnUU/XatPMFJ g1Uw== X-Gm-Message-State: AFqh2koVji3a0uauCNi92QX8oqz28ING3yA+Xg/NeVdNeYrP0kE4Vv9a Hl73/0uy8GWBtiQiA67KYz1UCcY5f+9iCQ== X-Google-Smtp-Source: AMrXdXsmUSQieiRljBjEiSRCtjcuxV5WneRcncBpq1GAyZc9sIYRseALLDzaMn8DpyJNGp7mY4OaRQ== X-Received: by 2002:a17:906:af17:b0:854:6b5f:4ffc with SMTP id lx23-20020a170906af1700b008546b5f4ffcmr1751360ejb.70.1673329434203; Mon, 09 Jan 2023 21:43:54 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:53 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 04/19] clone: use free() instead of UNLEAK() Date: Tue, 10 Jan 2023 06:43:24 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 5453ba5277f..ba82f5e4108 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); @@ -1413,7 +1414,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 Tue Jan 10 05:43:25 2023 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: 13094681 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 59B62C46467 for ; Tue, 10 Jan 2023 05:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230155AbjAJFol (ORCPT ); Tue, 10 Jan 2023 00:44:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbjAJFoD (ORCPT ); Tue, 10 Jan 2023 00:44:03 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECEE041D40 for ; Mon, 9 Jan 2023 21:43:56 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id u19so25731752ejm.8 for ; Mon, 09 Jan 2023 21:43:56 -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=tvQ6WpJDUzgpb47v0LLAcL+mHGZDORGvF1mh1AQ8C7E=; b=luiMQJXoSXy54SftmwOx0qw6t8bph1ekSvY2YCcLgjEAVZoY0h6Vdw9y/hdxImaHil iKkMVVpqavHQYD7fl6L/zEjDev3fiRTuE25NgeE6LN3PJAhYIMcsIbNtgEZUawC4F7YH r3Ts42lZvPlgGKlbcZ6j4I+uKt0DXqQhwQwtHHA957U5DkZrBe3cnce5+PqH7BRZIsr2 M/GIxpBWmxC/CVReAuXJ4gFQjsHsEQwUFHWLPNrFHqezsY80b5iHn80ZQHt0ajpRM+xw wJ7V/zuv/v3+vMssyPwpnFgM8yYRTEX7xG+zF9p3dwoDRIq+VQmC1J+KYbWssD5SfNwe b9RQ== 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=tvQ6WpJDUzgpb47v0LLAcL+mHGZDORGvF1mh1AQ8C7E=; b=7JwhMk9MxFfKNN192OtH9iNKVKbjGqtxqJq6k2lL1hylLoeyzeWw2Z/rlyJIRHb9IJ 06bT/g7xMUU1kFkDALo68avts55FzlYroadN32IutMN8DV/w6FEgOhbkdwiyM9SKJMWn YbPIqvoQN9rc1GnjmrseEmC3XApYdBvJOVWqfKt4g1zTqCEUOb0QxOJgmEIqLx8xf2sa MDt+6iI10aSSe2QM2Mqi/y5HftqiumCPHd2luLYrPTHz2HBeEir5qz+udNpUDaX+okT8 xQpW5jZnNNXSD/aaQjicuPckOq/eaKRmTDW7XaiApq4r0O6a9GFBgNmSae5FylvSveE5 Wz4g== X-Gm-Message-State: AFqh2kobAnJvBYkKnYrigFdeZACZx9EZtHu4gCyauAREMHqbUlexyMAr RA904Qp/0Psd4s85AAShHstj+3CCD3lW+A== X-Google-Smtp-Source: AMrXdXu/Q/G8B0PLCbC7JMDrx3cA5cLhTQAGi70ZlPhKDuCaxtXjUBHlcK3TFHCcm5GRQbAbieeY3g== X-Received: by 2002:a17:907:6d12:b0:7c1:79f5:9545 with SMTP id sa18-20020a1709076d1200b007c179f59545mr81688941ejc.42.1673329435074; Mon, 09 Jan 2023 21:43:55 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:54 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 05/19] various: add missing clear_pathspec(), fix leaks Date: Tue, 10 Jan 2023 06:43:25 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix memory leaks resulting from a missing clear_pathspec(). - archive.c: Plug a leak in the "struct archiver_args", and clear_pathspec() the "pathspec" member that the "parse_pathspec_arg()" call in this function populates. - builtin/clean.c: Fix a memory leak that's been with us since 893d839970c (clean: convert to use parse_pathspec, 2013-07-14). - builtin/reset.c: Add clear_pathspec() calls to cmd_reset(), including to the codepaths where we'd return early. - builtin/stash.c: Call clear_pathspec() on the pathspec initialized in push_stash(). Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 1 + builtin/clean.c | 1 + builtin/reset.c | 11 ++++++++--- builtin/stash.c | 7 +++++-- t/t5001-archive-attr.sh | 1 + t/t5004-archive-corner-cases.sh | 2 ++ t/t7105-reset-patch.sh | 2 ++ t/t7106-reset-unborn-branch.sh | 2 ++ t/t7107-reset-pathspec-file.sh | 1 + t/t7301-clean-interactive.sh | 1 + 10 files changed, 24 insertions(+), 5 deletions(-) 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/builtin/clean.c b/builtin/clean.c index b2701a28158..b15eab328b7 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -1092,5 +1092,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) strbuf_release(&buf); string_list_clear(&del_list, 0); string_list_clear(&exclude_list, 0); + clear_pathspec(&pathspec); return (errors != 0); } 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/builtin/stash.c b/builtin/stash.c index bb0fd861434..45bffdf54bb 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -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) 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 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 diff --git a/t/t7301-clean-interactive.sh b/t/t7301-clean-interactive.sh index a07e8b86de2..d82a3210a1d 100755 --- a/t/t7301-clean-interactive.sh +++ b/t/t7301-clean-interactive.sh @@ -2,6 +2,7 @@ test_description='git clean -i basic tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh From patchwork Tue Jan 10 05:43:26 2023 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: 13094680 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 47512C54EBE for ; Tue, 10 Jan 2023 05:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjAJFoh (ORCPT ); Tue, 10 Jan 2023 00:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbjAJFoD (ORCPT ); Tue, 10 Jan 2023 00:44:03 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE5741A7E for ; Mon, 9 Jan 2023 21:43:56 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id vm8so25800597ejc.2 for ; Mon, 09 Jan 2023 21:43:56 -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=NVHliO8MG7jMVOnByGlLXXS7QdQ0h2zR1hZePGUNKoU=; b=YYNV8SnnVgLEyRuKOPiOYk2y+n3vxmha3pRI21q7ykUMWQO2uZoVCM275xMW34u70D iqE/hVmBgCLi81Kbv20u37xy1gpUTth57NlF4Ki0UKyxKVfdLuAeLUNBFqgg+C9PEtx4 bjG7XidZQnOj7CB+Kr72Inktp0Wwoi8WAB6Y40JEeLxSoHzPmgPLBnIVeml2kTfwklPA Oaz4tHyyQkdxWgQdfAW6aqWdSqUMPPTSd6XKpN+8hsMfT6S7uAqfvXI4ovZtZQ6HRNY0 ZUeoSEw0elIDJ5ZbnQvz5emjqRr7dAHmr33tLSm59/unLk6F/866+uYYDKb8pyEOewcI dV0A== 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=NVHliO8MG7jMVOnByGlLXXS7QdQ0h2zR1hZePGUNKoU=; b=b3dJI27RXoB83UUZoh5rxlPQ8tkx5VSW/cNJ6N/i4tjkquPqQKRMUglwXj6CXB8K+d M+FR1SgtnsxeaceA0KdSTC1VnQzLCjlUUVtbT9uMNZYbfimZRpeAT9WVaM+Xev7AAyiN zWTZrnpMaxEEOmR7OcIc99ljQf/o+bco+lA7fRJ7juPBh5YpHyFZxF2r31PppTN16wUQ GkuWP7ah+O+LDSVIxrk7s1KZJ3F/Oob3EJcRnSm7pcVge4UD8FMNq+3oyrlWBuDypiD2 GQ6AqqFcuULxvlF7CCj4IkX2wq+kghzQZmOtpTXZ1nHQP/BJ3qW5XabYjiyTEWZQ/Wjq AdUA== X-Gm-Message-State: AFqh2krcKTb6Gg1S+yhjpK1y5Rgr5VKaeFE6i/Vs6/kr8c455YGIq8Ol 5OqRdWYxCmpNmMSqOoOa8B/ijXT3tptU7A== X-Google-Smtp-Source: AMrXdXuQcggWLStDygeq0nLj+9+LfUd9jYOZp+2p51SKsMy6W3vYXzBlbGQDQDtfW6vwM74BsUoFEw== X-Received: by 2002:a17:906:b150:b0:7c1:2931:2263 with SMTP id bt16-20020a170906b15000b007c129312263mr60655533ejb.71.1673329436020; Mon, 09 Jan 2023 21:43:56 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:55 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 06/19] name-rev: don't xstrdup() an already dup'd string Date: Tue, 10 Jan 2023 06:43:26 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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. We could xstrdup() only if "shorten_unambiguous" wasn't true, but let's instead inline this code, so that information on whether we need to xstrdup() is contained within add_to_tip_table(). 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 | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 15535e914a6..49fae523694 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -273,17 +273,6 @@ static int subpath_matches(const char *path, const char *filter) return -1; } -static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous) -{ - if (shorten_unambiguous) - refname = shorten_unambiguous_ref(refname, 0); - else if (skip_prefix(refname, "refs/heads/", &refname)) - ; /* refname already advanced */ - else - skip_prefix(refname, "refs/", &refname); - return refname; -} - struct name_ref_data { int tags_only; int name_only; @@ -309,11 +298,19 @@ static void add_to_tip_table(const struct object_id *oid, const char *refname, int shorten_unambiguous, struct commit *commit, timestamp_t taggerdate, int from_tag, int deref) { - refname = name_ref_abbrev(refname, shorten_unambiguous); + char *short_refname = NULL; + + if (shorten_unambiguous) + short_refname = shorten_unambiguous_ref(refname, 0); + else if (skip_prefix(refname, "refs/heads/", &refname)) + ; /* refname already advanced */ + else + skip_prefix(refname, "refs/", &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 = short_refname ? + short_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 Tue Jan 10 05:43:27 2023 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: 13094684 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 340FCC54EBE for ; Tue, 10 Jan 2023 05:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbjAJFov (ORCPT ); Tue, 10 Jan 2023 00:44:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbjAJFoI (ORCPT ); Tue, 10 Jan 2023 00:44:08 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A448040C2F for ; Mon, 9 Jan 2023 21:43:58 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id vm8so25800654ejc.2 for ; Mon, 09 Jan 2023 21:43:58 -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=8L2pFFIcDxNN1bhvWkYi9ywET2ix7HgymzThUUquK98=; b=AgkbzJb+FbiCvW4/CfJ9+W1qi5SWxVrEMSH2QZ1xeVsTc4xUkSd/OqARLbc38GPLBR JIJD4W3jXCFJXIy65PfbbQd7MFF4XABDHCTUY5m7856mnYLbLZSiz5cLh5zkR8OXD36u irrHwI9ImccI5N6FtXY0zz8GDOxzjil1waZq3g+2VFZJbpjG/29wUIJHinFrrazmrMaW 8hJb7F1wD04RICtK5BnUC19oQ4DnKaV1X0Jo990iltJCAx4pSMMco0FG19+HuVwpI58C awHMJ9CSb0O633V9A2D8EBhkqncnA2YTcmuYwxtSDyC5Vy31Cdxv2/ZjYlKUS95nmjOF DLdQ== 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=8L2pFFIcDxNN1bhvWkYi9ywET2ix7HgymzThUUquK98=; b=6K58YG6l506k/O04sJkTi29m8IIFUz5grU0guUjPnFSRPxw/0XPktpx74QeTWmXjA4 Y/YfWW2qOtFKvpaSyrN6jLZ/00uJwi7okfzaHALL4IW4opCPRV04E9PLOBKx49bFr6pI B8BioAygH2P15Ubt7mKQoeoisfcI6dv5NljqmpFtHC9NEHgDvkaM8xyWamuuCUnaxRW6 TrSngbbA8PxbAUeVnqd3Qs4t9opjwsITKf6gduX8NIm0DnLHnq+1/G0U0WR2i4zOaxHy zYAvzWxbcwJvouMbMnbkpm8SxypDFCJeuFjZ4bySLKSliyqzIIcXEz7w8nYsOE7bjn0L h7+A== X-Gm-Message-State: AFqh2krn+GcAB053XZSOKxx7DjAwprIoxi30dEFz5szP3rMvWERcbj4J c0TDmWstePOmHxf0Y4Qgtwaz3RO73Z5L/g== X-Google-Smtp-Source: AMrXdXtJ6AwJV1Dy5XNWQUNIbGv0U9KZTgPsYuXDr4jDsqQB7knffIdm71CXWW8P1N8QkV+7qRksuA== X-Received: by 2002:a17:906:3ac3:b0:844:1d1d:f7 with SMTP id z3-20020a1709063ac300b008441d1d00f7mr50685053ejd.23.1673329436914; Mon, 09 Jan 2023 21:43:56 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:56 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 07/19] repack: fix leaks on error with "goto cleanup" Date: Tue, 10 Jan 2023 06:43:27 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 Tue Jan 10 05:43:28 2023 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: 13094682 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 B10A7C46467 for ; Tue, 10 Jan 2023 05:44:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjAJFoo (ORCPT ); Tue, 10 Jan 2023 00:44:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbjAJFoF (ORCPT ); Tue, 10 Jan 2023 00:44:05 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7CBF3FCB5 for ; Mon, 9 Jan 2023 21:43:59 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id az20so6730404ejc.1 for ; Mon, 09 Jan 2023 21:43:59 -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=NTNEy6c6gVSbz//QMG6vUd8BR9QP0SM5R4gXZslEWrI=; b=R6m205YgDQxzsTbOomjFRV/iDQVOLcrk14owKRMhOBTHdf3GCv1pN6wYLNPslS59Rh IaGZTcNhD+AsStBxYv/AtZmw7lypzabvHSDWo/XJBJOKVZ3lbcCDFfei4XjIwdYVjxOH uMG8TSVATawfwz5E1ceWOtvnr6gdTW4w7OebK0Hfg3Zb2c42tXrRSWqLnqQ1LmSmk81W PImA3mI35U4R/v1f9EJ4Yab3atydyB2uni1jIbozR4BQ98DOjLzyElDfQv6sGoWHdo2I 7gbhqym8+Ya8QRflTrgwIl888TaXtaTGvbVXo/wMbB2KM1uccENerGBf+d2aps4tVOUj BC5Q== 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=NTNEy6c6gVSbz//QMG6vUd8BR9QP0SM5R4gXZslEWrI=; b=h2FhNiROmQx2zLq5MPZfXEgNnB3UHmroYIqpoVe32N8mf7MGXInidIeDAn5XEmT/0V GmpgAqXSDbDQAHBok1AxZikXw57CxRHiDN9ulC+Lu65n07gkLOMCzrnX/OTggs2a9p2G SKYwhEMQYUMZCYCvuK1zJt2huBX5OD6YbS4BTmx7aiOuv3DlYrqbYHUESdG+enNbJeA2 PzDGkqyCnsZFjeOvWgdbekUIQZhesEI88IYfJuibqJIsyvKvXxfuYa5lWy15rmIal8jS 4uUsszqJuUTFCB9HA9EWfGyUrgM/cmUqelSBXFwWsRkkCi6QtwnygnyKVSpJO1dfKBDm 0oDw== X-Gm-Message-State: AFqh2kp4s9Nvsv2gbm8wi/XPHxLj8mhpMgLneMft45LEGK6ikPNjGpP6 UDuFk5JwXbPJa8Sa/YvpiP89ET+aLUe9Ig== X-Google-Smtp-Source: AMrXdXsKXPHaVguecew1Z/Abv43KyZNirLNpIMoernErXZVP83CtvK7ig0LrPw812NgB6VEw1DvEJA== X-Received: by 2002:a17:907:c301:b0:7fd:ecee:c8ba with SMTP id tl1-20020a170907c30100b007fdeceec8bamr85603385ejc.42.1673329437843; Mon, 09 Jan 2023 21:43:57 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:57 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 08/19] worktree: fix a trivial leak in prune_worktrees() Date: Tue, 10 Jan 2023 06:43:28 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 Tue Jan 10 05:43:29 2023 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: 13094683 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 012A3C46467 for ; Tue, 10 Jan 2023 05:44:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbjAJFor (ORCPT ); Tue, 10 Jan 2023 00:44:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbjAJFoG (ORCPT ); Tue, 10 Jan 2023 00:44:06 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822C441A60 for ; Mon, 9 Jan 2023 21:44:00 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id vm8so25800789ejc.2 for ; Mon, 09 Jan 2023 21:44:00 -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=K+yNTeOcfOqu3TBJBLGoZmsttx8g2gxlzpL4rYp8WM8=; b=gl/MVB0Fx16dfa1oCCpZZzEURk6cK/ygj3CXxwU0bNZcgxVUOwXuUurDGFKOe8A74r 7QLT4w2h8lZgX5pfX6LoF58RxVJXX/hZZw5G6ePXdNa4XYlIMVUJSEWJNG0J+NeYZ+7F 97lLy3QynI3IbJ3p4Dtc6+v+gVv3jTRL97Rn2TJWXwL/zwU0B/0UgmQvm6eJp7+94vPA J8vVaBNZXchLw56HHXXd6QxKERp+88BgUD23ubPyHJcHoO7SxVHMLEEm9oCctnh6HIrR ik9MByfIpKIY/1u5TZOsE/CMarXmjhGc7NaLJx3MQLTkInbqqmFJfVgBejHE9LxI91c7 V+3w== 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=K+yNTeOcfOqu3TBJBLGoZmsttx8g2gxlzpL4rYp8WM8=; b=CTIqh9aGqlGJYR0/lrzruWG7ec5s0XudQQh5vJaziCEJjpUt28NWvZLOGvJljXelIC HBjHfUCCF2ekLSQMwg4X9f5vEB27yPJlu1ahfRAlc1uwXO2MFfV/4ckHAYMhildBnEB4 k0rq0JTtfLpI3bvQsgSJBq3vYkl9LgiWWsNQs4VVvs+9EGAfz/+LxY9gv5Ffl6wdFh27 nlnCQDfPfgvJCZWwkMdjwdERUMUl9y5KJ+UZT+fBvmy1gOe601V67WB/I+6oqDhszlfC dXNMjvdI7g6ThEhG8zpLkVqM4A4FdgSmzhTdimIKRy+QqmdOtezsI3TX29xW9iDsI5rP KkoQ== X-Gm-Message-State: AFqh2kq4nSn8uq/LS3uRqUIpe4YkeEspXnHvZBTotrQbQ2Q8SoqbBC/P TGCKBrHV4e0+S152hCkPS5/aSH7Onn9RKg== X-Google-Smtp-Source: AMrXdXs53bKlWpHvHpZ79O84SMYy0IS5NrX1URWrfaYJFN2GS3NfU6Q9lQoK7vAI6QYNUBshl/hJHw== X-Received: by 2002:a17:907:6d85:b0:83f:748a:5c6e with SMTP id sb5-20020a1709076d8500b0083f748a5c6emr94008107ejc.71.1673329438806; Mon, 09 Jan 2023 21:43:58 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:58 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 09/19] http-backend.c: fix "dir" and "cmd_arg" leaks in cmd_main() Date: Tue, 10 Jan 2023 06:43:29 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Free the "dir" variable after we're done with it. Before 917adc03608 (http-backend: add GIT_PROJECT_ROOT environment var, 2009-10-30) there was no leak here, as we'd get it via getenv(), but since 917adc03608 we've xstrdup()'d it (or the equivalent), so we need to free() it. We also need to free the "cmd_arg" variable, which has been leaked ever since it was added in 2f4038ab337 (Git-aware CGI to provide dumb HTTP transport, 2009-10-30). Signed-off-by: Ævar Arnfjörð Bjarmason --- http-backend.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/http-backend.c b/http-backend.c index 6eb3b2fe51c..67819d931ce 100644 --- a/http-backend.c +++ b/http-backend.c @@ -786,6 +786,7 @@ int cmd_main(int argc, const char **argv) if (!getenv("GIT_HTTP_EXPORT_ALL") && access("git-daemon-export-ok", F_OK) ) not_found(&hdr, "Repository not exported: '%s'", dir); + free(dir); http_config(); max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER", @@ -795,5 +796,6 @@ int cmd_main(int argc, const char **argv) setenv(GIT_PROTOCOL_ENVIRONMENT, proto_header, 0); cmd->imp(&hdr, cmd_arg); + free(cmd_arg); return 0; } From patchwork Tue Jan 10 05:43:30 2023 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: 13094686 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 512EFC61DB3 for ; Tue, 10 Jan 2023 05:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbjAJFpA (ORCPT ); Tue, 10 Jan 2023 00:45:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229922AbjAJFoK (ORCPT ); Tue, 10 Jan 2023 00:44:10 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C9DA4102C for ; Mon, 9 Jan 2023 21:44:01 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id ss4so18531230ejb.11 for ; Mon, 09 Jan 2023 21:44:01 -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=Uwl1zo1cOqA+tv66p0BTwdfcbsxGzdoucTAVbabRV7k=; b=h7+g0N6cuAXuZA7lOKS1fRdH7+/ObD39teEvWRTp9nMllYqyh8nRBhju7RtuZaQju1 9PHK7FfDH6wBKtCqov0SJV/OeAeL+An7BE7Iy+Dcz/QM39JI1ZTfWu2G3XaRqhOzhqGX e0oCzrwSfEIRiXrdWDCTvIKwxrj6sz0K+r2DLkdx1/Kq2gmuSv+JHf5yF8FS2hXvl7dZ bC+0T4o1phWvpJ5CFz3+qaUNM3zrJ8eMls0ZOvswGb0pbD5xCyRoq7HYm5HR+gnKtXp1 gnSxCMaUeTXwm9L/ooC8yMP/qmKX7m6S46f+CXu5bIg/czpp9vK83M5KnDfxOaQGlHhA JtPA== 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=Uwl1zo1cOqA+tv66p0BTwdfcbsxGzdoucTAVbabRV7k=; b=E0MGdEI/YxOiOD+JnOnlapka4AiJeUGWpI26t84I27EIJ+vYwsu+UTSQvW+F2CyUu1 6pWwVtgiE8D/tSQPkdzK8gkCnIO4TzxUxT8MjWfOLShmzQye8+JUt+FOJOEhD4YLWbla wQbuTDEl2F5KhMObLdngpy7zLxAOBBzWYsXNiGuDZ5Y8qDq4k0WuCaREB529mBZLKrX9 V2dg9Wwh7DkFZRiIqeH9V01PWhHxxxiMR6B32utC0wfXVR9+MubFrUmKFxxmgY18EdD0 Mwelh00l9Q7rhWfgJDzOuXYRRe4MxP6Z1F+x9s0GqcLdymvLyUKBTnJF1MPblT8Km4mU KJPw== X-Gm-Message-State: AFqh2koJ4KwpjVwMIKIkYdmVfIvabqa1oMWUClIOV1HYhLGQJn1dxmEl vR7KVC+ozRhNbu95aBPx8WqK/1afTAWsSw== X-Google-Smtp-Source: AMrXdXvW5MjF7zn17RHEvDjPqBdRzKmY7YRGpJP5RvWR/G9G4oVImx2TXH+BZjoCPL4zh3JwpVH2MA== X-Received: by 2002:a17:907:d387:b0:7c1:6fd3:1ef3 with SMTP id vh7-20020a170907d38700b007c16fd31ef3mr58066943ejc.33.1673329439732; Mon, 09 Jan 2023 21:43:59 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:59 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 10/19] http-backend.c: fix cmd_main() memory leak, refactor reg{exec,free}() Date: Tue, 10 Jan 2023 06:43:30 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 67819d931ce..8ab58e55f85 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 Tue Jan 10 05:43:31 2023 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: 13094687 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 5A46CC46467 for ; Tue, 10 Jan 2023 05:45:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230286AbjAJFpB (ORCPT ); Tue, 10 Jan 2023 00:45:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjAJFoK (ORCPT ); Tue, 10 Jan 2023 00:44:10 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60C654084D for ; Mon, 9 Jan 2023 21:44:02 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id az20so6730584ejc.1 for ; Mon, 09 Jan 2023 21:44:02 -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=/g93NVg2PymlFEP0Ee00h8xm1bjSzEbRSGsOcQLkisQ=; b=XkovYGvqoCxkVKj2uAI811q2pVPJLcu3UMN1cD7VTUumAWrk1atnRQhnIYQexHNvgr E8A4iO69wtMHrxEKYlx90VQ7FwVJxf08eQ4rdM/c4ladqz4FQ03giPMGII8XRvCQWjze d3qH3jVkxLdNpcX/9IWat9FNGmqRAAKb80t+T1hsXCPhNRvoEpsr+oXdx0pNX0AKN3dj wYPGb2m33z0N1s7ZcglCha0OlFq/2vcb08oIQuts5Gwz7djQeACg+PuDuAuLXim+s/+3 aKvmh+Vi5I8OQWY4gYDnVN2psiEnHnlJGYOKm8et7IDKaxz4oaahsga3Zp3b1LT53wbl 1SkA== 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=/g93NVg2PymlFEP0Ee00h8xm1bjSzEbRSGsOcQLkisQ=; b=MEKzSTND3YLINStUJf6NQ2rNtCHUkKA5o2rc+Jxl4rOzHnzTOJ36iYvLKcP0+LgWtI 2CPeFFxuSsZKttpxeeCexTBKXp00h/Ra/C1al4LPhDJPvwWJDQ+9mYNKu74LfW+Vsf7V dP2ncgaiWoVlRN7B1MT/G9H+rmgNMsrB8V8nXeKRtwZ62wJXoQtddWtTGdqSaMHXKdSg VQ7Pn7ZQpoBBThx1V2mueIe2fIoTx+/3Q+GGSPq6GsH1jXjsm/2SjB9CfJgyMnmgsy3z zQe8v3sEXafeLZxzdFc1T8N93Y/IVdoeEFcKcLyRWa4BB/7NtirLd2AygkLPYx9sXUkK hjrg== X-Gm-Message-State: AFqh2kqLElVNn0iK5MQgQqSIBo7MWleHsoe7kgiI1z9e2E7NpNW04CiC RKitsfg/nKFmOB4NtSSFpcDTEhdCKZlGKA== X-Google-Smtp-Source: AMrXdXtoMY5OLwT3ELX2AMfK2L9+fBD/PdIG4iD3GzYGbAn7RKL3Kstbk7ejGuSB2W6oMBJ4+b4TuA== X-Received: by 2002:a17:906:8d0f:b0:7c1:7c38:f079 with SMTP id rv15-20020a1709068d0f00b007c17c38f079mr41754285ejc.71.1673329440652; Mon, 09 Jan 2023 21:44:00 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:43:59 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 11/19] commit-graph: fix a parse_options_concat() leak Date: Tue, 10 Jan 2023 06:43:31 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 0102ac8540e..93704f95a9d 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 Tue Jan 10 05:43:32 2023 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: 13094685 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 32EE5C46467 for ; Tue, 10 Jan 2023 05:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbjAJFoz (ORCPT ); Tue, 10 Jan 2023 00:44:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbjAJFoJ (ORCPT ); Tue, 10 Jan 2023 00:44:09 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958804102B for ; Mon, 9 Jan 2023 21:44:03 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id qk9so25815995ejc.3 for ; Mon, 09 Jan 2023 21:44:03 -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=Efz/Kl6udRu6r4tsUusWym+eZrf9qMOq86M+gpdcp3w=; b=j2pmUa+gJhrFmog3qVCh3WQ5WpdEPK3IowHSUKCxiW5r0DNsJFFPdOn9c2ywRvWdCM 4GdbjU6Ln1u+ykWzNQ20CeSfxCXK5GTTXTfITg3/vSlrDr8JcK8f9SNPfGU/SVKKpPQ3 lsmGAOySVAYc0A9HeDbWLP06yT03Sbc9AE+U8Jq+E0/6wdpkt+O/qg62HdTgXtVrKa8c u7bhVfyExpJtKipq80xUoUM8GQvC0cJjkE7QSLRu8/c9G8bbzeqJblQQfpVDkov4ciKY 2lx2dBoyiJEZ49ZEYVI9VQsH18LGcXf0lEBROfNxFpLDrazrJxWTO2Nwy4Kqm3DEm68T fNiA== 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=Efz/Kl6udRu6r4tsUusWym+eZrf9qMOq86M+gpdcp3w=; b=kqXlhLQSeupZi072Eu4hQ/H892Rul4fxhCb0cw06vNIl4hBivaVHLDBlTZa1vtI7cY 51xJlPPQn6yJgQvmMBKtCw2di3a4lCzWG5DQ3Bb0Zbrg5F8sEybhPrO2Fmi9w6PxJL+r I42DO53iT6QVqtbZ0Hxq6twRfowU6b4FvoQPu3HDy+JeNmgyb+tOVmGn8rt+vOb1z+Ua j+0nMUkWTPo+9SbXM9pzx/YpNJId2Sn4d3HwUblyjKjF2sBIMf0BHUGS12P/7pm/B8E+ rIYv+wqzBmh7uk8oStWnxyCptAO2QUfVbwIjmkEVT8ZAw/Q8xjObcaOi7igylWJRL3xE BIwQ== X-Gm-Message-State: AFqh2kpcNhf18EYhsfdU3q6UxfXct4C+QxDgo+rMryuNbBnZgXWjnTOA JNlkHL72dLo4VMp/jVJtYud3G53Xzk0dFg== X-Google-Smtp-Source: AMrXdXvj4WpZCEDJPieJ/Lw4gT650vWKPKdKZqzSVpzRymRgpAFCeqgQAcrpH5ey6GaqD4xPBfbORA== X-Received: by 2002:a17:906:c192:b0:7c1:6fe:f4a2 with SMTP id g18-20020a170906c19200b007c106fef4a2mr58847734ejz.45.1673329441563; Mon, 09 Jan 2023 21:44:01 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:00 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 12/19] show-branch: free() allocated "head" before return Date: Tue, 10 Jan 2023 06:43:32 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 Tue Jan 10 05:43:33 2023 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: 13094688 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 3DFFEC54EBE for ; Tue, 10 Jan 2023 05:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230312AbjAJFpE (ORCPT ); Tue, 10 Jan 2023 00:45:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbjAJFo3 (ORCPT ); Tue, 10 Jan 2023 00:44:29 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 724DC41A78 for ; Mon, 9 Jan 2023 21:44:04 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id az20so6730703ejc.1 for ; Mon, 09 Jan 2023 21:44:04 -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=uvVz6LFCFaVeRms1Rh9TNN0SLNxSr/CyENoT9POliGU=; b=CCOh2MkjItdOF5a7iuMDUzZ01i81c1h7iYjao6eswKMq4f6j0czMpWgvN+mY6G2SsN bIYcPouUYDYTtKe2KV0cxVTZmuv9v0uRO11oO3iwANtDIPIZ5RJAoSgdstZhjGoUM+zD zafC19zaqXtniCkBT5jo8eqS8n+KixRG1Wu0eGZ0nYCSVh107eyd2f55fT48z/0rO0eY 9PHdvFkeB/d9UbNsUU/0Bj2zp0TGRCFQtwG2vLyRwEWiF9cH2CBU+8KfaI2e7tywsrr6 40nuIsHdDyYjxgnDRr+udtL3YyEYRYQZda5dPo7GxpgTQAU9gqVsCpoPBP9vXDplOQuP Olmg== 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=uvVz6LFCFaVeRms1Rh9TNN0SLNxSr/CyENoT9POliGU=; b=gUdircxneotADhViezhkWkStNr/c9osZ/RKuGO1CS7Ssu428TzU0EVZ1yNi/CeXh/9 /k97H62xA4tUOC5BbkrfOVg3AB9c+EbRimJjjvjPpEufupphzS5DnKD6Qciiz+qMnsZq CZLcp0raKLkLHvQS3Cj+4dXrNE0AVWIv3zYngzYeuSghLTxQp0D5BR3fWJaGDNuTSH3S xlTzkKxXheLfN5FbDgr5l5Ck1LBDAC75M6CpL7WobdfUNQJCRwEFi+AnA+hPjhz1drwW UDRfCRclTCVxtmT8F4ssy8+kiVP6jD71QIPE9l0prHL1/Ng8X61kJq/+5zxRYmd6uX4T K4Jg== X-Gm-Message-State: AFqh2kr3XtEWDYXVQ51v2rVVgePQ557XN7M7Ocw6EmOEltz6c72uVcok cP/Kx8rZvJIf9MfNTbbGGwsIDyk0bz3KXA== X-Google-Smtp-Source: AMrXdXu803YhZDgBP9BRhjSEEvbzH8TSpNyukv1N4gReRe8OXle/sAmwIM27vl0VKBsrGlLhJ4drQA== X-Received: by 2002:a17:906:8447:b0:7c8:9f04:ae7e with SMTP id e7-20020a170906844700b007c89f04ae7emr56714908ejy.22.1673329442518; Mon, 09 Jan 2023 21:44:02 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:01 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 13/19] builtin/merge.c: always free "struct strbuf msg" Date: Tue, 10 Jan 2023 06:43:33 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 address the "msg" memory leak in this block. We could free "&msg" before the "goto done" here, but even better is to avoid allocating it in the first place. By repeating the "Fast-forward" string here we can avoid using a "struct strbuf" altogether. Suggested-by: René Scharfe Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 11 ++++------- t/t6439-merge-co-error-msgs.sh | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 0f093f2a4f2..91dd5435c59 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1560,7 +1560,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) !common->next && oideq(&common->item->object.oid, &head_commit->object.oid)) { /* Again the most common case of merging one remote. */ - struct strbuf msg = STRBUF_INIT; + const char *msg = have_message ? + "Fast-forward (no commit created; -m option ignored)" : + "Fast-forward"; struct commit *commit; if (verbosity >= 0) { @@ -1570,10 +1572,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix) find_unique_abbrev(&remoteheads->item->object.oid, DEFAULT_ABBREV)); } - strbuf_addstr(&msg, "Fast-forward"); - if (have_message) - strbuf_addstr(&msg, - " (no commit created; -m option ignored)"); commit = remoteheads->item; if (!commit) { ret = 1; @@ -1592,9 +1590,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } - finish(head_commit, remoteheads, &commit->object.oid, msg.buf); + finish(head_commit, remoteheads, &commit->object.oid, msg); remove_merge_branch_state(the_repository); - strbuf_release(&msg); goto done; } else if (!remoteheads->next && common->next) ; 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 Tue Jan 10 05:43:34 2023 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: 13094689 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 95B8FC54EBE for ; Tue, 10 Jan 2023 05:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230362AbjAJFpH (ORCPT ); Tue, 10 Jan 2023 00:45:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjAJFoa (ORCPT ); Tue, 10 Jan 2023 00:44:30 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A47640862 for ; Mon, 9 Jan 2023 21:44:05 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id vm8so25801106ejc.2 for ; Mon, 09 Jan 2023 21:44:05 -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=wuYTKjTk7XWDGwdWhx+LIoy2M27eh7bfsBuGhMmK1RI=; b=ASVreSRfPsoIUHN0a6vkTo88b4W9MGakR9rOHKs4QwnvDTSoyNtrkaHpV6ruV3kzEB zJCJQX5bCBYDsrdybm3noBV2CrYG7qQtrCHTL+s9BP44sY3UCK0TXRSThCyFMd8lqSRU gpF57IiwG5CqIGqp/A4KdRB64fd2ZeZ7suJl1IwndM/OyevIJn/uaOBuwxK44UpKzi4R 4rcg+iiBdBdyenrT+Nvr9Kx2RoOgSuDV5fTzn1D+QASU7wiZr7PI5tG2lWNcnaemPNcX cYsRRmvWQnLvcfyWxN706pd2eVpa33d6LD+dLR6iS0UpGdFeTvMdD4CwZR1hAEW3W+Na d10A== 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=wuYTKjTk7XWDGwdWhx+LIoy2M27eh7bfsBuGhMmK1RI=; b=AhBooehXbmnwoDrMjitHLM7oDOf2PZJ1SWAJj2Mhn7WdHAKP9ngyvmYuu6ws8G/tgg A+oRwZKue1Uq1yT3Bo65dTLSXXsYtj048kyWRtTQ5HJrqsKblvJi7DvQ4yfErNRT7cjU JQTwzzPuzz5geI6V5cb9xfH6lPLFfB0fvjU+NuHXJCuA2Nf/mco1NYxLllnJeKlAEXjg WX4aHdhAVMi+XTrFPSASAMp/fQHt2ZJkFGrV52XpJisWCO39yhBj4WlAjB3zfmgBPKyB 3NUeHIpuxLco6vW9TBCmuy0h1OB4e9EGnzC27hu2FSu/AJXJol1CEvqiLdSO2FKeOP56 BJrA== X-Gm-Message-State: AFqh2kpyPB+QHxquH/B6Fgxjv2NaLBjuCqAJZLM8a3JgkucRgQ0vVOat c8I+Wgi+TM1hoeFVfRSHbuwdqYznXBzwyA== X-Google-Smtp-Source: AMrXdXtAqFQ2boici3YLBJud2dSNW6k+XxXribNENHa8MOGtKaCXeH+IRBa0nvo0d232o5tTSmgNpg== X-Received: by 2002:a17:907:93d5:b0:83c:cca7:64a7 with SMTP id cp21-20020a17090793d500b0083ccca764a7mr52102894ejc.73.1673329443455; Mon, 09 Jan 2023 21:44:03 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:02 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 14/19] builtin/merge.c: free "&buf" on "Your local changes..." error Date: Tue, 10 Jan 2023 06:43:34 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index 91dd5435c59..2b13124c497 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1618,7 +1618,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. */ From patchwork Tue Jan 10 05:43:35 2023 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: 13094690 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 15120C54EBE for ; Tue, 10 Jan 2023 05:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbjAJFpO (ORCPT ); Tue, 10 Jan 2023 00:45:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjAJFoa (ORCPT ); Tue, 10 Jan 2023 00:44:30 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CD6A40841 for ; Mon, 9 Jan 2023 21:44:06 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id cf18so19457639ejb.5 for ; Mon, 09 Jan 2023 21:44:06 -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=8JqIp03kxI3hXdFuwS8M3uz/VLJiA94qJQr8Y7PMcoQ=; b=d1dBF3JDT6XgEy/QP37VAPlBskYYnEknhLkXgxmE5ee2Lzo2UgsG9TJeL+MhX25MYH 2l6ooikFxkAjpqrCRj1TlOhXu2ptebEKFr5bjc9HU9ekYAp7eoRmvHsI/kc+suXUSd+k j9QokWHlpPDp1hYm8SN0hf3eld4wKQ7CZ1hPeRUUTyQ7KyxFvBZQ7bUbeZrRxHV7Kpem pm7RjGoHP//2m3S9GDDQ7oFf7Ift72Rr6v+nRpibxCOuppUmYpMIniWSvjjVaFHgoq7+ h43dOkXRMi4GAVCj03sYvzd1F+r8ZlBD1o0EAX2MjbA+29m7CxoKzk9yaL4ph/0cHSmA 7mdA== 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=8JqIp03kxI3hXdFuwS8M3uz/VLJiA94qJQr8Y7PMcoQ=; b=jW/mtxHr5VjemFferGtTXIMF34zwf5AWb7WfuRqyCzU1DBgF9EyODQNjW2rbJlWpKu v044/f3UXKsa6AEbJXtbfUcVjLxsP3oB7ZvbKgcAzGS2GnJNrCVk3WCsfC5furictYeX bO0t4uh/DO5xgcc3Q0H8iCje7ZqBukTO+zAwDzdaoyyGdLiQFURXK+JsVz+XkUuR9xQ3 GCayGajycOZ+pOJS3pcWobG5gLqxtv+dLYoC8p4MUcS4Q7VX5rFFgF53X2Xp1coFgn51 OP0FS5HFLEF0hrDgDojbm1KyXTcfZnHJrBcN2m6bKNY62LPBQ+NOHxczbNkT6T7zZrW0 c3Tg== X-Gm-Message-State: AFqh2koQXYqAnO3ZJ+9UkVDt9wTwA3JXCu69cR5xP/W92luoyx70LwQG 1WR8/jrdNWf1yZEF1nvpvZkwwspLkuLeFA== X-Google-Smtp-Source: AMrXdXta4I2taDUmufscFVSZ2nvDBgG1b8Gdl9gE7admw4DPnzDDf5g2Vob/LGO5KGhv+5nfoZDhJw== X-Received: by 2002:a17:906:d052:b0:7c1:5098:907a with SMTP id bo18-20020a170906d05200b007c15098907amr60116001ejb.35.1673329444459; Mon, 09 Jan 2023 21:44:04 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:03 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 15/19] object-file.c: release the "tag" in check_tag() Date: Tue, 10 Jan 2023 06:43:35 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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. The clearing that release_tag_memory() does for us is redundant here, but let's use it as-is anyway. It only has one other existing caller, which does need the tag to be cleared. 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 80a0cd3b351..b554266aff4 100644 --- a/object-file.c +++ b/object-file.c @@ -2324,6 +2324,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")); + release_tag_memory(&t); } 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 Tue Jan 10 05:43:36 2023 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: 13094691 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 89A0EC54EBE for ; Tue, 10 Jan 2023 05:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbjAJFpU (ORCPT ); Tue, 10 Jan 2023 00:45:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbjAJFob (ORCPT ); Tue, 10 Jan 2023 00:44:31 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CDFA40850 for ; Mon, 9 Jan 2023 21:44:06 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id fy8so25713926ejc.13 for ; Mon, 09 Jan 2023 21:44:06 -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=Y5u8BbA1My5DYqFkW8qtbOm6T0TIpfWVD3SpGq+b5Bw=; b=B92KBNo1kqZqJjfosmgKFmNqKZO3lQSpas5ROjoO/ih7XwAN7qMJPF5artExN+mnCT cDNC16K3mYkzyDggjMBvpxqR20Co/ey6LWhdDXOGbbSZcdSQ6N5E6p50b9WSLSVCkqGH EGqJAAdoy2Bx5jTOPW2WWz8XY0/jUbRFmWiFkFQmCAITUQ134P5A5QMVc2yiwfH9E2Jn mU8cPbPUGcnSStMPwAeqlcym7sR2oQvha2xja773sZ0L4NcM4jVeziNMVd0JUBQ4FYVQ sEcZHlAyvRzmrqikg/BWGbzV2xr9r4PteWbLMxszF9Pu62inmIOemjiDlxPn5MtSOfki voyQ== 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=Y5u8BbA1My5DYqFkW8qtbOm6T0TIpfWVD3SpGq+b5Bw=; b=zzogb/qQkwKZ2IqKUY5YjR7fpxtZ5DUKBvGz2Hwgdv5TVDl8VGpphpDZDvfP1iuhrO TRkPvXzrtiUPS4+a6J+tUhpTbNkfB5vryrpRW92mMBjS7LKo8hNrVoaJK0RgM/KRZvhq btfEADpPMTJKZZdZHuZaB63nR7mXuCkWdI6RrWGw1nc9rjahnemCLm7WNTTp4Tk1VL/Y IED2TSJiqnskn/S7PNa0Yo9bD52UfhieJuEMuEO/yACtCLqNIShwOfXjb/1VXjrj6UUu p2ZhXkSbOLjDVcVUhTb29TutbLnhsjYg37p95Z99GIanJ3uGpTp9rQu9uX31jG0dupw3 Rong== X-Gm-Message-State: AFqh2kodxCmbXRC60iHwRCmj/5hDKDVJmPqelO+FrP3bxt3AooQYVu01 3Tg2JiHNLiNU5Eg5+VhP0VEUpTMNM+2eCQ== X-Google-Smtp-Source: AMrXdXvHA9ca0jsJdGIvMtQ+h6Pt1W0nXVdbCO5hnpnjb21D9t0ZGGveRqlqtWr3G39wJqLKONrw6Q== X-Received: by 2002:a17:906:3993:b0:844:de87:8684 with SMTP id h19-20020a170906399300b00844de878684mr66339420eje.46.1673329445453; Mon, 09 Jan 2023 21:44:05 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:04 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 16/19] grep.c: refactor free_grep_patterns() Date: Tue, 10 Jan 2023 06:43:36 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the free_grep_patterns() function to split out the freeing of the "struct grep_pat" it contains, right now we're only freeing the "pattern_list", but we should be freeing another member of the same type, which we'll do in the subsequent commit. Let's also replace the "return" if we don't have an "opt->pattern_expression" with a conditional call of free_pattern_expr(). 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 the subsequent change, but as we're refactoring this function let's make it easier to reason about, and to extend in the future, i.e. if we start to free free() members that come after "pattern_expression" in the "struct grep_opt". Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/grep.c b/grep.c index 06eed694936..a4450df4559 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,10 +790,14 @@ void free_grep_patterns(struct grep_opt *opt) } free(p); } +} - if (!opt->pattern_expression) - return; - free_pattern_expr(opt->pattern_expression); +void free_grep_patterns(struct grep_opt *opt) +{ + free_grep_pat(opt->pattern_list); + + if (opt->pattern_expression) + free_pattern_expr(opt->pattern_expression); } static const char *end_of_line(const char *cp, unsigned long *left) From patchwork Tue Jan 10 05:43:37 2023 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: 13094692 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 8FB88C46467 for ; Tue, 10 Jan 2023 05:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbjAJFpY (ORCPT ); Tue, 10 Jan 2023 00:45:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjAJFoc (ORCPT ); Tue, 10 Jan 2023 00:44:32 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17FC441D6B for ; Mon, 9 Jan 2023 21:44:07 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id vm8so25801298ejc.2 for ; Mon, 09 Jan 2023 21:44:07 -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=e1OwbEEsy2sPzLTZbmkdC9lxrYZERuEx+7/I0upOelU=; b=SvzbsFae609Oe/Cj9iZQz9O/myFC9a4X3Gc3yg+q3lhD5/IYJY3LKmjY1IM5Mbr/h0 DZhPtE3jxWE9+bwkXrRTPiuaOhkVO9H+Q6iEQED4wEBsKiKR8TUTiSd3EuNmIBJauO1o stAtVyfjv/4f37uemnNOI/qFnhIh00oK6LCN+eGIp9PLPf2E/nYGak2hA+D7yn2bHl4X PAwfRm9OH86wg+jTb2qCJwUXdBtd7AcimAx/WhNAeUdPK0K6xtFGQ2r8iEBA3+fOO9q3 KxSVremEJ64QdN3pUoKlcrurJqZGEsk85CXoohLiDU+F5r3KgT+BfjUG1gkzT2Xbybwi LQaA== 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=e1OwbEEsy2sPzLTZbmkdC9lxrYZERuEx+7/I0upOelU=; b=LeX0OD4gx+Ywg9JzqxxRY0P2qt+qm7vSnRKDWLpkDoW2cp6+11f1/uCvf11l4bRDxH ykQsF88162NhmvthibmSRK3g5HH8nXCt7JVVIjkH+889Bw2DQS/5izpP4+1EgPpYz3sn f+GKTDB+a6apkC4PkOvj4rP8bH1mTgkWFuB+Cm6bDcvkAH5pwCTPP4/f9/7+c4aGHseq GhpFwWCCN1CseCr4T3LuvfMo8wfDo/Zts4OWgR4KeiMzLK1JJ6MxQ3DehgskDgEdOh5S vJ1dC+dn0VbB8mqMPl6G5ThnHJRGIlOiUrXQM2Aaz3Nt+7hagxbZL41qhS+pD2zbbSrx YFDw== X-Gm-Message-State: AFqh2krtQM9g5P7RS82pq0Fti3BE5RJJ3Ghp/DKjpMaQWYCBs8w60X+0 90qget7MsWC1rQF8llvBk7Jkg0sgbGPbJg== X-Google-Smtp-Source: AMrXdXs5Gz+obgBuQ2nAuhkRB6YNrSO3mFPzqX3C6pmk4/FIaX38Cr4DldU2pMAvQmrZ6HWk/EyYmA== X-Received: by 2002:a17:906:8478:b0:84d:373b:39dc with SMTP id hx24-20020a170906847800b0084d373b39dcmr8666073ejc.25.1673329446395; Mon, 09 Jan 2023 21:44:06 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:05 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 17/19] grep API: plug memory leaks by freeing "header_list" Date: Tue, 10 Jan 2023 06:43:37 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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. 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/grep.c b/grep.c index a4450df4559..c908535e0d8 100644 --- a/grep.c +++ b/grep.c @@ -795,6 +795,7 @@ static void free_grep_pat(struct grep_pat *pattern) 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); From patchwork Tue Jan 10 05:43:38 2023 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: 13094693 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 D5D4EC54EBE for ; Tue, 10 Jan 2023 05:45:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbjAJFp3 (ORCPT ); Tue, 10 Jan 2023 00:45:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbjAJFoc (ORCPT ); Tue, 10 Jan 2023 00:44:32 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8D241D6E for ; Mon, 9 Jan 2023 21:44:08 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id qk9so25816384ejc.3 for ; Mon, 09 Jan 2023 21:44:07 -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=4uso+ZOOlGJiUguFVqdie08BryGf/LseLSoyR9v5Tzw=; b=JAKEEbPF7pyuxxXyGBFI0LZi6e18nDsjl/N10y/KwvwSAgO48NAewTugeUJsy9z1yH Pc27a1C6eJvPdDLpZvv+87a9G4Gqo9KoEknGDOAvxK9ygh+APsyHYliLXoBQpkJT/VCe OZ9IHFdYYuPp3IIZdLAqdxL5ipyWdPg692cVmuuBBXsKxlzbaoEuncgWRjAg2o/CVXPn jNkzeAnThLf5zfwQzW3/pXS4HvlmH2zC8vGKF/wZx4r+/ma2JZYMTclKYn9SYJL2iPrx 9DBwzSRxrJXpkYxHYbfgjAJx4RSjYLyhuqEG3gFQ3/taFjENKk+XH8V6y/QjtPdGZ2QG wGdg== 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=4uso+ZOOlGJiUguFVqdie08BryGf/LseLSoyR9v5Tzw=; b=0v/OgAFyECdX4Xx8wbXw6GTa0fB532kExWdAn1RdJ2G69gs7HCgI4/VvGme7lq/jR5 F1EWelYE3zKa0QKcGT4F0/tD7TXSb9paZwRd7cYMlUDfEbI1GVYzV6DxGrQEFF/fGd3z dZHVTXfU3gRhQAmS/nvEsgDqf8xRjDEecLQsemyEyHn2uKOnPRkcBnOPX/BqUFgrt/ML fm0wlHTcDu2/fDGBnRjDQlGLdspbktjLjaFHMfQS0B4ahOOy90oOXHZNbhCOaN9aT4HJ H3xTIcZgx0MiQx9Fu+sJurO0fTuOwU5zCpB/yMsaqyfvrrFWae6r+3/K0QuP+CYH01QR IoKQ== X-Gm-Message-State: AFqh2kpIMqnWLRaJjvgBnzWnhJjtxxRbANXPIUqzSgR9ORIWAdvFVs28 Cb70OwMAxDVYnl0b4VJ9wEhaKH+P2b60YA== X-Google-Smtp-Source: AMrXdXuvP5cQaettN5avoRc3y1TrIetz7f2xMd1cpqTNmhGgaboxFc7m5cJvzCzsyPamHL2ZCcn+Cw== X-Received: by 2002:a17:907:d004:b0:7c0:f213:4485 with SMTP id va4-20020a170907d00400b007c0f2134485mr57581156ejc.73.1673329447313; Mon, 09 Jan 2023 21:44:07 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:06 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 18/19] receive-pack: free() the "ref_name" in "struct command" Date: Tue, 10 Jan 2023 06:43:38 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 575f497456e (Add first cut at "git-receive-pack", 2005-06-29), see eb1af2df0b1 (git-receive-pack: start parsing ref update commands, 2005-06-29) for the later change that refactored the code to add the "ref_name" member. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 10 ++++++++++ t/t5405-send-pack-rewind.sh | 1 + t/t5406-remote-rejects.sh | 1 + t/t5507-remote-environment.sh | 2 ++ t/t5522-pull-symlink.sh | 1 + t/t5527-fetch-odd-refs.sh | 1 + t/t5705-session-id-in-capabilities.sh | 1 + 7 files changed, 17 insertions(+) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index a90af303630..451bad776c6 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -2032,6 +2032,15 @@ static struct command **queue_command(struct command **tail, return &cmd->next; } +static void free_commands(struct command *commands) +{ + while (commands) { + struct command *next = commands->next; + free(commands); + commands = next; + } +} + static void queue_commands_from_cert(struct command **tail, struct strbuf *push_cert) { @@ -2569,6 +2578,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) run_receive_hook(commands, "post-receive", 1, &push_options); run_update_post_hook(commands); + free_commands(commands); string_list_clear(&push_options, 0); if (auto_gc) { struct child_process proc = CHILD_PROCESS_INIT; diff --git a/t/t5405-send-pack-rewind.sh b/t/t5405-send-pack-rewind.sh index 11f03239a06..1686ac13aa6 100755 --- a/t/t5405-send-pack-rewind.sh +++ b/t/t5405-send-pack-rewind.sh @@ -5,6 +5,7 @@ test_description='forced push to replace commit we do not have' 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/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh index dcbeb420827..d6a99466338 100755 --- a/t/t5406-remote-rejects.sh +++ b/t/t5406-remote-rejects.sh @@ -2,6 +2,7 @@ test_description='remote push rejects are reported by client' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t5507-remote-environment.sh b/t/t5507-remote-environment.sh index e6149295b18..c6a6957c500 100755 --- a/t/t5507-remote-environment.sh +++ b/t/t5507-remote-environment.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='check environment showed to remote side of transports' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'set up "remote" push situation' ' diff --git a/t/t5522-pull-symlink.sh b/t/t5522-pull-symlink.sh index bcff460d0a2..394bc60cb8e 100755 --- a/t/t5522-pull-symlink.sh +++ b/t/t5522-pull-symlink.sh @@ -2,6 +2,7 @@ test_description='pulling from symlinked subdir' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # The scenario we are building: diff --git a/t/t5527-fetch-odd-refs.sh b/t/t5527-fetch-odd-refs.sh index e2770e4541f..98ece27c6a0 100755 --- a/t/t5527-fetch-odd-refs.sh +++ b/t/t5527-fetch-odd-refs.sh @@ -4,6 +4,7 @@ test_description='test fetching of oddly-named refs' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # afterwards we will have: diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh index ed38c76c290..b8a722ec27e 100755 --- a/t/t5705-session-id-in-capabilities.sh +++ b/t/t5705-session-id-in-capabilities.sh @@ -2,6 +2,7 @@ test_description='session ID in capabilities' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh REPO="$(pwd)/repo" From patchwork Tue Jan 10 05:43:39 2023 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: 13094694 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 7697FC46467 for ; Tue, 10 Jan 2023 05:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231177AbjAJFpd (ORCPT ); Tue, 10 Jan 2023 00:45:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbjAJFoe (ORCPT ); Tue, 10 Jan 2023 00:44:34 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E22641667 for ; Mon, 9 Jan 2023 21:44:10 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id qk9so25816436ejc.3 for ; Mon, 09 Jan 2023 21:44:09 -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=I1zwBX8h2fV2lrJOvsQ4jfSES3qlf0gpExpUdDWDAEY=; b=cRsytfhFfvZZOQIqhJ8lUkotaMzU3hMn5sOlRTQHSguRhdmxLeCkSw4ysDBsoSKFpG MOsDzviTK0pOjD1mFnZUAZMK9X6wUj0t0pklEwMgDjD5U+jIFvmkIdei1H8NtJQbC7OS AsmjyR9D9gLxFW1UiQzn6AHRh/BACJe9503EN44zb9Iwy0dLZRxUc4/el+XWPL0QNJo/ qPeySkVXo1FS832D40VZAEnTtWPWyBF1PMxGIT9raEp/uWb8g/xLjqMZItT5Ne/tIIE2 Flm1GWpsjCQK9I+JZNri7inWEYXnhnuROqft5P6jT+hyMuK7Q0wyyIgpW0VYcxKI1KdI JW1Q== 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=I1zwBX8h2fV2lrJOvsQ4jfSES3qlf0gpExpUdDWDAEY=; b=MATPKFn0J0jLE+HMylTFlTwoje6zzb3+fhzU4UfBwv6ltYV2XzuULH1C/iVSf9uWjc /wg71PsVBUSKx2Sf/ZAFngkCoAoQjZVn6QO7MdRioY6s3hYpZVFwp9gDHTQk1QETnkt9 xCbdGNg8IjZR74aK52peFoidPXrSRBMfocQM3m31sCta+CYjTcfP8Vi9QRaqkvVDpVoZ b/7JAoPSKTHtWAGl2SdZFaZyVTNZrcqNAk1yxNdWnDesX49nkxLCN/T8ZKJZGHJz+Dbk 8B40PC7T7b+RQaqAfDJWHMZryJBjTUsIeA66n2KHyqzaAbBAo3dVIoASsiXx9onuTfNU QIRw== X-Gm-Message-State: AFqh2koPcNnZTGBQMOyzUVINiSwrlkCT0kb9xYb2Ky3LwrD6AGLsHPZT /UDzMSwrf7J+DSaNBfNgdSKGUxfvPRlEHw== X-Google-Smtp-Source: AMrXdXsedWT7i+jMnjYP43D0tFffDtnkWBY83Ru9liC4avuPG7K/zMm9txKZXcc2uUUYKU24gF7Hog== X-Received: by 2002:a17:906:4cd2:b0:7c0:e5c6:2a74 with SMTP id q18-20020a1709064cd200b007c0e5c62a74mr53546357ejt.34.1673329448238; Mon, 09 Jan 2023 21:44:08 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g21-20020a170906869500b0084d36fd208esm3428423ejx.18.2023.01.09.21.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 21:44:07 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 19/19] push: free_refs() the "local_refs" in set_refspecs() Date: Tue, 10 Jan 2023 06:43:39 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1195.gabc92c078c4 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 added in ca02465b413 (push: use remote.$name.push as a refmap, 2013-12-03). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/push.c | 1 + t/t1416-ref-transaction-hooks.sh | 1 + t/t5504-fetch-receive-strict.sh | 1 + t/t5523-push-upstream.sh | 1 + t/t5529-push-errors.sh | 2 ++ t/t5546-receive-limits.sh | 2 ++ t/t5547-push-quarantine.sh | 2 ++ t/t5606-clone-options.sh | 1 + t/t5810-proto-disable-local.sh | 2 ++ t/t5813-proto-disable-ssh.sh | 2 ++ t/t7409-submodule-detached-work-tree.sh | 1 + t/t7416-submodule-dash-url.sh | 2 ++ t/t7450-bad-git-dotfiles.sh | 2 ++ 13 files changed, 20 insertions(+) diff --git a/builtin/push.c b/builtin/push.c index 60ac8017e52..f48e4c6a856 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -129,6 +129,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo) } else refspec_append(&rs, ref); } + free_refs(local_refs); } static int push_url_of_remote(struct remote *remote, const char ***url_p) diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 27731722a5b..b32ca798f9f 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -5,6 +5,7 @@ test_description='reference transaction hooks' 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/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh index ac4099ca893..14e8af1f3b7 100755 --- a/t/t5504-fetch-receive-strict.sh +++ b/t/t5504-fetch-receive-strict.sh @@ -4,6 +4,7 @@ test_description='fetch/receive strict mode' 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 and inject "corrupt or missing" object' ' diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh index fdb42920564..c9acc076353 100755 --- a/t/t5523-push-upstream.sh +++ b/t/t5523-push-upstream.sh @@ -4,6 +4,7 @@ test_description='push with --set-upstream' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh index ce85fd30ad1..0247137cb36 100755 --- a/t/t5529-push-errors.sh +++ b/t/t5529-push-errors.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='detect some push errors early (before contacting remote)' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup commits' ' diff --git a/t/t5546-receive-limits.sh b/t/t5546-receive-limits.sh index 0b0e987fdb7..eed3c9d81ab 100755 --- a/t/t5546-receive-limits.sh +++ b/t/t5546-receive-limits.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='check receive input limits' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Let's run tests with different unpack limits: 1 and 10000 diff --git a/t/t5547-push-quarantine.sh b/t/t5547-push-quarantine.sh index 1876fb34e51..9f899b8c7d7 100755 --- a/t/t5547-push-quarantine.sh +++ b/t/t5547-push-quarantine.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='check quarantine of objects during push' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'create picky dest repo' ' diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index cf221e92c4d..27f9f776389 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -4,6 +4,7 @@ test_description='basic clone options' 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/t5810-proto-disable-local.sh b/t/t5810-proto-disable-local.sh index c1ef99b85c2..862610256fb 100755 --- a/t/t5810-proto-disable-local.sh +++ b/t/t5810-proto-disable-local.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test disabling of local paths in clone/fetch' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-proto-disable.sh" diff --git a/t/t5813-proto-disable-ssh.sh b/t/t5813-proto-disable-ssh.sh index 3f084ee3065..2e975dc70ec 100755 --- a/t/t5813-proto-disable-ssh.sh +++ b/t/t5813-proto-disable-ssh.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test disabling of git-over-ssh in clone/fetch' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-proto-disable.sh" diff --git a/t/t7409-submodule-detached-work-tree.sh b/t/t7409-submodule-detached-work-tree.sh index 374ed481e9c..574a6fc526e 100755 --- a/t/t7409-submodule-detached-work-tree.sh +++ b/t/t7409-submodule-detached-work-tree.sh @@ -13,6 +13,7 @@ TEST_NO_CREATE_REPO=1 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/t7416-submodule-dash-url.sh b/t/t7416-submodule-dash-url.sh index 3ebd9859814..7cf72b9a076 100755 --- a/t/t7416-submodule-dash-url.sh +++ b/t/t7416-submodule-dash-url.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='check handling of disallowed .gitmodule urls' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh index ba1f569bcbb..0d0c3f2c683 100755 --- a/t/t7450-bad-git-dotfiles.sh +++ b/t/t7450-bad-git-dotfiles.sh @@ -12,6 +12,8 @@ Such as: - symlinked .gitmodules, etc ' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pack.sh