From patchwork Thu Sep 5 10:08:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792076 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DA9019538A for ; Thu, 5 Sep 2024 10:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530924; cv=none; b=QxAb0HM/hIshFGlZhIF3tTBHjydh1nIy+WBOf5uIjrXU7zWGp3b9v8uGh7SBrA1QOFNk6jbuLz6lQHOcUHrBeWuCq1sTJFciCbJ70KxqJHyY94NfDlnK89DD1KryCbDR7AKa9hdAoOWS7PEKaO+8zBVtuCtrpP8A3GidzBgkzVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530924; c=relaxed/simple; bh=BvhyX2pIjwJdN5DI6FFPqgJLrLe8VcaT1j6XjwJCZdc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AIohei5MOHLz4JHTHZv41F8U6p3Ue5Phg51yubaq5Pf17dVvPxxvV0AGEuBqBw+j0u9kbkWnipm5BXHh4qQzW7xUPb7sLJ3UfRvYgShjLGfg/nSLr03jDWD7PzexCm/GpgWzV/JCNwf2d7OA4AWmN7r6db6P7VAxrOjJj5ScDrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=MPJ4QxM3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QZ3ZvMCz; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="MPJ4QxM3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QZ3ZvMCz" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id A3F8E114029C; Thu, 5 Sep 2024 06:08:41 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 05 Sep 2024 06:08:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530921; x=1725617321; bh=6H96m48SNj sEadvOmjTzNk/LklRhDlWQ96GodTyN23o=; b=MPJ4QxM3TjOrubuPAXvB0+S0E5 EkPDg9H3lgyvb+QdxWXX8usXw8MM0c9qVQx7uAh2V+t2+DDdvrdZjlBJWucwMjEZ e1c9WcO/FD3BeAtpcaTdja9jOEQS4IEUUs5VdWqa6mUPp/OTPSPViQHuvpjc8+ng aH4+crz4aEpSIaqKZ6huyzh7fXvPmDiwQGFcB+V0CU4sp2TExO79z0isBtlrPGmc dC9qhcmXxZlfvu7Dgs9CyCAz8GVoEQKyDh9ukOE2C8Q55EhK6FST8hv8a78uwwN9 ogFvBe9drgbv0V1Qt7HG8q+1ywdlTQvKTDY83+qB8A4Hs+bw8OvFBy20jkHg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530921; x=1725617321; bh=6H96m48SNjsEadvOmjTzNk/LklRh DlWQ96GodTyN23o=; b=QZ3ZvMCzcLWEFBo3pxbGWmmdPpeGUMEUMs9kfVo9BvBy JdJ7If7Cyw6pTF/j3x6JvreAopfB+hH3twwZIspmxTo5sz6y5+uo9xT3kVEkZXwD aeaAxOpp2qXRJDQXYiPWmrvllt5iXXxWqBiYmNjpPaf7y9oCOuAPAohJ8x7QNywY 8hz8BTFYDRAyGL4y2PJJwLhBwfYpN0yb5WdHI1E7HPkdCIeHa7fFLRbdQ2GFWL6Q ji8ooV8JGIgwyH0FGGRwS+oBZkoKPls5wcCsBMtSczMdyXn02ANVriHD6/PPFZAU yZ1lMaz94HXQIZk4lZzeZxuO2OY1HxlodTfMHt+bVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepnhgvfihr vghnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegt rghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 05fcb5b6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:28 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 01/22] t/test-lib: allow skipping leak checks for passing tests Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: With `GIT_TEST_PASSING_SANITIZE_LEAK=check`, one can double check whether a memory leak fix caused some test suites to become leak free. This is done by running all tests with the leak checker enabled. If a test suite does not declare `TEST_PASSES_SANITIZE_LEAK=true` but still finishes successfully with the leak checker enabled, then this indicates that the test is leak free and thus missing the annotation. It is somewhat slow to execute though because it runs all of our test suites with the leak sanitizer enabled. It is also pointless in most cases, because the only test suites that need to be checked are those which _aren't_ yet marked with `TEST_PASSES_SANITIZE_LEAK=true`. Introduce a new value "check-failing". When set, we behave the same as if "check" was passed, except that we only check those tests which do not have `TEST_PASSES_SANITIZE_LEAK=true` set. This is significantly faster than running all test suites but still fulfills the usecase of finding newly-leak-free test suites. Signed-off-by: Patrick Steinhardt --- t/README | 3 +++ t/test-lib.sh | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/t/README b/t/README index 44c02d81298..8dcb778e260 100644 --- a/t/README +++ b/t/README @@ -386,6 +386,9 @@ GIT_TEST_PASSING_SANITIZE_LEAK=check when combined with "--immediate" will run to completion faster, and result in the same failing tests. +GIT_TEST_PASSING_SANITIZE_LEAK=check-failing behaves the same as "check", +but skips all tests which are already marked as leak-free. + GIT_TEST_PROTOCOL_VERSION=, when set, makes 'protocol.version' default to n. diff --git a/t/test-lib.sh b/t/test-lib.sh index 54247604cbc..64bd36531c1 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1558,8 +1558,16 @@ then passes_sanitize_leak=t fi - if test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check" + if test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check" || + test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check-failing" then + if test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check-failing" && + test -n "$passes_sanitize_leak" + then + skip_all="skipping leak-free $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=check-failing" + test_done + fi + sanitize_leak_check=t if test -n "$invert_exit_code" then @@ -1597,6 +1605,7 @@ then export LSAN_OPTIONS elif test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check" || + test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check-failing" || test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false then BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_PASSING_SANITIZE_LEAK=true" From patchwork Thu Sep 5 10:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792077 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0865613AA2B for ; Thu, 5 Sep 2024 10:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530926; cv=none; b=NAKp5mxO9IMMqz9JMdSpPaV4PYr+2aTzRoAHpmD0PFeKYRgYYbMBMM8tpJ+ozZHR8MBmjJFs59XrlFEQ2z7I4dyOj6IvDN9MVs1cizbDNGIRUDKN/mLEbBk5tA7LaQnD4Oboml5SvIOMfi9k801nEcg3B0MvKqZ/LydwQqp54p8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530926; c=relaxed/simple; bh=63iXi3RlbcS7LLK+SZnZtPzbuAZ+oqm7Kmw//FFFVyQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=opt/X9B63QF+FDS9+8h59aLEbF9/aAXhYuhNblMgh2hHJPJOh47Ps5Hsn9j2Bp33RiJp+kV3g4RMZUseW7vG5mKwmqnHMQeWHP2/2az1vXdGYE4xnVdjiwG/HqKVLerTNk+IYVFeGUDbxXhnWI+Y6Kggic8CjnazhIZfWFCWKKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=NsIEfgKB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KTX+Y6y9; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="NsIEfgKB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KTX+Y6y9" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 38FFC1140265; Thu, 5 Sep 2024 06:08:44 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 05 Sep 2024 06:08:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530924; x=1725617324; bh=HrD+6UAk08 MaoGQtpSY8lxshGKKgOVPAawhHHoV51sE=; b=NsIEfgKB/Ks9ZMcWT6FLelq5Q3 Ep5lHFA+YqtCigd6upaEIFenYpr5Y9Iff0lb/bogC9kH+1PxgCCyQmC9ojLn5XFJ 7BlMEzwewco9C9h5AI1yj2e8Q4pOw4cQPynGren6BKI7M0AQEQyZEatQ5FbMQBAc 7r9N8J6aF2uHS0e9VJg4WZ3AwokjATRJqdjsWmfReyhJpoaeJljkIZik3jNYdUAN GoYF2cAhQ7OkevruG8akGS4b2UKZ2Qi5qOnAyFt9fZl6PedzEi35T0xTeJjo9aGX AJLQswxS68oiiBY8XZ1zRPFl+g5JDNESuJOfFEKQWmp9aOpvNodv1UsPczUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530924; x=1725617324; bh=HrD+6UAk08MaoGQtpSY8lxshGKKg OVPAawhHHoV51sE=; b=KTX+Y6y9ra/3f55j1bJ3fqh+xzlkz5lOSUZRPv3c+OWD NLMxcB0xVR/FIuF8zJpO7rrT6xUMxiyZqN+2+mgbEC9x97YWUaFmiZolXWrEqimg M5aJwPD7ruokFaUF9gmNmCEITSCw3Sg4r1V9GYojc43z+XqQeAR30hKVcSs3+tdz N6CmvDMfq87s0X4zcucbVOvcuChhfEr59RKET+lH02Zidb5x2WaJ6/nWm29DzRt/ X7k56LeWrW3QLDlTaxfp3Ckxpds9SiRmxOcmYMOg+R8cY4n/YFkG9fqhGvG2uLMR yinxQhG4OJ0dHg0LI/agmBhyhJ+zgJUAYCx8N3+V8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehsthgv rggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrih hlrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgt phhtthhopehtohhonhesihhothgtlhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:42 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a359f351 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:31 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 02/22] fetch-pack: fix memory leaks on fetch negotiation Message-ID: <611a29d1ca30759b7c91597a580d93578382955c.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We leak both the `nt_object_array` and `negotiator` structures in `negotiate_using_fetch()`. Plug both of these leaks. These leaks were exposed by t5516, but fixing them is not sufficient to make the whole test suite leak free. Signed-off-by: Patrick Steinhardt --- fetch-pack.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fetch-pack.c b/fetch-pack.c index 58b4581ad80..0ed82feda14 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -2227,7 +2227,10 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips, trace2_region_leave("fetch-pack", "negotiate_using_fetch", the_repository); trace2_data_intmax("negotiate_using_fetch", the_repository, "total_rounds", negotiation_round); + clear_common_flag(acked_commits); + object_array_clear(&nt_object_array); + negotiator.release(&negotiator); strbuf_release(&req_buf); } From patchwork Thu Sep 5 10:08:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792078 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADF71198E89 for ; Thu, 5 Sep 2024 10:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530929; cv=none; b=SRdXEoMGx7pNUVBMklAveSnuRf/g7Xr2hZUAEf38P0InvUi2ALJKzinzxt/1nF9Nq8oBl00cZGFoDdWedFBpLxM4kI/Kq70rEo3pPgzIPyOHHU451CdJU2uulBrYjy3U18mUuYte6tJD/tcvQxLe4ILlKwvtokW2DZCJrwAAY/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530929; c=relaxed/simple; bh=NmdwQwH70YSI3EZP+4+Gpf+uxPmMSoVE7vtRuyGtN/4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=adjcmLmip0MqjRevA1H7IFSuU6fwUXX8QOp3N8lNv0eZVG5VxCsFLpyI8ViX8bSi5Xb7Dv0o571Xzuw0TqXZp0iJoKpQR+iPtSo63sv4Xb+9KeJL8JF/q3clifVL/zeKz3SY/Qb9cOyUkZTQa4Tme0zy9mlE64LbxRsyQHqGdj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=TCUFsCo0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=R4xTIlos; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="TCUFsCo0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R4xTIlos" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id D6788138034A; Thu, 5 Sep 2024 06:08:46 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 05 Sep 2024 06:08:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530926; x=1725617326; bh=0RP7rwyPbP zTPjPjN1bM0BZAfcyEU45jtjyxDwylACI=; b=TCUFsCo00KNiC6TmQagTis1aC4 ctuNaKHVcD57FFv+s5xmxzR4hUEgjUYK7Nj0zh+rImq/uHUkssCDly8GzEPsIPEg XJywb6nZ31AZwRtaN74qSjCf+RTPd9ILw5hBbNfu51/LQi2bz7EQ4v4Bqd5lhGiS B1kcODQp0nrvuc7VtZZRHB8uurZnGVdcuzXX9FBpRWgsnfOts7auS7jwjKhHwzVi 3EhSggRUmmVf/xqfr9KA+TdU/nWQOOjC/Z+lVVeeTZPMt0M1W1OVTTWc86MSEjev chuuZmwz92UTe23MLpcjggNS8lU0+JAHg07l875KkgJKdVOHVVF7177nOuHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530926; x=1725617326; bh=0RP7rwyPbPzTPjPjN1bM0BZAfcyE U45jtjyxDwylACI=; b=R4xTIlosQUoOO+2q0wZfuRLtKwqoa01Y6qiWaPw69sMa V9yElpqBVpIW3ZXNnfMwbbPLpBUQjR6JzHAb8tiobBDSPJaC9fh25gV+rvaJh3dc DFy7/7utPDgytids9IzoZ5SCb2CWOCk+8BDotmwA6LfFpCdb9Lrm2Cm5KIjrW8AH E3mCXq2Sie+/GrEH4HCmvYQ5MfsXzo1JBIDEjzQkfUB8Vcabt3/CNuhAYFgxEoTK QRPlEFfjzr/soyrrXxuNtWrwvIZTzk07Iwtfq1LoLWwopLT1HlA/vIkK5SK47PoD /PGKLrKN1MPa4wQ6cRCPjOv+siBA1DpVa6QWRPgC7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnheptefhgeefhefhveeffeelledufeeggeefledtjeeluedv gefgheejudfhveefhefgnecuffhomhgrihhnpehhthhtphdrshhhpdhhthhtphgurdhshh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshes phhkshdrihhmpdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtph htthhopehtohhonhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehp ohgsohigrdgtohhmpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomh dprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohep tggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepnhgvfihrvghnse hgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f668152a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:33 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 03/22] send-pack: fix leaking common object IDs Message-ID: <0d969962a39bb48bc1831129fb154997bd06093e.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're leaking the array of common object IDs in `send_pack()`. Fix this by creating a common exit path where we free the leaking data. While at it, unify some other cleanups now that we have a central place to put them. Signed-off-by: Patrick Steinhardt --- send-pack.c | 34 ++++++++++++++++++++++------------ t/t5549-fetch-push-http.sh | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/send-pack.c b/send-pack.c index fa2f5eec17b..b224ef9fc5e 100644 --- a/send-pack.c +++ b/send-pack.c @@ -508,7 +508,8 @@ int send_pack(struct send_pack_args *args, if (!remote_refs) { fprintf(stderr, "No refs in common and none specified; doing nothing.\n" "Perhaps you should specify a branch.\n"); - return 0; + ret = 0; + goto out; } git_config_get_bool("push.negotiate", &push_negotiate); @@ -615,12 +616,11 @@ int send_pack(struct send_pack_args *args, * atomically, abort the whole operation. */ if (use_atomic) { - strbuf_release(&req_buf); - strbuf_release(&cap_buf); reject_atomic_push(remote_refs, args->send_mirror); error("atomic push failed for ref %s. status: %d\n", ref->name, ref->status); - return args->porcelain ? 0 : -1; + ret = args->porcelain ? 0 : -1; + goto out; } /* else fallthrough */ default: @@ -682,8 +682,6 @@ int send_pack(struct send_pack_args *args, write_or_die(out, req_buf.buf, req_buf.len); packet_flush(out); } - strbuf_release(&req_buf); - strbuf_release(&cap_buf); if (use_sideband && cmds_sent) { memset(&demux, 0, sizeof(demux)); @@ -721,7 +719,9 @@ int send_pack(struct send_pack_args *args, finish_async(&demux); } fd[1] = -1; - return -1; + + ret = -1; + goto out; } if (!args->stateless_rpc) /* Closed by pack_objects() via start_command() */ @@ -746,10 +746,12 @@ int send_pack(struct send_pack_args *args, } if (ret < 0) - return ret; + goto out; - if (args->porcelain) - return 0; + if (args->porcelain) { + ret = 0; + goto out; + } for (ref = remote_refs; ref; ref = ref->next) { switch (ref->status) { @@ -758,8 +760,16 @@ int send_pack(struct send_pack_args *args, case REF_STATUS_OK: break; default: - return -1; + ret = -1; + goto out; } } - return 0; + + ret = 0; + +out: + oid_array_clear(&commons); + strbuf_release(&req_buf); + strbuf_release(&cap_buf); + return ret; } diff --git a/t/t5549-fetch-push-http.sh b/t/t5549-fetch-push-http.sh index 2cdebcb7356..6377fb6d993 100755 --- a/t/t5549-fetch-push-http.sh +++ b/t/t5549-fetch-push-http.sh @@ -5,6 +5,7 @@ test_description='fetch/push functionality using the HTTP protocol' 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-httpd.sh start_httpd From patchwork Thu Sep 5 10:08:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792079 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4814C1990A2 for ; Thu, 5 Sep 2024 10:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530931; cv=none; b=pq1+kIahg4lPTa7K7eXAsPBGghYk+PBtI53P7xsEDboaMt8NNIW09GYtoqovjVs5eZCKG4r+wUgI3DjfIKPa8SmW+kLNygzdRt1pSJAdcdWUWedJ62WJwopDtEhcOVFqYa05Ss2pczPZv4OwCAoZIOq3lJbBBnwSk5uoCk4BLRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530931; c=relaxed/simple; bh=6WIz0KxmsEq4YqZdDv8BZapbfCTO97/jvUfFYWkYrbQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ESa3jxKoq7qgEt63rTd/XbizC2TeII7ZdM83iAP66gb2cr1HQ/oIlyVtVAuBIoY6dRyUhU9hu1UaHp0SWTI2VwGEVrnMXh/JmL5/V8jxNVcV1XL0zJzgYmcxORj7w99e4t3wb0zrksJdxGCna+CF5MdfQk7xog7O6cyKl1jv0iE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=R1Jhb89s; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eRQulyQ7; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="R1Jhb89s"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eRQulyQ7" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 6D3881380359; Thu, 5 Sep 2024 06:08:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 06:08:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530929; x=1725617329; bh=N8sIT0MLok 6ky59KH/TRK5QPJZFFmw5Hj88jdbLgu98=; b=R1Jhb89sTSPCrfI8P9Ylb4iCFm dl6uZpAx0cB8GYJQP1PlDwSoW99T0JcoZ1tPpuUze2PcMa0RSl/PwvYz86RCUZn8 tVkBPMQU8TD/BGGVxkujbJeY361khUsqKBGuM+UQ1yywmOlCfmLwda5prOdWMlby uiCd+bSJWLe/kGFx74vVqTj26CzpqIdeOcZvSwa1z8JYNbIyTeNv6yBARsK2Wdjc cmq5D8xvsjTtOMSpROfcLfCuMuB4E5OyPPN2QT2NRpHNtOEAe7M72SVC0v1H0wTw UxN4+66M2/EYz1inkWfM6vZdNqeg1Ijp8nkUrofr/pcgn7PgeRtlVEWDEBxQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530929; x=1725617329; bh=N8sIT0MLok6ky59KH/TRK5QPJZFF mw5Hj88jdbLgu98=; b=eRQulyQ7cXY7RTf551Pv6OOczsP6TYrDRQVUS38VgMr1 uxiu+SP7C1yvpLTWFBWC1j6DhnVQgit4PN/MXgAbbIUAMEBB03DqDAg9dCMolTkQ wZaDUXGZ/4b+tUSsNv1UdR9YySIZVspcR2micN9ALtHZ6FiDXSKFBEpRIQNYSby2 bQaiG7XeF6/Wee1qX2qyRX9sYK9CDOdy66tOCSA2iLrrato+71wde9umBgQ/bl57 fW9Dw5KXdraS+cJxyPXW8KBRiQ+LTpj69XsxW2/B6OFxhIBcjEpsfUe3TUzirhBx 0vDf6rgq0alfTYYBh5KDjlVwh64SZYFegJkUjlHCYQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtohhmpdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehtohhonhes ihhothgtlhdrtghomhdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtg homhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohep shhtvggrughmohhnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id de4e03d2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:36 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:46 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 04/22] builtin/push: fix leaking refspec query result Message-ID: <834a184c855c6e7b788771ccfd6a4f63dbacc358.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When appending a refspec via `refspec_append_mapped()` we leak the result of `query_refspecs()`. The overall logic around refspec queries is quite weird, as callers are expected to either set the `src` or `dst` pointers, and then the (allocated) result will be in the respective other struct member. As we have the `src` member set, plugging the memory leak is thus as easy as just freeing the `dst` member. While at it, use designated initializers to initialize the structure. This leak was exposed by t5516, but fixing it is not sufficient to make the whole test suite leak free. Signed-off-by: Patrick Steinhardt --- builtin/push.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/push.c b/builtin/push.c index 7a67398124f..0b123eb9c1e 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -72,13 +72,15 @@ static void refspec_append_mapped(struct refspec *refspec, const char *ref, const char *branch_name; if (remote->push.nr) { - struct refspec_item query; - memset(&query, 0, sizeof(struct refspec_item)); - query.src = matched->name; + struct refspec_item query = { + .src = matched->name, + }; + if (!query_refspecs(&remote->push, &query) && query.dst) { refspec_appendf(refspec, "%s%s:%s", query.force ? "+" : "", query.src, query.dst); + free(query.dst); return; } } From patchwork Thu Sep 5 10:08:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792080 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E70561990D0 for ; Thu, 5 Sep 2024 10:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530936; cv=none; b=e+AC5VQJrK8rGhGH4DTJ3ihBDdUx+kQ5TJQayC6CABmdWzVsBK60k9jtsOs8KruPOSJEUTa6hjX1SheB3jSKLT4iuNRomtotPQ0HWF3V3ZFXnm6MRuDYXn18ypuzdf0lqPRLZuhCcoeVlMS+Yq5hnOe4aX2VvG8O+zy5DGbbi7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530936; c=relaxed/simple; bh=hLaDXSLIeqs7vwAZZ0T5B8qHjOQvSTyTl7686+5JYQ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nKeIuljfKiY0uMmMfFxxIm36Ri8DLLpoRe2znWHTfcbNoJhXVxJdutuoRDR6nd9RT8F/3lpk7ouIoEUjB0NNphCNvg8Qj9mdP8cYdfakAkJkzZQD0lplLjbwc3jW5JY1cvmz+xkeZ+SRz/NMhUn2mJMl4YNz5hIQOd8CIwH1l5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=fH4DRzgg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HMlYfBs6; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="fH4DRzgg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HMlYfBs6" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 11F881380348; Thu, 5 Sep 2024 06:08:54 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 05 Sep 2024 06:08:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530934; x=1725617334; bh=oDPdQBH9rv zh5gXI25efy7GfVF+L3L2HLBt1Pb7ywhw=; b=fH4DRzggJXFTt2LtsEqbiTUGrI HTV8/LVKXLo2LXPe2YryCsieHPxHXYmM2IrSuUzMnONOK/qoffTgaFcQc5Cows0O tD9MIVvh6Aw/WLZpDGRPWu9wgeRnHRYqgOPK5GD+4JFG7BECJY7gX2UafQsrjUD+ lMXnVH6HKItELNiJcv6VWru9mZY31NpJ62Y/GZLMets/ru3wPj5Tzv7pdLWZjGAh U9Q+NnQCpsUARyalpxLDeJyXtIqJXdkbWn/YuaS8rcS4T1d1UoEfu++tjyvYVR9Q 3xTtDuuglXm66y+TWjtRLSaImYMNhrenfVoFnvgyowqsN522BvtDpb3r4zOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530934; x=1725617334; bh=oDPdQBH9rvzh5gXI25efy7GfVF+L 3L2HLBt1Pb7ywhw=; b=HMlYfBs63W8AZ2QK8Ecvg6n1bA23C1tLoCzjJHV4gT+/ sKUFoDlCKBlrU7VJM1Yw+nCtNRBKy0N9NpOPM4ErbUSD1gh+fXYU3ejPLs+pmcg0 Yy8lmaWTrTOuSP5Dj7BrLeEXqdhghfUEfudx4AHsly7/VhpfpdATMBZECu8Ry1aL WlTRZUmc13gH0MbUc4wTgVnMEuApR0OrgsmM7SIZG4tHFwahldQEeoUF7O+Thp53 srAW3sE5R+9FV2YDo08DKM4lebbNUU/5xsoguefXaMcgYvAwr7vAb502sPEZIKKa G+XioFRvmpL51okgsr5ZmslH1bqJS5/+H5EamiUqsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehs thgvrggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttg hlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphht thhopehnvgifrhgvnhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f65bb07f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:41 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 05/22] upload-pack: fix leaking child process data on reachability checks Message-ID: <17b0c4b577afc0edbedb52299528c89e65ee5a92.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We spawn a git-rev-list(1) command to perform reachability checks in "upload-pack.c". We do not release memory associated with the process in error cases though, thus leaking memory. Fix these by calling `child_process_clear()`. Signed-off-by: Patrick Steinhardt --- t/t5516-fetch-push.sh | 1 + upload-pack.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 9d693eb57f7..331778bd42c 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -19,6 +19,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh D=$(pwd) diff --git a/upload-pack.c b/upload-pack.c index f03ba3e98be..c84c3c3b1f5 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -709,10 +709,13 @@ static int get_reachable_list(struct upload_pack_data *data, struct object *o; char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ const unsigned hexsz = the_hash_algo->hexsz; + int ret; if (do_reachable_revlist(&cmd, &data->shallows, reachable, - data->allow_uor) < 0) - return -1; + data->allow_uor) < 0) { + ret = -1; + goto out; + } while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) { struct object_id oid; @@ -736,10 +739,16 @@ static int get_reachable_list(struct upload_pack_data *data, } close(cmd.out); - if (finish_command(&cmd)) - return -1; + if (finish_command(&cmd)) { + ret = -1; + goto out; + } - return 0; + ret = 0; + +out: + child_process_clear(&cmd); + return ret; } static int has_unreachable(struct object_array *src, enum allow_uor allow_uor) @@ -749,7 +758,7 @@ static int has_unreachable(struct object_array *src, enum allow_uor allow_uor) int i; if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0) - return 1; + goto error; /* * The commits out of the rev-list are not ancestors of @@ -775,6 +784,7 @@ static int has_unreachable(struct object_array *src, enum allow_uor allow_uor) error: if (cmd.out >= 0) close(cmd.out); + child_process_clear(&cmd); return 1; } From patchwork Thu Sep 5 10:08:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792081 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6978C1990DE for ; Thu, 5 Sep 2024 10:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530938; cv=none; b=IB89jOBzHdHq1lgu80lGxlHzSYxT2p7CQ7wwoYdp1M36Jw42YazCgSBPAGz1F5ymqshdUuVL860xpBC7cIRC5K/45ayV7t2wfioMVRYUjnRjQrE93JBQUbrVcrvCFwtT2rzPZcOt9ZFJuUAEtRzi5SjXwgWJ7jAf3dXWG2pXeqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530938; c=relaxed/simple; bh=v2tHYyF0OaP+fdZ/dLl4LGxbzQ81uXq7nuBW9BPwT4Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U3vVgfYIQQnkv3t0GMzAgF7UZchZ12gSO2sYo2ObSFzHpyNuPLqLpOeIzh4YX9BrushOd+Z1651U5wh1fDTixz5Wrqj4CVq7kbhO0o5oFvvSr5DobsFQKZzzNJY2R3iRCB4JKxD81WF04iEYTdr8gmY15lA+1qS63njf6MIGNJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=K4NZN5mv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gSlAV3Qm; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="K4NZN5mv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gSlAV3Qm" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 9F8951380359; Thu, 5 Sep 2024 06:08:56 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 05 Sep 2024 06:08:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530936; x=1725617336; bh=DpeijigHC/ ZAMWDNooI+XM4asMss1AH6mfDAaUuuA74=; b=K4NZN5mvZ1kLwT99a8Vnmuag1z BmU1Sby9QtuGSImONKiUgB7leStrS1TJrs/wV9wUpxOilx/WWQFxfQPU6Ls7oKbP 1dyaSGBWy4TmABmDdW+OUH1NiFuJARTMroS2TnFdkd00nui5I1xoBel/6l5cfy7E h7dlxiRrWE/z5qyJXA/pDMwuqqYM7NAb8ikUyW/2SQHxx17l7O3EN8JTGrDcJtvz 0PCAFG5f+ru+Uknw4ORdzkwk6jtrUm4NjO5c0Jsw/g5pKzmqnK0Zvsq3h3fCev5v mi+NmhmUy/WK51f4WLN2HkeH+qdHr8LcKB2v7cjM7bTFG86VV+ZZox4lLY4Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530936; x=1725617336; bh=DpeijigHC/ZAMWDNooI+XM4asMss 1AH6mfDAaUuuA74=; b=gSlAV3QmcR/PD5lR2MLVaS9nwhyZdyduGPu1oEPg5q/o gZw/H7kBq1O6N+Mef8mrM81NWCKL3/bvkvBATw5EljJR9lvjOK4pUA2Dc52BJmLL GejF7OEgy1Div64gfJsBauIGTHvG+82CH6OqG4/Hy76zrD3/Ly0MBuQWlViRWdY+ FRBk+ZZJA+6TAgyW/4+x0eohI00e4zvFaVVMkbVzyRNWw6twZ3wFB6hfn8YQtKhm MxHeSz4fjAcYJ6bSU1wp1L4DPSVpQfG+IBo57Xk9tNCE32Hid0UIaUX9+ukExHX1 BcPWZdanat9mqwdbPd29nSqkbcuLpZJxOchi25KCwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehn vgifrhgvnhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgt phhtthhopehtohhonhesihhothgtlhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:55 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8cabc077 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:44 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 06/22] submodule: fix leaking fetch task data Message-ID: <872f39faece60cba10aeb4606fd3ff28b59ee568.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `submodule_parallel_fetch` structure contains various data structures that we use to set up parallel fetches of submodules. We do not free some of its data though, causing memory leaks. Plug those. Signed-off-by: Patrick Steinhardt --- submodule.c | 2 ++ t/t5526-fetch-submodules.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/submodule.c b/submodule.c index 97516b0fec1..97d0d47b561 100644 --- a/submodule.c +++ b/submodule.c @@ -1883,6 +1883,8 @@ int fetch_submodules(struct repository *r, out: free_submodules_data(&spf.changed_submodule_names); string_list_clear(&spf.seen_submodule_names, 0); + strbuf_release(&spf.submodules_with_errors); + free(spf.oid_fetch_tasks); return spf.result; } diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index 5e566205ba4..2cfb5bd6bb1 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -6,6 +6,7 @@ test_description='Recursive "git fetch" for submodules' GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh pwd=$(pwd) From patchwork Thu Sep 5 10:08:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792082 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02B031991B8 for ; Thu, 5 Sep 2024 10:09:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530941; cv=none; b=Lljk9CqMBhxhYml3qsmU+8kTmUNVerXD4pHUsJlgOinorklrNUoF3wQxp7d9qiKGXfWvvvgG3t41NSQomj8dOMpcG3/6uCMEXJJSwa5bwiFYu2W8V18eyyl5bzVm2REoY8uvqtKCBWve0bsp7QtZvKV3yFkvr5b3eSqRnHvXtVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530941; c=relaxed/simple; bh=YKNGebA9jp/NpJS2wMCJeJrVLU9GQyK/nY4Eub3yMF4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Jh14PiUWcNipTcPgQRm4nHWRygs5186hZphuauTP/ZRWZXinzqelPsh8myAa+egL1m1+yaHnEcQtnITJU7PC/Wm6CQTyq+kdcKgyeQcRx5jEV6BdIJU+1OoGyRaaARTw7/zOYKN/LthqVKZyZfjikNp3pMdBFJ6UMalHN1XT1vs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Ky7Xv4j/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lx3poeN7; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Ky7Xv4j/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lx3poeN7" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 370C71380359; Thu, 5 Sep 2024 06:08:59 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 05 Sep 2024 06:08:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530939; x=1725617339; bh=3PSaNP5gKj DUZvLPOpCjWQQNepInVNVeiBWq3w9WNBg=; b=Ky7Xv4j/Z7ltfP9o6nv6Cxkx+G RNKag+bqC3mopvK399XHKnhQOjMcOeFiCPTZmmw2rbLZ9dZ7kHgbccDGmUyWOERj vxLTb+WhdCR0JAKoyaQ4C3xO/oiL58t+DWBlzJOjUvQwr7QY8OwWnmiq9rWdy/6a XMUCbw/xxqG9/YfOc8If72KH0taayU1UXcZG2pL0wLiowRUn+3vbD1GAmKQkZKVs keFqW1K4N/ZFPCVIQsdsquiLyOorzUmcVnnOkiu0pks1sBhXsp0Fcefw2eaRBf0w UE1yIOxyikfxEWzc1mPS/i0mlahLIiNgEr4oq9JGUppx0ewozGRGdEIJtezA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530939; x=1725617339; bh=3PSaNP5gKjDUZvLPOpCjWQQNepIn VNVeiBWq3w9WNBg=; b=lx3poeN76jUQl9bbN1gq33FYr5JzckyYsxp/hFT0BmyL 1CkXaDKxTP0F2WaeRHLyokVEuvLNN5AFlRS6wWJhd6E8po8C+uLN4xM5ECJiz4C0 w5MdM/PMT17pzy6tR+82gOi2WgGjaeji4bWmLWRnGlRKRLW0Qy2KxbnFC4fg/kCn H74BFHN6d2Lup0L10pQwy8cC0qjDQyAiF690KVL5sMWB6Vxo7Yx2l94Hnt2Co0nx s7hAfr7/jOASyfSO7wu68+JuF1m+bTfoMMymEFmNKW8q6BHTdhUjsAk0UuivH6jY Ebw1RlU4Lx2MPUe4VvhHMzmXS0dxVNZ54oOgPt9YIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehg ihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrd gtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:08:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1fa9dc0f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:46 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 07/22] builtin/submodule--helper: fix leaking refs on push-check Message-ID: <3cbd6fe808eb934407c031faeece08459531c487.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In the push-check subcommand of the submodule helper we acquire a list of local refs, but never free that list. Fix this memory leak. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 2 ++ t/t5531-deep-submodule-push.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 85fb23dee84..642a0edabf0 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2958,7 +2958,9 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED) rs->src); } } + refspec_clear(&refspec); + free_refs(local_refs); } free(head); diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index f3fff557447..135823630a3 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -8,6 +8,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' From patchwork Thu Sep 5 10:08:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792083 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEB591991C1 for ; Thu, 5 Sep 2024 10:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530944; cv=none; b=s8Agvf9BegOm8kQc/ID8S5JGoiQKNMgppCXWRv4V9vQ4TwjC2euzYvphlHeCqZ6d9pP+uGZiVCxTwpP90azT1JHWfGHfcUHxDiyVzrLS4RBzcEHmeMzbgJN0SZ04IhQ9mxABovWYtuRLaiwdVeDen1AeYbZPAcvw3D25/A0hnyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530944; c=relaxed/simple; bh=rdauaC+lZD8YvtFKTmJvi9KJXvoywRbJ0YoFdi7k0Dc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bWe2z0rY44pyzs/DQwmkkhweZbhsHljrPY/EdEBPu9ygswTcLno2e5cRbcUWURR6OfvT6xuXSXE8dbWH4v13yykYDCCtHMsW/fYlpZYbb2RvFilWPimjGxI7huJIli4tiln5T53WoD9DFZ8SsbHP4i8c6+1vkaxBlk3g+K5m6iE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=oe2HM6+m; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RZTwuoTx; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="oe2HM6+m"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RZTwuoTx" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id C482B138035E; Thu, 5 Sep 2024 06:09:01 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 05 Sep 2024 06:09:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530941; x=1725617341; bh=5MglUoFwQc 9g1+mFtCZkCebJLAZvATufZcbGnBTlQGk=; b=oe2HM6+mhAUALXsoqNoJPgU9PY 4ie20Fds9qWi6S7O+tBilHm/AGQj412LdSz5NS8cgjZzQnNkWDKQCpLN2ALoJOc7 Vl6sTTMhxo7rskEhGv23aJ1sWTFBc1UwzgAZdMEoM0HUCwLvzHRmC4KDbZ++QJVb VEWHMSMqlsPOXxJK8jlqvppjALh5gmEhSL00BUyXA7jyAfoZBby357uivIHMJSOL m0BrMkLWckSwqZa8H12f0WjJtJbvySs1z7tzTORjkIbGUz3MMiD3GR5opIYFt/P6 x2wisy9+nzWIciD1wnbdQIEYr2cas1VOiB+rC21fUEtT2XLGrR6RCKfzTPTA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530941; x=1725617341; bh=5MglUoFwQc9g1+mFtCZkCebJLAZv ATufZcbGnBTlQGk=; b=RZTwuoTxxGOCr3bFtBKFZ4EI8jjMXZjb3Pwf3qr0zvVM IATRsWP9yFY7bGo7Y3iuns42GDLLH7fJ2CCnxFFpdXjEyCwSDeSk8gqvCzJnTnqL PhqTW0QSCZ9UNPc4xVH0eUy8X8YA7nyToKzUWzBoJzLW3jML6aMlQmv33sE9ccRw 5gMrmbvlPe2MCPgQAaATk7pgKQuWQ6o/BvvyTa7VRzqGPWeKGefWV5/N3B6k3BLO SBSU3GblvrCK95VpLt7gh/T22W5ZzZDM5kPailPwY3b946HeIqQNrBbyNspO0bv8 jREYKWeR6cIj9AyiRcePUiWSe+QV3yyNMPCpJY6H0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehsthgv rggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrih hlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:00 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id dc509d3d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:49 +0000 (UTC) Date: Thu, 5 Sep 2024 12:08:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 08/22] remote: fix leaking tracking refs Message-ID: <90647301de58b519f36fb0d677ed7be99924769b.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When computing the remote tracking ref we cause two memory leaks: - We leak when `remote_tracking()` fails. - We leak when the call to `remote_tracking()` succeeds and sets `ref->tracking_ref()`. Fix both of these leaks. Signed-off-by: Patrick Steinhardt --- remote.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/remote.c b/remote.c index 8f3dee13186..240311619ab 100644 --- a/remote.c +++ b/remote.c @@ -1123,6 +1123,7 @@ void free_one_ref(struct ref *ref) return; free_one_ref(ref->peer_ref); free(ref->remote_status); + free(ref->tracking_ref); free(ref->symref); free(ref); } @@ -2620,8 +2621,10 @@ static int remote_tracking(struct remote *remote, const char *refname, dst = apply_refspecs(&remote->fetch, refname); if (!dst) return -1; /* no tracking ref for refname at remote */ - if (refs_read_ref(get_main_ref_store(the_repository), dst, oid)) + if (refs_read_ref(get_main_ref_store(the_repository), dst, oid)) { + free(dst); return -1; /* we know what the tracking ref is but we cannot read it */ + } *dst_refname = dst; return 0; From patchwork Thu Sep 5 10:09:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792084 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 053A1198A33 for ; Thu, 5 Sep 2024 10:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530946; cv=none; b=KfDpEeWPHBxQVBOBNeSSGBxzrqm6gbzzmin2vED3y6z8siHyZn6p/u39L2QKK/gMn+vrEdd58PqLBf1gOS+8qJyGB9s8AxKFEdnNrZ17XYTgZQqXFQohWdoVaqjoeoB9miO3Y1tYSlUqW2U17H8YJGqjGUiE0LA/+RfWPpAQFTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530946; c=relaxed/simple; bh=GVAqibZzTpMcbZ9XGxRDO2nb3C44a6bWeOKJjV5QgAI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gqOFmRvD2C9eiV2im2JNk8Lxzh8d/K1J3vteqxx8tQqw1JC5BWGNezw/9BuMU1dGpwxTrOK46BIplbv9YBwY+7RLXtPf9X30T6t85ia4F3EGbzCJfe7UL6Gi5nGPbc938KF9ZhaEGStNP3SORVzV+ljCd4H+Ctb5X1OI0b2Vil8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=TuRyuHnQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=s4EYRHma; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="TuRyuHnQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="s4EYRHma" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 58F141380348; Thu, 5 Sep 2024 06:09:04 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Thu, 05 Sep 2024 06:09:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530944; x=1725617344; bh=oIs7KZuDCP xyYGV6zg7T/9yxfRFPsHn1Y6vd7hOuero=; b=TuRyuHnQwIYaEILk95IDIj9jtw MII5ekShZ/fbyo26XlXJZtoaBwTJySrKPwMpUYJsNiHnega8vvsVkCJwKbzoOuGR Nvylm1psrfy/Eozgv2RzxbHF23RBQV+cgSlRAK2thzfCUxDnLPY+OQhvg2Fj9JgB jYaiyDo2Ng/NPpPut/QF4G2c945hY+3byVFbC5I9JrCbo+KHnV9i1mHLjI7l5/U3 RXwkLlOe5/Cgo7GERGu3yAEJBOSNYIP8Yx6Fq8Xe0tGkb23Mwuame6UzY78WFYi2 mO3ztwSYoSQRpP0HVtbCjfmXTIC8FqUHTVoo1pdVYB1xmaRwtztCMBdxig4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530944; x=1725617344; bh=oIs7KZuDCPxyYGV6zg7T/9yxfRFP sHn1Y6vd7hOuero=; b=s4EYRHmayRIdW3uaEaS6khpqKpyl5mWoauIcf/gdYRz0 06kmBqBnOmcRb7STYGnkfbPXQ735xp69Z6WRofFOGZKhKrywQrZhCDkld1aylyeB B+gbHtxATFFtznHMUzBIffBvq/WFfRjRJ13d9F/truMFzLwPJGNF9pjLyhuTXT1T k3aVA1bKdO1H2P2+Lx9igM8A9e/7NKxRnYJ60HtvPoFALfeib34y8XuhW7k/Sh86 HU5aWSZbwuRXZ1aE3dFpDqE/W02fGX+PPbCwPa0nsOaUvsjgBBI6hVSO3wdDhDDc gkjYs8wsYxnlY6/A2d+Cqp0J01sEnReiL2O0riCoDA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtohhmpdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehsthgvrggu mhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomhdprhgtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgtphhtthhopegt rghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:02 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 24ba5407 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:52 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 09/22] remote: fix leak in reachability check of a remote-tracking ref Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `check_if_includes_upstream()` we retrieve the local ref corresponding to a remote-tracking ref we want to check reachability for. We never free that local ref and thus cause a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- remote.c | 1 + t/t5533-push-cas.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/remote.c b/remote.c index 240311619ab..bff54046b2c 100644 --- a/remote.c +++ b/remote.c @@ -2774,6 +2774,7 @@ static void check_if_includes_upstream(struct ref *remote) if (is_reachable_in_reflog(local->name, remote) <= 0) remote->unreachable = 1; + free_one_ref(local); } static void apply_cas(struct push_cas_option *cas, diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index cba26a872dd..6365d99777e 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -5,6 +5,7 @@ test_description='compare & swap push force/delete safety' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh setup_srcdst_basic () { From patchwork Thu Sep 5 10:09:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792085 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E065E198A33 for ; Thu, 5 Sep 2024 10:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530950; cv=none; b=ECUraMd5WwgYj7Oij0c+4anoE2iCIv4eAXHi7yqhKf3vAGf2laE39v+GaGARZbBPbHyyDYGT2WiROpSFI+BtZ8vWyt8Z3Xt54XIfYkLi1L3jHcalGxEJEHxyCklzTTfjLd/MXyQKd9Dzpbwa2oC8I7GG7DsCQar1SXxz7337NRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530950; c=relaxed/simple; bh=3jNulDoEtszGX6IKGHMO60P+FD+bIrdOXyjTWR7fWEg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UerLodECRxhFq+00O9Vf/1DxADkTyHcg0rbNVW7JNLmtMGinUrkkQ5pQckt+ahQr2eYzaUSSXB7pn2hETo7pCP9OWZkbc/XqOAgs/FD4UzTttta6eTQ9iXADRXq0poA5KF29AayPed12Ka/7wnE+Sdjw6n03GpljCN6z7n9oRZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=NFiZSjeC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XnLSIl+R; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="NFiZSjeC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XnLSIl+R" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0AD0E1140265; Thu, 5 Sep 2024 06:09:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 05 Sep 2024 06:09:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530948; x=1725617348; bh=NYrmNutO5j gH0+qQyI30oOFidvbdgYn+jR/j4uVZIKE=; b=NFiZSjeClZDj6Z/heWP8DWkH7b pbnWuUOVWvm2L6SF5SODFqZzpA8BzTKTDi0T7kTPSMN4YeGJhcrhvh+0RWxBtXXr 0dQq7/omv0lFNM2ASPi1k25uq+8YAAftrfRl2kB7563m7Th+o1iqxrPxVzLLPE4k Pv74n1827pObAxApbPreqXOKV+gaDszI6/0t8x75Exc130czzU+iDQiiSuCYY9Qq cI7zxkh06T8q+hwaiyTyPmftoG/ZLBZXWH+JL7pfGGaDi0FJCHRREItCTYlOuIa6 PWQ3t8IvhGaA6swk34hdBQHlx2WTWhgKvBQj+IxAYCAXCBzr5ZIe0Odde4vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530948; x=1725617348; bh=NYrmNutO5jgH0+qQyI30oOFidvbd gYn+jR/j4uVZIKE=; b=XnLSIl+ROPvQAEiqwylRy9to8x6MWDBYHM8ie1W7jte7 RKA4Sn1I+Vi2MjR/xmBPaWicKr5dPso6QoyNgD/ri7k/Orow/HBK0cGxsLEs/LhY QQ+joF1YZ/W7sPMEAwdOuUAgVz6OPiGL/vjkEqt7gEOP+UOI0VPwj8LobvRVhnto CSl15c2mz9CDJ1TSvawrbC/8dIpc1ycmG3fXfHh4bvmb/6wvOzyh9NyNNphAY/6l Pv0KAcusteUig2KSw8p3Pt17B+qf1XWP7r1HRChA29ub8l2ppRJC6KAn/DSgKNcu erCUn1rvNRKUSj+Dg5wL4drm/8z3Ay+bV0lEYo/WfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtohepshhtvggrughm ohhnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrd gtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 86a53388 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:08:55 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 10/22] send-pack: fix leaking push cert nonce Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When retrieving the push cert nonce from the server, we first store the constant returned by `server_feature_value()` and then, if the nonce is valid, we duplicate the nonce memory to a NUL-terminated string, so that we can pass it to `generate_push_cert()`. We never free the latter and thus cause a memory leak. Fix this by storing the limited-lifetime nonce into a scope-local variable such that the long-lived, allocated nonce can be easily freed without having to cast away its constness. This leak was exposed by t5534, but fixing it is not sufficient to make the whole test suite leak free. Signed-off-by: Patrick Steinhardt --- send-pack.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/send-pack.c b/send-pack.c index b224ef9fc5e..c37f6ab3c07 100644 --- a/send-pack.c +++ b/send-pack.c @@ -501,7 +501,7 @@ int send_pack(struct send_pack_args *args, unsigned cmds_sent = 0; int ret; struct async demux; - const char *push_cert_nonce = NULL; + char *push_cert_nonce = NULL; struct packet_reader reader; int use_bitmaps; @@ -550,10 +550,11 @@ int send_pack(struct send_pack_args *args, if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) { size_t len; - push_cert_nonce = server_feature_value("push-cert", &len); - if (push_cert_nonce) { - reject_invalid_nonce(push_cert_nonce, len); - push_cert_nonce = xmemdupz(push_cert_nonce, len); + const char *nonce = server_feature_value("push-cert", &len); + + if (nonce) { + reject_invalid_nonce(nonce, len); + push_cert_nonce = xmemdupz(nonce, len); } else if (args->push_cert == SEND_PACK_PUSH_CERT_ALWAYS) { die(_("the receiving end does not support --signed push")); } else if (args->push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) { @@ -771,5 +772,6 @@ int send_pack(struct send_pack_args *args, oid_array_clear(&commons); strbuf_release(&req_buf); strbuf_release(&cap_buf); + free(push_cert_nonce); return ret; } From patchwork Thu Sep 5 10:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792086 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F8EF18787B for ; Thu, 5 Sep 2024 10:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530955; cv=none; b=s78yVE4opNQo/gRGtWZIBInUl2DU+5LROk2dLZMX9a5M4AGHFXuo1spza9iVw6s8Wk5OcOmrh95t7IKbu+bzURFZDUnjvlHmcIC7CtdPV6eWrDIf5H9FUhxyUGz9A7CsvQ7vFCCE/INTBhtF/jU/ao/2tqOmaXlDfx+bo5oRDRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530955; c=relaxed/simple; bh=ujqtWT3V15sawy++z32Z3WRLHGOu9irBBW4kCSqJv7o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fX4nXFo4u7If3s6vGhMbIJcC07NWkMX6Wi0g4BfVDXBR5dBtU5II9afB2lUDBgn110wmwWA9iRF5FDqnG4h0kiQ7M1UlBsDxcOS3xAgMMrPAmbEWaGD++xrUpIFa2nIrhWb3cjI6DwsDDm13XlaTDrHAqYAq4ZCJdse6LE8ekVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=FE6diLP/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jP5jFbez; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="FE6diLP/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jP5jFbez" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 935E91380338; Thu, 5 Sep 2024 06:09:12 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 05 Sep 2024 06:09:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530952; x=1725617352; bh=kWw3q0QTZR 9BBwcffOcFeQgdGq38RYOJHM0pVyG6120=; b=FE6diLP/a7numpEFe08avK3Qty BWvV+yEWmqY+MHoEjOtrgnPJeSY7eBO3sD5kofYEuCgXToArkJSAc6yRi2yT13Ie 32iHQwxhJwc1y1dn/nLl5J77eOjbJmPpZ7vikZeWyVoJDMRYUEXdus5D/dvdq1tn fikyTKJxck8QYSEjRdDDaGj1k7j/T1aPqYUrESss4Vj3SAfEkk1V91CteI7olXN+ LeuyJE/ogi3INYU6hqaLm91yAANyC61RRFdPQ1wv/kxi659XW2mV3w0c/3gFD6tH yyUgdU/aBtxnaXGRLsh/x5l/CfRw975V7P7zMONpqRrQZh/pXPFFbNFcz9zQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530952; x=1725617352; bh=kWw3q0QTZR9BBwcffOcFeQgdGq38 RYOJHM0pVyG6120=; b=jP5jFbezLtGAPh9gwpnXqspr0YuQrLNAtFgAg6JNafK4 Cj25WfHO77iu4IgbCj8az4DylNFk2FQqpvM/GfDkceZNO9tPXUpxlANJkO4jdzdE R5kE4pa+DkTR2Gxs5h76fFpPrcbvm5elBMwUQp9wc2B6DyO6u5e9yEYSK8sXnTDI a2H565K6tlN7C8tDtcpX6LGr5KBqgj9bYI1q+Ql+eczcGBnAMh8mu5X/JXsQwjmK 1TflKpPl/4VK6zWwQUd/rjO43tORBy0wp0ZYcvFxT91nJOSzUMfdOlvVUQzN/JMT EhkSezKwNB3Waj9A6E2w90AE5mT9O7jNzdMvRdA77A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopeht ohhonhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrd gtohhmpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprhgtphht thhopehnvgifrhgvnhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 92e49632 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:00 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 11/22] gpg-interface: fix misdesigned signing key interfaces Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The interfaces to retrieve signing keys and their IDs are misdesigned as they return string constants even though they indeed allocate memory, which leads to memory leaks. Refactor the code to instead always return allocated strings and let the callers free them accordingly. Signed-off-by: Patrick Steinhardt --- builtin/tag.c | 3 ++- commit.c | 9 ++++++--- gpg-interface.c | 26 +++++++++++++++----------- gpg-interface.h | 4 ++-- send-pack.c | 6 ++++-- t/t5534-push-signed.sh | 1 + 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index a1fb218512c..ab3b500543d 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -160,7 +160,7 @@ static int do_sign(struct strbuf *buffer, struct object_id **compat_oid, const struct git_hash_algo *compat = the_repository->compat_hash_algo; struct strbuf sig = STRBUF_INIT, compat_sig = STRBUF_INIT; struct strbuf compat_buf = STRBUF_INIT; - const char *keyid = get_signing_key(); + char *keyid = get_signing_key(); int ret = -1; if (sign_buffer(buffer, &sig, keyid)) @@ -190,6 +190,7 @@ static int do_sign(struct strbuf *buffer, struct object_id **compat_oid, strbuf_release(&sig); strbuf_release(&compat_sig); strbuf_release(&compat_buf); + free(keyid); return ret; } diff --git a/commit.c b/commit.c index 24ab5c1b509..ec9efc189d5 100644 --- a/commit.c +++ b/commit.c @@ -1150,11 +1150,14 @@ int add_header_signature(struct strbuf *buf, struct strbuf *sig, const struct gi static int sign_commit_to_strbuf(struct strbuf *sig, struct strbuf *buf, const char *keyid) { + char *keyid_to_free = NULL; + int ret = 0; if (!keyid || !*keyid) - keyid = get_signing_key(); + keyid = keyid_to_free = get_signing_key(); if (sign_buffer(buf, sig, keyid)) - return -1; - return 0; + ret = -1; + free(keyid_to_free); + return ret; } int parse_signed_commit(const struct commit *commit, diff --git a/gpg-interface.c b/gpg-interface.c index 6587085cd19..cf6126b5aa0 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -45,8 +45,8 @@ struct gpg_format { size_t signature_size); int (*sign_buffer)(struct strbuf *buffer, struct strbuf *signature, const char *signing_key); - const char *(*get_default_key)(void); - const char *(*get_key_id)(void); + char *(*get_default_key)(void); + char *(*get_key_id)(void); }; static const char *openpgp_verify_args[] = { @@ -86,9 +86,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature, static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature, const char *signing_key); -static const char *get_default_ssh_signing_key(void); +static char *get_default_ssh_signing_key(void); -static const char *get_ssh_key_id(void); +static char *get_ssh_key_id(void); static struct gpg_format gpg_format[] = { { @@ -847,7 +847,7 @@ static char *get_ssh_key_fingerprint(const char *signing_key) } /* Returns the first public key from an ssh-agent to use for signing */ -static const char *get_default_ssh_signing_key(void) +static char *get_default_ssh_signing_key(void) { struct child_process ssh_default_key = CHILD_PROCESS_INIT; int ret = -1; @@ -899,12 +899,16 @@ static const char *get_default_ssh_signing_key(void) return default_key; } -static const char *get_ssh_key_id(void) { - return get_ssh_key_fingerprint(get_signing_key()); +static char *get_ssh_key_id(void) +{ + char *signing_key = get_signing_key(); + char *key_id = get_ssh_key_fingerprint(signing_key); + free(signing_key); + return key_id; } /* Returns a textual but unique representation of the signing key */ -const char *get_signing_key_id(void) +char *get_signing_key_id(void) { gpg_interface_lazy_init(); @@ -916,17 +920,17 @@ const char *get_signing_key_id(void) return get_signing_key(); } -const char *get_signing_key(void) +char *get_signing_key(void) { gpg_interface_lazy_init(); if (configured_signing_key) - return configured_signing_key; + return xstrdup(configured_signing_key); if (use_format->get_default_key) { return use_format->get_default_key(); } - return git_committer_info(IDENT_STRICT | IDENT_NO_DATE); + return xstrdup(git_committer_info(IDENT_STRICT | IDENT_NO_DATE)); } const char *gpg_trust_level_to_str(enum signature_trust_level level) diff --git a/gpg-interface.h b/gpg-interface.h index 7cd98161f7f..e09f12e8d04 100644 --- a/gpg-interface.h +++ b/gpg-interface.h @@ -80,13 +80,13 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *gpg_trust_level_to_str(enum signature_trust_level level); void set_signing_key(const char *); -const char *get_signing_key(void); +char *get_signing_key(void); /* * Returns a textual unique representation of the signing key in use * Either a GPG KeyID or a SSH Key Fingerprint */ -const char *get_signing_key_id(void); +char *get_signing_key_id(void); int check_signature(struct signature_check *sigc, const char *signature, size_t slen); void print_signature_buffer(const struct signature_check *sigc, diff --git a/send-pack.c b/send-pack.c index c37f6ab3c07..31a62e6a98c 100644 --- a/send-pack.c +++ b/send-pack.c @@ -348,7 +348,8 @@ static int generate_push_cert(struct strbuf *req_buf, { const struct ref *ref; struct string_list_item *item; - char *signing_key_id = xstrdup(get_signing_key_id()); + char *signing_key_id = get_signing_key_id(); + char *signing_key = get_signing_key(); const char *cp, *np; struct strbuf cert = STRBUF_INIT; int update_seen = 0; @@ -381,7 +382,7 @@ static int generate_push_cert(struct strbuf *req_buf, if (!update_seen) goto free_return; - if (sign_buffer(&cert, &cert, get_signing_key())) + if (sign_buffer(&cert, &cert, signing_key)) die(_("failed to sign the push certificate")); packet_buf_write(req_buf, "push-cert%c%s", 0, cap_string); @@ -394,6 +395,7 @@ static int generate_push_cert(struct strbuf *req_buf, free_return: free(signing_key_id); + free(signing_key); strbuf_release(&cert); return update_seen; } diff --git a/t/t5534-push-signed.sh b/t/t5534-push-signed.sh index c91a62b77af..d43aee0c327 100755 --- a/t/t5534-push-signed.sh +++ b/t/t5534-push-signed.sh @@ -5,6 +5,7 @@ test_description='signed push' 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-gpg.sh From patchwork Thu Sep 5 10:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792087 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED0E8198E92 for ; Thu, 5 Sep 2024 10:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530957; cv=none; b=Tn1GIYFoQLU8fUPXK9t52AnPa+vsrXqIpDL84XbKRBvyHWWnWpJpaouW1WSuu8d+hLmhgc0Oqg6zM6g6k7ZXFAbUH0wR90u+HnE7udgWWn3HhhTCfzbjxGeTWHYs+MOdaSUuqnOHaaXfJNzdNEDvWEY1lOryxAdSUYKSk51QoiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530957; c=relaxed/simple; bh=6zPjpWr4TK0j8N3Y3dH6yv/43Aqz6+EAHeag5wp1ZFs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rOTAecj3BB4WbE3j337CzyVIqOokhoLBjzJ0KEo6mxH9zSnSn36Y+ZSLkygK//draOHiVr53En2UtS7UvwNBX2GpZK5MMcso3UIpd4ZwGVXAuNJvIq9f+vriKRVGKpDYUsoh/JiDPKfcWLxQM4gmq9DmEi/O6CwdRpdstMNER1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=dRS5RQUN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TQGmxjhb; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="dRS5RQUN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TQGmxjhb" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 22CA31380348; Thu, 5 Sep 2024 06:09:15 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 06:09:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530955; x=1725617355; bh=uJNcX4nM8Q E6wZH+PZIxDeZWyxn8KA2X29CTGWFlHWw=; b=dRS5RQUNSvHOqF9/S3ReSXs6x3 DtKJtDBDAx/9qElqCUFaWatStK05BEgAjEGKk620NLUJ6HWX9Ht9YRc/PyUUirzQ KvAi+VFDNJkbM0kx9PzaiBM75zPu3AjyXD05u8PiwBV0QGjerPNPb9BkriO5PWul cmRdXqeHXJZhpFWzTmDH89Bc7JII4DFSjn6k8HjaOVuSIOOn2NUCpFDbZSDdw7+3 E3s8OAcvh3/BK44OAw0h+y7fAED3iCKE+7m4Tfd+iZg2oPfegzH2YjhnCpRCAowf 5CiX++sLtEyGgQx3nX6wcv9al0CwsWgEhX3L1RSS7uMKOGWF9z8AdQMUzkPQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530955; x=1725617355; bh=uJNcX4nM8QE6wZH+PZIxDeZWyxn8 KA2X29CTGWFlHWw=; b=TQGmxjhbgIOWNB2IpLwhuQKan5/E4TiCRDZ32n3II70G BVqCxTA1G/Vkai+SHQiJQgQqOBlm9Qe+QbmQhRW+PY1cz7NyXiHFILM23M35M7PI N+Bzzm3TnjYRCj3ipzqsYUui6NqelDvdigNmz4zWuoLU1rgMDNcbHYUTH86tMmCE E3tUdGmfK5HmqmOYaDD2OCnKJkRO+bVvdge0VeTGxxgrlObhhsZVr6k6w5M46yZK yr/idOVvg1ZrI8M7Io6feH+eGkelzhYkhUxDGvOr8paJFt1DR575aM45h7Bcv4xw JCT441nvfgxyZxG30ET2wkN4oLl18xC92bwMBwUBHQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehnvgifrhgvnhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvg drtghomhdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgt phhtthhopehtohhonhesihhothgtlhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 13c8e337 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:02 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 12/22] object: clear grafts when clearing parsed object pool Message-ID: <242f6b76db397cddf2b3f1ced69bdd0b36711192.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We do not clear grafts part of the parsed object pool when clearing the pool itself, which can lead to memory leaks when a repository is being cleared. Fix this by moving `reset_commit_grafts()` into "object.c" and making it part of the `struct parsed_object_pool` interface such that we can call it from `parsed_object_pool_clear()`. Adapt `parsed_object_pool_new()` to take and store a reference to its owning repository, which is needed by `unparse_commit()`. Signed-off-by: Patrick Steinhardt --- commit.c | 14 +------------- commit.h | 3 ++- object.c | 14 +++++++++++++- object.h | 4 +++- repository.c | 2 +- shallow.c | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/commit.c b/commit.c index ec9efc189d5..bbef0e81c65 100644 --- a/commit.c +++ b/commit.c @@ -177,7 +177,7 @@ int commit_graft_pos(struct repository *r, const struct object_id *oid) commit_graft_oid_access); } -static void unparse_commit(struct repository *r, const struct object_id *oid) +void unparse_commit(struct repository *r, const struct object_id *oid) { struct commit *c = lookup_commit(r, oid); @@ -318,18 +318,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) return ret; } -void reset_commit_grafts(struct repository *r) -{ - int i; - - for (i = 0; i < r->parsed_objects->grafts_nr; i++) { - unparse_commit(r, &r->parsed_objects->grafts[i]->oid); - free(r->parsed_objects->grafts[i]); - } - r->parsed_objects->grafts_nr = 0; - r->parsed_objects->commit_graft_prepared = 0; -} - struct commit_buffer { void *buffer; unsigned long size; diff --git a/commit.h b/commit.h index d62b1d93f95..5ba0f77b1eb 100644 --- a/commit.h +++ b/commit.h @@ -108,6 +108,8 @@ static inline int repo_parse_commit_no_graph(struct repository *r, void parse_commit_or_die(struct commit *item); +void unparse_commit(struct repository *r, const struct object_id *oid); + struct buffer_slab; struct buffer_slab *allocate_commit_buffer_slab(void); void free_commit_buffer_slab(struct buffer_slab *bs); @@ -240,7 +242,6 @@ int commit_graft_pos(struct repository *r, const struct object_id *oid); int register_commit_graft(struct repository *r, struct commit_graft *, int); void prepare_commit_graft(struct repository *r); struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid); -void reset_commit_grafts(struct repository *r); struct commit *get_fork_point(const char *refname, struct commit *commit); diff --git a/object.c b/object.c index d756c7f2ea3..94ea8fb8d2c 100644 --- a/object.c +++ b/object.c @@ -545,11 +545,12 @@ void repo_clear_commit_marks(struct repository *r, unsigned int flags) } } -struct parsed_object_pool *parsed_object_pool_new(void) +struct parsed_object_pool *parsed_object_pool_new(struct repository *repo) { struct parsed_object_pool *o = xmalloc(sizeof(*o)); memset(o, 0, sizeof(*o)); + o->repo = repo; o->blob_state = allocate_alloc_state(); o->tree_state = allocate_alloc_state(); o->commit_state = allocate_alloc_state(); @@ -628,6 +629,16 @@ void raw_object_store_clear(struct raw_object_store *o) hashmap_clear(&o->pack_map); } +void parsed_object_pool_reset_commit_grafts(struct parsed_object_pool *o) +{ + for (int i = 0; i < o->grafts_nr; i++) { + unparse_commit(o->repo, &o->grafts[i]->oid); + free(o->grafts[i]); + } + o->grafts_nr = 0; + o->commit_graft_prepared = 0; +} + void parsed_object_pool_clear(struct parsed_object_pool *o) { /* @@ -659,6 +670,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o) free_commit_buffer_slab(o->buffer_slab); o->buffer_slab = NULL; + parsed_object_pool_reset_commit_grafts(o); clear_alloc_state(o->blob_state); clear_alloc_state(o->tree_state); clear_alloc_state(o->commit_state); diff --git a/object.h b/object.h index 05691486ebf..17f32f1103e 100644 --- a/object.h +++ b/object.h @@ -7,6 +7,7 @@ struct buffer_slab; struct repository; struct parsed_object_pool { + struct repository *repo; struct object **obj_hash; int nr_objs, obj_hash_size; @@ -31,8 +32,9 @@ struct parsed_object_pool { struct buffer_slab *buffer_slab; }; -struct parsed_object_pool *parsed_object_pool_new(void); +struct parsed_object_pool *parsed_object_pool_new(struct repository *repo); void parsed_object_pool_clear(struct parsed_object_pool *o); +void parsed_object_pool_reset_commit_grafts(struct parsed_object_pool *o); struct object_list { struct object *item; diff --git a/repository.c b/repository.c index 9825a308993..e6fc2c6aa9d 100644 --- a/repository.c +++ b/repository.c @@ -54,7 +54,7 @@ void initialize_repository(struct repository *repo) { repo->objects = raw_object_store_new(); repo->remote_state = remote_state_new(); - repo->parsed_objects = parsed_object_pool_new(); + repo->parsed_objects = parsed_object_pool_new(repo); ALLOC_ARRAY(repo->index, 1); index_state_init(repo->index, repo); diff --git a/shallow.c b/shallow.c index b8cd051e3b6..a10cf9e9d5d 100644 --- a/shallow.c +++ b/shallow.c @@ -97,7 +97,7 @@ static void reset_repository_shallow(struct repository *r) { r->parsed_objects->is_shallow = -1; stat_validity_clear(r->parsed_objects->shallow_stat); - reset_commit_grafts(r); + parsed_object_pool_reset_commit_grafts(r->parsed_objects); } int commit_shallow_file(struct repository *r, struct shallow_lock *lk) From patchwork Thu Sep 5 10:09:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792088 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 997491990A7 for ; Thu, 5 Sep 2024 10:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530960; cv=none; b=VeVbGz1YV4tEy+mR8RIe7ROQAygBMGIQSMZSMFXsLYv2xz6JF6CQPQYj+nQIn3npTpi3PhF2H/02ibZnhxivpsrvWZVmdh5ea+uwirXhtfn0wxcIyGZg+PpufZZLCZZ4xbwUGajiMl4nsLwARxla6XyyHWAPA4y2FVjesa6Yn6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530960; c=relaxed/simple; bh=CiPrT9Lv5ZmDA3iI5uFH9UoeIHMd31aUeAlNF0PhILE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=luw2KOo3uj/E9jH82NzQZf9Y4MU+axlSfZgOhhheov43er0QHFMEbjFJdw61gV2TflLJ6gomKr4zL64nUXcwOH8ocOEeSU0zBU+M1LFqCqdhD8iQ4a/+xxxH6OWL98+ZB8w3LE6cInIYzY9Udn/V2l7NUophy7LIuj7VkAAA8us= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=joJbIRE7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mWfCJnY/; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="joJbIRE7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mWfCJnY/" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id A61EA11400DB; Thu, 5 Sep 2024 06:09:17 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 05 Sep 2024 06:09:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530957; x=1725617357; bh=5H237q3dmm 8m5oMw3ClNqlwpvtO7Zp/23dAOnNAg/jI=; b=joJbIRE7V8lesuUjBYG4qP7T/g tcjoJ+m9pYfUpkXBMaWSZbxHZo++5wXm8YbNgpmterFP/GbvJnZM7Jlr2gaVlLIN xwSNYHTDnvowYFO9V7yeaiJAiH9XnJUJ/o7qpyovQXA355QPt5YOz8uwVt4xYz86 eAPV5dTvEzLuGNJj8DhqYqWqqEB3mq6Rh8caR89n5MjZrKeOY/nyM4HLoEIWqPnY WKM/NhbSI6Sk2llTRizcdS8PuT0FO86tTPHGxxkt7I+Zxnp0SryEmFq/GXTJFCG8 cT+2rLluv8OEqR4qqXj5XrRKoKcyS9afA6MBPkk0N/eJ4zPGXzqJgOCtgnUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530957; x=1725617357; bh=5H237q3dmm8m5oMw3ClNqlwpvtO7 Zp/23dAOnNAg/jI=; b=mWfCJnY/Qfg7c6PbGHaC9rXeYgWOtTUUFAzNp6cb1sxd 91igGAycfkfVLbG20Fq6GtOsfYzc7Q/s87OYKX6b4B1kDT96fK7z5vzIFmN4NvdA fZOoBWEKvdBN8HJY9l/WM/i00QmsfW9pEKC9BTiEAr3OQF4vSY29UnxDXGRPubj9 vWaRsLjXFJADFW5JXdraSZ5s1v1pur0RT52WRyWMgl1gmS7UUPmkStdtVbcjvBDk LM6HcQFoMXBs0a4FTu1FKjkGjw3h+C+fw567Q0NT1RGm0A98QQFlCYVrY3tgSSQd hlZpi3CaFnimZcyDt0sIi8eDD2Q8JTG2S5JW6hSghQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehg ihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprhgt phhtthhopehtohhonhesihhothgtlhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:16 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4ed1975e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:05 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 13/22] shallow: free grafts when unregistering them Message-ID: <4747042cb6a779c87eef35f23e127795828281db.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When removing a graft via `unregister_shallow()` we remove it from the grafts array, but do not free the structure. Fix this to plug the leak. Signed-off-by: Patrick Steinhardt --- shallow.c | 4 +++- t/t5537-fetch-shallow.sh | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/shallow.c b/shallow.c index a10cf9e9d5d..7e0ee96ead9 100644 --- a/shallow.c +++ b/shallow.c @@ -51,10 +51,12 @@ int unregister_shallow(const struct object_id *oid) int pos = commit_graft_pos(the_repository, oid); if (pos < 0) return -1; - if (pos + 1 < the_repository->parsed_objects->grafts_nr) + if (pos + 1 < the_repository->parsed_objects->grafts_nr) { + free(the_repository->parsed_objects->grafts[pos]); MOVE_ARRAY(the_repository->parsed_objects->grafts + pos, the_repository->parsed_objects->grafts + pos + 1, the_repository->parsed_objects->grafts_nr - pos - 1); + } the_repository->parsed_objects->grafts_nr--; return 0; } diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh index 37f7547a4ca..cae4d400f32 100755 --- a/t/t5537-fetch-shallow.sh +++ b/t/t5537-fetch-shallow.sh @@ -5,6 +5,7 @@ test_description='fetch/clone from a shallow clone' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh commit() { From patchwork Thu Sep 5 10:09:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792089 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00E921990A7 for ; Thu, 5 Sep 2024 10:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530963; cv=none; b=soyBUAUFJn8bb3T/M9YAH5gt7WqVxb7DLYLhdGpyskO8gxg7vKI0Bnoki3WG/DXWQweUDvA8onaZhrWjLdmvsoHGcwBIDH7ga0qpeCs+8kcXf61lum5pkERhiq0yUF9imMs6ieEwmM6VUqrFHvX1DqfCgz751GNXdGPr3m4lNUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530963; c=relaxed/simple; bh=FylzJ6t7N4oPQTYzCUApyYbHyDs6GgLd9fem4CdZN4Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fwTSzmjjdQBUoPL4IYzGesnULJGXGHj9GWQO5xHi4wYsVzU99WlVDHyLptxWxBI/qPsAm6AaOpyhpFLbB0vzky9pMOMESiae7K8P6zRSOYgnQxTSv6+38ev30A2RS3sHARNJ6oor6G9cPl/740oz+EDM7WTtzXvEeM+4weLOiLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=I2i932pK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q+LOqQHg; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="I2i932pK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q+LOqQHg" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 34CDF11400DB; Thu, 5 Sep 2024 06:09:21 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 06:09:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530961; x=1725617361; bh=NTxjXGNx1/ 57StEdxRaEzgkrVxehsxakc1i8DSCcFSE=; b=I2i932pKcPci3X7OrFRqKy9mp7 kttpSeQEdh3mjp1ozkDxqTIgjDfaLs1oBtBdGf5VD20NtTAcB6Z2Hl4z/8zKqDE2 faELN8xbiL6YVwZ3qLPS3q/EuCJTFV/BvNgE5Z6fOpkpg0CWdZw4mA6PjgGoop3X vH3pmcbq7u24f21OXDlXXvvV9dnRbBjxM6JuitDT1+KZ9mSmudnO1gKC8A8PJ5Yz 1nmKAjTBVB4IN2yNhotdkk5BTjwun8MzEl1+YjVC1SCzDO/AyIxE34ZIarYSsz4c y0VAh7igJopkd+9vjPF5I2mqKtEZsf0ShzwU1fkVasMcxA/P8veqcZkPU7Hg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530961; x=1725617361; bh=NTxjXGNx1/57StEdxRaEzgkrVxeh sxakc1i8DSCcFSE=; b=Q+LOqQHg759lMXNbIfaHmtbE1JlmINQXJXaoSxKIjn6t iQjFhW4b7yfuMFSD1goKQ4xiK2hoyXVUgOkYTyXnN+lCTUK3NB4OXJVodNz0aj5v GU21+RTgoEaKzcNBUM4P54sP28EX/LHqXgyFPx8L20JEoFID0bvTJldoQCIMe6P6 F38MMfSGWafi5GkACY2SSVjE0AngJq6kW4TGYm9RrN9uc8VpZhkzSRnKRhqafPnS 9EbMmyPR2i6EbCcW4xZy+a2K3mMv2Qn15+joWK7SaIw9EHQ48Wl0p/xWDcgA7XCw +2LEbmx/YbXDg7r2Js/rtjlfX8aEev+g1pcrCHWmSg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprh gtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtsehvghgv rhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglh gvrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphht thhopehnvgifrhgvnhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:19 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c5f610f4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:08 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:17 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 14/22] shallow: fix leaking members of `struct shallow_info` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We do not free several struct members in `clear_shallow_info()`. Fix this to plug the resulting leaks. Signed-off-by: Patrick Steinhardt --- shallow.c | 9 +++++++++ t/t5538-push-shallow.sh | 1 + 2 files changed, 10 insertions(+) diff --git a/shallow.c b/shallow.c index 7e0ee96ead9..dcebc263d70 100644 --- a/shallow.c +++ b/shallow.c @@ -489,6 +489,15 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa) void clear_shallow_info(struct shallow_info *info) { + if (info->used_shallow) { + for (size_t i = 0; i < info->shallow->nr; i++) + free(info->used_shallow[i]); + free(info->used_shallow); + } + + free(info->need_reachability_test); + free(info->reachable); + free(info->shallow_ref); free(info->ours); free(info->theirs); } diff --git a/t/t5538-push-shallow.sh b/t/t5538-push-shallow.sh index e91fcc173e8..6adc3a20a45 100755 --- a/t/t5538-push-shallow.sh +++ b/t/t5538-push-shallow.sh @@ -5,6 +5,7 @@ test_description='push from/to a shallow clone' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh commit() { From patchwork Thu Sep 5 10:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792090 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80C3C199246 for ; Thu, 5 Sep 2024 10:09:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530965; cv=none; b=EWsYdYVgILR/X70AYpMya8kF43ScUtLnK7X4UYdOkJdJGhofrAdZlYB606IAHfywEPCo5kwhQZhn/vLbXQrPJ6OTFVRix0ardijKx6RmXdeWqiU8TxOjm6Ri1EJGDIgM+gsKPQnrLrvFbZj17YO+Kkmur4yy1lStnSFnwT59Nfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530965; c=relaxed/simple; bh=eraQUAUR48ZkU20xsJ++2AoC1B+6Eus536H6aVawGB0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MmPinsyUsHc5cK5G1Vqn5s8u8/06m41sEGfuTh6rqmRIQbC7rdhSqh6cFPYR142ai9zHCPuupElB63pIyXKNBlHvwsIp7FYs+L9kRZs8SD+4Gllq714YOCC6tW2JaJHQZEWHdntoat7+lnojk1j26GpuN2GrRo/JG2mtv9O3Jf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=KT4AhIL1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z1kypia7; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="KT4AhIL1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z1kypia7" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id CD81A11400DB; Thu, 5 Sep 2024 06:09:23 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 06:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530963; x=1725617363; bh=XFShJbJ5du UoNmgFcv7Z3cbPKeHX+PtCL0kcsHu+ujE=; b=KT4AhIL1tkzSJoBrxF6tBjymZW dbP+j05VMPJmQQ1iUCc1BVOgQGyqYGuJMmZmZcRs1dyuO1aPazV8RbOyMP3zJQJt JMwJSNTQfOaUJcJb2syaCB+0rPdEXk46Kb0q+DR3Mw7Z4sqET3FV+jHtfzvgKOAW Sz2yydxl0FF2tF2qfJW8bYmYQ5zjQxVWF0rTjLXv16poggjGmOcpfh61pUxkMVOL EKSeT/RcNGP0IztiVgnqyICU5mLH6XlE2HCgz2ppSbCovyZ8ULYaOx+H00aPitGt 8uDrt97F1V3FC28gg5kHb4HvFeH/a331S2NUO3R1+oNLn0tyOBmqi70VHJ/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530963; x=1725617363; bh=XFShJbJ5duUoNmgFcv7Z3cbPKeHX +PtCL0kcsHu+ujE=; b=Z1kypia7NK1AYGRVz7MKzUDmBNgs+fi9P7HX7MM5gDEe 9IlNKjdrAjSIl6CRoBN1krtfe90vkRW9n7bgyoCSnmiEiPF3L/N1ejD+dEyAfJXh +e3nMcUHpFwhpiHkE37pjNc6aiK3VAkgyZrr84RlTn42776eKslclv3DOrDd3wO1 1f2ChXHgDVB4klMV4Umf+G03ltPSyjHZpYg3WQzeTqQIHRey8pXsudESatAAqt5g 9Ywb0SEU0tAvGbG75C6ccvh4G749apQqM4MZ9rXZy/Jy5k5aIUtaxSK/idtX4X/6 avg9tXmdsXKXV53NICEN3wdWJDO0OpjOirJ6cDiyQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtohepnhgvfihrvghn sehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomh dprhgtphhtthhopehsthgvrggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:22 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d57d9d9b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:10 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 15/22] negotiator/skipping: fix leaking commit entries Message-ID: <66ed1151449aad1d39d0d6fc10844e7938ea9209.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When releasing the skipping negotiator we free its priority queue, but not the contained entries. Fix this to plug a memory leak. Signed-off-by: Patrick Steinhardt --- negotiator/skipping.c | 7 +++++-- t/t5552-skipping-fetch-negotiator.sh | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/negotiator/skipping.c b/negotiator/skipping.c index f65d47858b4..b738fe4faef 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -247,8 +247,11 @@ static int ack(struct fetch_negotiator *n, struct commit *c) static void release(struct fetch_negotiator *n) { - clear_prio_queue(&((struct data *)n->data)->rev_list); - FREE_AND_NULL(n->data); + struct data *data = n->data; + for (int i = 0; i < data->rev_list.nr; i++) + free(data->rev_list.array[i].data); + clear_prio_queue(&data->rev_list); + FREE_AND_NULL(data); } void skipping_negotiator_init(struct fetch_negotiator *negotiator) diff --git a/t/t5552-skipping-fetch-negotiator.sh b/t/t5552-skipping-fetch-negotiator.sh index b55a9f65e6b..4f2e5ae8dfa 100755 --- a/t/t5552-skipping-fetch-negotiator.sh +++ b/t/t5552-skipping-fetch-negotiator.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test skipping fetch negotiator' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'fetch.negotiationalgorithm config' ' From patchwork Thu Sep 5 10:09:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792091 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DFE719938D for ; Thu, 5 Sep 2024 10:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530968; cv=none; b=ag1YbQXYt1Xi7h8mTDP/Bpzq6IztwVT/kQ06Nj5z3UEHBSwPTK6eUyIfe9X61LopBZ2p1CTstTzqF1+LaCXCPmER4NUc6rJKaBKEtEU+iN1lJ9Opcd4LWSwswAFHjXVLtOAEQ1Mu/pxZs8gp8lVvp/6eDlKoLJ1zhAyFh8qN1KE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530968; c=relaxed/simple; bh=84HOOY/1BwEXbQqHLt0FNDWmSDtgDj4Sm0UxGkQRfUA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T0EpA0lhyUs9VHdF6Y+4/4sgZ4gdF0z/gfNoGPU6gYDl4xvxaeySRjpQF3EerOA5Q21CqcRKGf/iRTUNjG0dvUIR45ikqQqAXgAFQ/CsKXV28q1i4xhQtcSAe/2BCApm67jSjeYcnLNbwhKfAOtwU3ireG1IreU9Wwp3X2tg2xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=hGiGFLIB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jWkncuCG; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="hGiGFLIB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jWkncuCG" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 640E0138034A; Thu, 5 Sep 2024 06:09:26 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 05 Sep 2024 06:09:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530966; x=1725617366; bh=rXhjDEdxbV onkdB2KRrpDpg6E05JKW39AhwEM6fxFZ8=; b=hGiGFLIBFqlFwb77uR7fQjYKir p5E061nvQaGGHEZGUXURIfGqSOi0fP3y9wcByCb5dM3Ok50dwcgSeBgO8tsrk0P2 Lwm/uIwII/8i4lekhnQIuG1xxHIFVMx3Ag22pUgc1lklQ3cqVP1yQ5okL8eUkYaa /lxVbPW5nK0UDWoGZj4zp+ZM4GfgGmESEbzt0myHOHBA62AiYMTbWX8axIIoGejp 0E4CGW2H39zOk+R6Pysk7VtM43weUNKDLaPNTI01K2KqEXGNyfr/RzSkCJwLznSH 0zvYTULdYqlHFlBUy7nPqc8tGn6MfkpNY4oAGXHrpht7W4GAYzm2/xu8C6CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530966; x=1725617366; bh=rXhjDEdxbVonkdB2KRrpDpg6E05J KW39AhwEM6fxFZ8=; b=jWkncuCGw7Z5TT3azB7lB/VIdA7QHkzxC+ZVbEGiJdFk gc0Dq2zglodiAU7EKhNcy2cfXsNIV5Kx/ZWawaUojlip2nEQtNNYj5/haZT80f+r kWzwvAnZoXANeYHfpFjoXE3ouCA3nID74gkoMU8HsjbwELrCIF8wSbPS8/BeKk40 dLv0G7e4jsAMbLN8E9lnLjqyuljvH5lXIHx5JfypIPTTCsL55fP6H3Car73CqRPs F1Uwc/ftS9MWKXmT5o6mVA5WRRIkdGGdyW7tV8uEdq2iDFv7xPxapt56lysjWgn+ HWS4lL+4Gh10yXuGWQa5LnZTOz4o2aMKBJ4c9/1ttA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegtrghlvhhinhif rghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrd gtohhmpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprhgtphht thhopehnvgifrhgvnhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:25 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4a3022ce (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:13 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 16/22] builtin/repack: fix leaking line buffer when packing promisors Message-ID: <78c1e5e1772d8920859588c4eaf67faab0b5730e.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `repack_promisor_objects()` we read output from git-pack-objects(1) line by line, using `strbuf_getline_lf()`. We never free the line buffer, causing a memory leak. Plug it. This leak is being hit in t5616, but plugging it alone is not sufficient to make the whole test suite leak free. Signed-off-by: Patrick Steinhardt --- builtin/repack.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/repack.c b/builtin/repack.c index 8bb875532b4..a382754feee 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -425,9 +425,11 @@ static void repack_promisor_objects(const struct pack_objects_args *args, free(promisor_name); } + fclose(out); if (finish_command(&cmd)) die(_("could not finish pack-objects to repack promisor objects")); + strbuf_release(&line); } struct pack_geometry { From patchwork Thu Sep 5 10:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792092 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9242419938D for ; Thu, 5 Sep 2024 10:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530974; cv=none; b=j0Kn7LIhqAlMD3F/CHMkGRjAFRIyIhQmzHxCXtU6VRQ/pveY/LkcvQ9VythRQSweK/BXBGAsfd2krQsD7GrHgphyWRb3gfKzU2y4Vm+PDCNO2/naJ5Hrk9Vi5x4wrUAGqLfyszlzPYzla+pqa0QsaZX2G3Ir8Bx7aQOeTXgK2QE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530974; c=relaxed/simple; bh=UkobPt+kUPJJmSZWlB1xIwYc2IKeEIOwOvTmVu8B42I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XCuPZHa+8DTxiYu62AFwhSaaWcsjgawozZ4hEvUY+IEI0hGLJNKrZE7M+jy22k99Z8Df5X+qBMcRVb/C8a4N1W0YPod6rEFHMI63rdvZnFl/PhElEjOiq78SXlOuZkpFV3k0ZguDR8H1E4ayWPww24YFVwXW53qkKrqW16Mwsi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=RFEXgOJ+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YGlfsB9L; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="RFEXgOJ+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YGlfsB9L" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id EFA3B1140299; Thu, 5 Sep 2024 06:09:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 06:09:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530971; x=1725617371; bh=H3wJk/Ia3P bKA2JM4Qw3J5eyt1/rUcKQl7L/vqWfzmY=; b=RFEXgOJ+6wDDNNfhjD/z+tbRE+ Exd26NyMBGBmvOLVhKoSJKc79Au1Hz4qaZ8n4Zzb2YdrSui12pyxTxxBYWMdz1wG xDkYw0/0pPD5M1WkSDF0R1xuyQ3FrHKoe0n9KtpH45VlgP9A94XSE8Soevb3yAFQ xJh9b0HLyFbs6XbaghDou/wqq4YJb498MxLDckwGxe5PJgvNxCOZwU6QMVhx5ima P/lzU1K8h1O6Vx4tBY3HL5P0h2h/g349qbRtmIKohesUOws/x4baaKdcV+7ea2rX PAZDTRXLcQveIKqqOtaQvBM+fjd8QFm3jZ1y902Jc6fJfz+Fi40EAHdnQ/Ww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530971; x=1725617371; bh=H3wJk/Ia3PbKA2JM4Qw3J5eyt1/r UcKQl7L/vqWfzmY=; b=YGlfsB9LCbvhEa1yOVJyXWDKVawGkNGoZA6H1kbPiYXc X9WLcHJ0ambXINM2aytHcjThpt9WQftRb9SIxQ/Y/V8XD5oOi5+WX6igzXfl+3ck oXpIIJ72JjwIpfBgQwFE4SaX6HGYn+UgcQzpALW6wkw+Qy9DhcHQDTeaP8JRMBQO VdaaaQGdmrespXL08bBYDrm7A9pJlIL2TLys2jEcaMhbxX4b7XFRBBLg1iMVnIkv oNNUoHjvpOTJW8Z6lydy4m/zgCBLh58Zd9ObBBjK/C1VI5+IoZRKmiHkR9Cd9fN/ LkW6EHoiBrOL/UNJH3XOKjnk5uh4g1bVtiYvFk+8PQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtohhmpdhrtghpth htoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehsthgvrggumhhonhesghhooh hglhgvrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthht ohepghhithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f0ed7b24 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:19 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 17/22] builtin/pack-objects: plug leaking list of keep-packs Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `--keep-pack` option of git-pack-objects(1) populates the arguments into a string list. And while the list is marked as `NODUP` and thus won't duplicate the strings, the list entries themselves still need to be free'd. We don't though, causing a leak. Plug it. Signed-off-by: Patrick Steinhardt --- builtin/pack-objects.c | 1 + t/t5616-partial-clone.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index c481feadbfa..ab78d72e273 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -4641,6 +4641,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) cleanup: clear_packing_data(&to_pack); list_objects_filter_release(&filter_options); + string_list_clear(&keep_pack_list, 0); strvec_clear(&rp); return 0; diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 2da7291e379..467c46dccf6 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -5,6 +5,7 @@ test_description='git partial clone' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # create a normal "src" repo where we can later create new commits. From patchwork Thu Sep 5 10:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792093 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F7CE199939 for ; Thu, 5 Sep 2024 10:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530976; cv=none; b=bPyBJqmnWuZHhIm6lCCiH/ssEf+7wjNVpGXiPG0xecYXZ8I2d02Dqh3FQ/cmfGheT7TsU9n/lCzCxxAManTYkaFG8YMz+W1HoAN6jAp+vZNnnsJ57K/Ue8f5xvxp/DKzSJUoXnB076HEmWl1Hscfn5KTxH6Kjtmyk9bhrDR66vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530976; c=relaxed/simple; bh=6HjMh0PC04bLWX6kUMBMU49FQyJ1qHBYkjqQ319Z/UI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cCpsd0LHi2gFQosBpuTLRXDB+Fc7yFn8wlJC9djl6UZieswZikQnvIa00ThN4nDtiuVvPELULH4il1oG2zU/efonfEQclrGjlXtdyfdMkgLZimDdjq7VjgF9U32WKbyTBI+USsOt4ezdDkQiHRjBjWxhdgYFO3WDkgCECOsQSOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=laFf/Pxs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jb+4rbDq; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="laFf/Pxs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jb+4rbDq" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7AF501140142; Thu, 5 Sep 2024 06:09:34 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 05 Sep 2024 06:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530974; x=1725617374; bh=5X1K3yxkDP A6xlYNhmXOiHf+wP9eEYMqFSidkM1JlLY=; b=laFf/PxsDu2HYWt7NuL97XOkcP IqMASauinpQQk3woIQve2XicibD3gQCie4/nu944hTPi886z5xTt/5NA2BQMrrIO xqH5xy7izo2P4GdGgQmUahigG958xy+4QYrI1E20VRXjPPQoF3fSyoSDIsAZze5/ WHj3t5e153ac/cU6Cl4sFpEo37jDjf/D7lFfuzg3JOXIdaiHw9DRTmaR46GOfnaU ZhyX4Ah9qx/LelorqmK+P6t7JG9F1t4gQtqNp9To5p/2+1Z2PXtpGjyNdUnnUJbB YN6CkvkqKMOfJ6Iaw2JSt0oYgYxpweOddQX9BcbMpOmEFZ8D1dtlSr0FPEKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530974; x=1725617374; bh=5X1K3yxkDPA6xlYNhmXOiHf+wP9e EYMqFSidkM1JlLY=; b=jb+4rbDq636QN+XcYisIjJWSQ4qP0HR8lmyA8GqEyg4I K+eImOYk9KGJUvcsZK9T8rcoqmbCX/m+Bo0NvT6EEvYdNLRchzgkr6Q6GQTAiVws wBgWho1O0WBxmucRrFfIm2mIS7Cj8bpH/Y76pqfaQQuxlKIgiFIdH8RQWgarGd81 2OoB3Of863CGU3hPTuIfHHFjXbUdyjdRIGE9X1CM2LwxxIBXVTkycY+4KgzzGCC7 biN/7+sX75TJ5QiOggHj1b8pPIC2ve+u0upg+Nevqd+Hltc5xvKAu6CHs8UfAgTV ndSXxzemnA1z1iwEKM69YGkbUwGu8uaR7PON3mM8MQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptggrlhhv ihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepshhtvggrughmohhnsehgoh hoghhlvgdrtghomhdprhgtphhtthhopehnvgifrhgvnhesghhmrghilhdrtghomhdprhgt phhtthhopehtohhonhesihhothgtlhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:33 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1a3a368d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:21 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 18/22] builtin/grep: fix leaking object context Message-ID: <9fd891f5222163d1cc61281ec9f91e9e35481eeb.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Even when `get_oid_with_context()` fails it may have allocated some data in the object context. But we do not release it in git-grep(1) when the call fails, leading to a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- builtin/grep.c | 1 + t/t6132-pathspec-exclude.sh | 1 + t/t6135-pathspec-with-attrs.sh | 2 ++ 3 files changed, 4 insertions(+) diff --git a/builtin/grep.c b/builtin/grep.c index dfc3c3e8bd2..dda4582d646 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1133,6 +1133,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) &oid, &oc)) { if (seen_dashdash) die(_("unable to resolve revision: %s"), arg); + object_context_release(&oc); break; } diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index 9fdafeb1e90..f31c09c056f 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -2,6 +2,7 @@ test_description='test case exclude pathspec' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t6135-pathspec-with-attrs.sh b/t/t6135-pathspec-with-attrs.sh index 120dcd74a51..794bc7daf05 100755 --- a/t/t6135-pathspec-with-attrs.sh +++ b/t/t6135-pathspec-with-attrs.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test labels in pathspecs' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup a tree' ' From patchwork Thu Sep 5 10:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792094 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BACA119995A for ; Thu, 5 Sep 2024 10:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530979; cv=none; b=TzXn2rmmGiEPykyyzzt9Wg/DkqC46Gi2lLAM5XfbD3g2IZ5st2aaOGFAs73LgZ7sYMWJZ8/XD3nEqFof4pg4b2DAPpBXMTXX1i7Yk06R9+dI4Q00tJ2y2sFigI38zfiGsdOa3dzzXQ+tpzbERW39hlbSMd/hK3tNpRmvV+okh/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530979; c=relaxed/simple; bh=OxOPufwWt4I+Xy6TVpcs4o6LK7uvwjctX6/R0lgP/Os=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Awj/6KTcCDSX19vPTGgB5Fx0Fj53tfkmTu+DkvifRR6+BTVQnPWbhzqyaU1a+wKyy1z5zOiDIh9ySE32dGlPQT1m6KTvyJYl+jC6q2rKWPICUinqwZvctX62YTb42heE6mfX8Yk3UKGTdHNVkwvjd8MoqPCHPLlAyL9XN2G/Aio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=lKigbZ9B; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FoZLBqxQ; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="lKigbZ9B"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FoZLBqxQ" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1A2F21140142; Thu, 5 Sep 2024 06:09:37 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 05 Sep 2024 06:09:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530977; x=1725617377; bh=5b+CqJcTg4 wpeAtbX8NmdmGooZQyZNQpuh8d6eXETFY=; b=lKigbZ9BuxRf052bPzfOxGOwWH Pec5UyhRdlRhsZhDKx2S4bqyb7GOnjYK6hEwBK/GbDEalSAu/YXWsnuSO3qbJsU4 rDIEa/13dprN0ZBYwsjHidcfxPu4rzFADhQ3s6DkIJOk/DFThL5krhmF3HkrK3o+ 3h0PXSXRYF8aLqcfQN30ZElpKsJha0GN5FXIhIs8SGK9MP/8jyDrnYeqrxUvcSz0 g4CBQaf15KlkKE+QyNE3PizNiJOOJDd6dhnR84jRKJdNhfXGEZUyBEuagFr9aGqd aeI4VtqkwWI0FNvgslnhsaJD/qU8zw2NGrZ8cyVEkCschyI2Kv/4QHTQ+FWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530977; x=1725617377; bh=5b+CqJcTg4wpeAtbX8NmdmGooZQy ZNQpuh8d6eXETFY=; b=FoZLBqxQvRcgssC67QwTPU40RZaXJzJyXbqDuVdAORYN OoVUIgVyUxKtcjRc9hisR9lnxjI9NBbw1UoJ43s63XbrJZQ7Mu+2vj6qTMYdBu2J XLzVGTPLY46KZjZSJBNpQ0pFQcNiDksQr33UeyX7gw/6C4t2z8MXqofsX4PgrZzl A3o9wTqOcZzYt8/Cm+E9/WOUsAtEGIjhlHhgaWSYwPvir55P5uRkLROEd8z+2wX8 jlVAqnFix8SAI15XPmV683n4KicjVp/nOHhM2uDkFT5aZSIH68CwMzhnXPgw44al S+Od25kyZ1QY3nPwyZEeP4uCYezgcGrc1HmvYjKqUQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehsthgvrggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepnhgv fihrvghnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtoh hmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopegt rghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:35 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c2aea191 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:24 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:34 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 19/22] builtin/fmt-merge-msg: fix leaking buffers Message-ID: <84b68affa0d8420ee907a6bb1af15c7f37b13485.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Fix leaking input and output buffers in git-fmt-merge-msg(1). Signed-off-by: Patrick Steinhardt --- builtin/fmt-merge-msg.c | 2 ++ t/t6200-fmt-merge-msg.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 957786d1b3a..0b162f8fab1 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -67,6 +67,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) return ret; write_in_full(STDOUT_FILENO, output.buf, output.len); + strbuf_release(&input); + strbuf_release(&output); free(inpath); return 0; } diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 5a221f8ef1f..ac57b0e4ae3 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -8,6 +8,7 @@ test_description='fmt-merge-msg test' 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-gpg.sh" From patchwork Thu Sep 5 10:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792095 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55C37199E8C for ; Thu, 5 Sep 2024 10:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530981; cv=none; b=Z2n2OTY+Vhgg6v87NkFrlY50D0GEVE1B/UQkvADO3kJkIseIIrv0YKExTxTksfJsTMzmP2wGdcEBRiCXViGXkC0lWySom8NzpYdWBUuQVDplhzxFfjTRQtvB29jMBt6amUnP0DUm8udb26eLNSRWhj9ydl9QZ+Jy1iy9jzWtfVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530981; c=relaxed/simple; bh=7r09tD4qMGzpy8PCSDkBIgsA6FB6B9+FSmPT2/vxRtA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W9i/IHWpGusYF/fH6wv9gTUNzD+CkvBchYygHF7uoie9bj4bANIUUc4AELbxE5QNvBkuwqjhdFrG8oZOk+g5KuNBDbME/DNjVqK5wF7htaXhsJ98EIUve0SYHBqpzCrvojlqwrkvbqDEBc16itLrhPJUgoIbLpxaYpMvG7DwpCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Yymfqb33; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UFDGGAZu; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Yymfqb33"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UFDGGAZu" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id B57CE11400DB; Thu, 5 Sep 2024 06:09:39 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 05 Sep 2024 06:09:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530979; x=1725617379; bh=qmmRH7YJtK bQzbOt3DlvUpBeo6T0bXWs3IieHCAb4dA=; b=Yymfqb33xNRMpfLl6bLFODq9se jJN/8WCA4Pl1cKLy+KJSJTNA8FZTBUKgCKjKb2dZeYNeLx20ax+sq50kkX3lVSCM R02atni64mBPXjWVCvAgvXcCkeFXGHkuh7Sqkj0M2XHKnG1y6NCUGFmmmYMc/kJo HOOZmgEQEuvP+/P4mxlMSz/fKks8jidkp17DMS7q3hbwUTry395cZGRhUCON6T+B Xt4isRvq/mmZOq3iJicX1HpnGnieszJA3rME3DNjH+dy/JcRxMcH6FXKxFfLMuWv j/Eemc9Yi9prOWupbvR/4t1ATYgz0pdn18Ce5po2/HCtQlIquwBxHyRRplBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530979; x=1725617379; bh=qmmRH7YJtKbQzbOt3DlvUpBeo6T0 bXWs3IieHCAb4dA=; b=UFDGGAZuLwmkTQvCHzSJR8zGXepNFeNp3pmBV2ADgP9b 1Gn+9xcCDInUhbXm8+JmhwsX1rZNrl9Rmpz1pUeAPM59aoDTK8ezeic9oLmtGa4T ao7X4MZjmyXshYROrCwiOjRDgHf7W76MR99v9zJdP1mC4rRSn/uOBdH3fdL/sVgj iv9gsfjHkYXsfUMOdAvq4Iq3ExCy1HC6dRQ+C/wNZsx35X2OEYbvgRPwzb+lPaQX HKUbcBm3HQvE6LQtUsfSdswxeMXRjNhGa6sFmttDy7X5sJ/U04gxZ19D2QjnUdtC H+WpV+hrCzYWHAfzhme6whH/qkq/K+ECAU7z4VENVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshhtvggrughmohhnsehgohhoghhlvgdrtghomhdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopeht ohhonhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrd gtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:38 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ca18b1db (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:27 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 20/22] match-trees: fix leaking prefixes in `shift_tree()` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `shift_tree()` we allocate two empty strings that we end up passing to `match_trees()`. If that function finds a better match it will update these pointers to point to a newly allocated strings, freeing the old strings. We never free the final results though, neither the ones we have allocated ourselves, nor the one that `match_trees()` might've returned to us. Fix the resulting memory leaks by creating a common exit path where we free them. Signed-off-by: Patrick Steinhardt --- match-trees.c | 10 +++++++--- t/t6409-merge-subtree.sh | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/match-trees.c b/match-trees.c index f17c74d483f..147b03abf18 100644 --- a/match-trees.c +++ b/match-trees.c @@ -294,18 +294,22 @@ void shift_tree(struct repository *r, unsigned short mode; if (!*del_prefix) - return; + goto out; if (get_tree_entry(r, hash2, del_prefix, shifted, &mode)) die("cannot find path %s in tree %s", del_prefix, oid_to_hex(hash2)); - return; + goto out; } if (!*add_prefix) - return; + goto out; splice_tree(hash1, add_prefix, hash2, shifted); + +out: + free(add_prefix); + free(del_prefix); } /* diff --git a/t/t6409-merge-subtree.sh b/t/t6409-merge-subtree.sh index e9ba6f1690d..528615b981f 100755 --- a/t/t6409-merge-subtree.sh +++ b/t/t6409-merge-subtree.sh @@ -5,6 +5,7 @@ test_description='subtree merge strategy' 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 ' From patchwork Thu Sep 5 10:09:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792096 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E332B199E95 for ; Thu, 5 Sep 2024 10:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530984; cv=none; b=paDeDv66pKdCVZdUsy4qlDqMNwF3QjrnbfMTYvURXD9YyNw8TyLSary9/Ai9NDGwIB3fq3ehYbC6vBq/w5YC+jT8neDlm8SnPN6IVeYNtb5NW/WzgwLYxvzb7HFBRxD7brtwVTR2KN0sfiRx3RflKgiZCXsUDsnR2PZeHj1/2nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530984; c=relaxed/simple; bh=rblmIVlmQeoJa9epGSp0XyYAS5PHDIgfn4+UACaO9t8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sr7p/m+kIaJqmdk0Dni3kmVYVOqLDzS0oxNgqOkkddHLp2oJJrh2Elo4R2pHmh0/K59X4TxKcRHrr4axLpbDPWZ7JJ2jcCaotG/2knf8yW/Ugik42/Js1y0Ax9lNLSUEkwObT+Gw9AWftAajv0+Cogv8PwYb2h+PP8zDu9GYtBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=OldrCHra; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gPdXnz0E; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="OldrCHra"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gPdXnz0E" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4532111400DB; Thu, 5 Sep 2024 06:09:42 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 05 Sep 2024 06:09:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530982; x=1725617382; bh=eMUxY7aO7b y7bE+OOsl2DwEqLYDj/Kaz4whM4imcRgo=; b=OldrCHraf8A3Lnu7cGf9HfWqgT 8Z4snguw6QBXVqjw1cdy+clSvO00bAwTN5F5BB9dfcyVhPAjsUq6xD9+vDTdTfjT 17Cw+Y7IXn86CefrSv4t3GM36QQRfcoanU6IOCK+iIUUmKNwrXE1VTiGgAat7Nmm y1Dkzy1sOKlTAP23Ol7S/6Hhw7S3Vfp5jvy30Ofbx5Igr6ncrvPORyQZu8ApJADR z+cHM2M/t4rFpun8ryXvS8VIqICg83JQIRnmX3xdC1GMaJ50UxtLDDaZN6MPnoxy wQuOaAmdgpLgGsMc26RMa9NjZgZAug/b7qKkZ4iwmcnYY4VpHAdJwYAZ9AHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530982; x=1725617382; bh=eMUxY7aO7by7bE+OOsl2DwEqLYDj /Kaz4whM4imcRgo=; b=gPdXnz0EAX5Pbt6X+qBrEPeY7xCVNFf7wZnmyZ+5jX0S BH2xyZCsHw5VhvIjhI8Oz2n9COuD1Ng2q1HWZTy7RZ2fj30BrcmWOYsTjNM4fOBt qFdUAxgKrMfR9XQGAF9JakW4ZYG6jvWA7YTs8OlCBHTSfMzm56TTXn8LWtqjk3Oc zpWbAZXhcg8gAGBO48LicSPsP7a1CqVLoNvrnc6F0mgorvWsPrdI1+em7lvc0Z8j KhHV/h69O2aRuBZ2hiz5qRYeHSz2eh9cNtYWAOIJ9pCo6yMFd5ZGJjth86v16OvY K9sE3/NulIoK5I8d8WSCKwm/ptkBlA3s28e6Z/q+LA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehs thgvrggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgtphht thhopehnvgifrhgvnhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 33a5755a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:29 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 21/22] merge-ort: fix two leaks when handling directory rename modifications Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are two leaks in `apply_directory_rename_modifications()`: - We do not release the `dirs_to_insert` string list. - We do not release some `conflict_info` we put into the `opt->priv->paths` string map. The former is trivial to fix. The latter is a bit less straight forward: the `util` pointer of the string map may sometimes point to data that has been allocated via `CALLOC()`, while at other times it may point to data that has been allocated via a `mem_pool`. It very much seems like an oversight that we didn't also allocate the conflict info in this code path via the memory pool, though. So let's fix that, which will also plug the memory leak for us. Signed-off-by: Patrick Steinhardt --- merge-ort.c | 4 +++- t/t6423-merge-rename-directories.sh | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 3752c7e595d..0ed3cd06b1a 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2710,7 +2710,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt, struct conflict_info *dir_ci; char *cur_dir = dirs_to_insert.items[i].string; - CALLOC_ARRAY(dir_ci, 1); + dir_ci = mem_pool_calloc(&opt->priv->pool, 1, sizeof(*dir_ci)); dir_ci->merged.directory_name = parent_name; len = strlen(parent_name); @@ -2838,6 +2838,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt, * Finally, record the new location. */ pair->two->path = new_path; + + string_list_clear(&dirs_to_insert, 0); } /*** Function Grouping: functions related to regular rename detection ***/ diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh index 88d1cf2cde9..4aaaf38be68 100755 --- a/t/t6423-merge-rename-directories.sh +++ b/t/t6423-merge-rename-directories.sh @@ -25,6 +25,7 @@ test_description="recursive merge with directory renames" # underscore notation is to differentiate different # files that might be renamed into each other's paths.) +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh From patchwork Thu Sep 5 10:09:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13792097 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86829199E9C for ; Thu, 5 Sep 2024 10:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530987; cv=none; b=AkC65rLQ8iHE2tq8HF5k0H1kLFYnUTO+bahZbrP39oe+BhWI6akL22W7tjO8rWCHJccZGJA4qi62h+sniuTnXinVmyV6+Du/4QT094kFTotFMcMVWN2/xHPxYItVpw+OewvFbKKLQ6S0N4AR5mwDwiW2QdJGn4SaXT8nvjfL7kY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725530987; c=relaxed/simple; bh=w8nRoE2GNGJ7UiiPKRXUYY4+URjWQKB134uaMe+/hl4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nm0HG9g7AGf8n6KM746S1C4RobVgmoD5dfwctScWkhlFdHKyszuWu2Q2XV12Hocdblxbu44ZtxBKERkPnNe3Cgz9Ao2twbZ4/ZiZGEQNZ/VAIBr0pzQ+3uE924lE9ds4xv8TniE0Z6bOomz2XMYe8yVRnXxpIAO3nqHB280HBH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Ud0JBrvU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qQHf/bZj; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Ud0JBrvU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qQHf/bZj" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id D384E1380359; Thu, 5 Sep 2024 06:09:44 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 06:09:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725530984; x=1725617384; bh=8NClZX3ow5 IHFqE4ul4j7SyAUEmLpaEshm/2VgeY2B0=; b=Ud0JBrvU9odqlIB9DnTUGLaKNq qTRWqisKYcJHpDYcX5CjW3S+nrgeWc59J8PvpJa3vejzN7cWeJG4iXq5XKZQduzW M/Dp/dinK3Sb1370arJtYn6PBYGWM0lduyDznifVmqKcGfRcbTEdyEBhW1yDwOZS Ze/2nBnGHTUpWvOsb6q13RuNOzGDQcLe9LMnzxxdzGtkdCFnc5XFUGjQ8iRCVoyy Fp9xNKcibgxkJbwUOdjeMFClbZ8O+sFE/oFEvxZSKZdUWftcbrOHDLbr5Iav74qz 2TqNDrHxDVWQsTbhrzGEpfzjwdCqgp57czUnDFYJtpMIcyl4S/7p8aUcDLVw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725530984; x=1725617384; bh=8NClZX3ow5IHFqE4ul4j7SyAUEmL paEshm/2VgeY2B0=; b=qQHf/bZjGj9PaKDvtWTNa7QBm+LMzrxEDyrZNF6dvMWv THo3Z3Xlv0+KGA2epJaQdObDF8csbVZJ44STJwLE9yJTtAoP2iHKCiCkl5pq6U3I 3qDJbaUL2sL75HtXKFlU3HF9SIeTz1kJZm5uhPP6osC/UtP5D+ftifa88NdMg+Ln WUyRQXHPqTeShyz1MFxlzgqx+GgT8lbYK0IdmJ7WXFN+wsyY2ZATnrKxsY5BWa+z 234cqMYYIKCvJG6JiAKJidP1tNPpOJ79XJCaO9D66lcZjALsWYG1nzT3xX9H7x+z I57X+O9rqk1QBc0mcFL0H9xaipD0l05/C0OWcdydfg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehsthgvrggumhhonhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepthho ohhnsehiohhttghlrdgtohhmpdhrtghpthhtohepnhgvfihrvghnsehgmhgrihhlrdgtoh hmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthht ohepghhithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 06:09:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 270e0db7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 10:09:32 +0000 (UTC) Date: Thu, 5 Sep 2024 12:09:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Josh Steadmon , Junio C Hamano , Elijah Newren , Toon claes Subject: [PATCH v2 22/22] builtin/repack: fix leaking keep-pack list Message-ID: <2368924995ff5cbb6b95dcbaa46a7ee18cd52d03.1725530720.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The list of packs to keep is populated via a command line option but never free'd. Plug this memory leak. Signed-off-by: Patrick Steinhardt --- builtin/repack.c | 1 + t/t6500-gc.sh | 1 + t/t7703-repack-geometric.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/builtin/repack.c b/builtin/repack.c index a382754feee..3ee8cfa732f 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1543,6 +1543,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) } cleanup: + string_list_clear(&keep_pack_list, 0); string_list_clear(&names, 1); existing_packs_release(&existing); free_pack_geometry(&geometry); diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index 1b5909d1b70..58654b3437e 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -3,6 +3,7 @@ test_description='basic git gc tests ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh diff --git a/t/t7703-repack-geometric.sh b/t/t7703-repack-geometric.sh index 9fc1626fbfd..8877aea98ba 100755 --- a/t/t7703-repack-geometric.sh +++ b/t/t7703-repack-geometric.sh @@ -2,6 +2,7 @@ test_description='git repack --geometric works correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GIT_TEST_MULTI_PACK_INDEX=0