From patchwork Thu Aug 22 09:17:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773046 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 0E621175D2E for ; Thu, 22 Aug 2024 09:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318235; cv=none; b=lpRgsmZoTQCEJ04xUBWeBcxdcawxlvULIHFZrnuvXRHPN0SvRiaWF5n0ehP8kPv+C5ZwkDHa1ua0xsG8DzcUgdiQm5o0Fdo1NEcsJo8IHLMJhXJJkE4uPVyFmyI3VIDoWvRyozSCO3YCnsSacG6YwfzfSu6GrsOFBIVcILvYZ5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318235; c=relaxed/simple; bh=JSmfvtR/Ct2tqfGDjOlz6UwxLrCiRpmHYB+uixyz8DU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rehx4TEMi7NOXzWtWVNMB3SnYv64DklAYdFk1gmPoQe0rc67wfRpKvoPcTxGJFZxU9wff6fSGHx8NpamQ8/wv3maJ8wSIxZCc0echU8gOOlgQkZy6bEn3nvpeaDw863L07eW0J7Lvtogx4LJboWJFRfMjQZs6vctmK1bJcYZXDY= 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=MB0zx1xe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=O61c4ONM; arc=none smtp.client-ip=103.168.172.154 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="MB0zx1xe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="O61c4ONM" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1A35C1151BBA; Thu, 22 Aug 2024 05:17:13 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 22 Aug 2024 05:17:13 -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=1724318233; x=1724404633; bh=osC24z7dhB sS6tpvNcPKRxMjKSKUX0C6NSUaScxGReA=; b=MB0zx1xe+c4ZsqEt2Djm9yeRw7 yISChTrtqOdT74SLmK0Vqx2QXZ8293F4cNbOy5HHVeUW2ezsr7QiUQz3B8/OF8rZ UdJJH9mBN1Vok2KRNsCQHKJEqncSP4vSmUm8ykZxTbCTUOZK3RwmTc+QAKEMrYDJ rLq0KB1jUypdWzDYCe9Ju0K5yot5FIYA8LAT/rYXWowAJ4nuH3ZUq0iGthBGyfHK jQnkiowSu4iZ6Tqp0Du4RIAzFpF7iAe4zFtCB4KQPWEznHAf5cJZkE67oYPLp+9S ikOQ44k5Cxr9wkZ04eRiA2YoqUbg6mD+T2cXx3PEWcdX6sv5HPtUHWPC58bQ== 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=1724318233; x=1724404633; bh=osC24z7dhBsS6tpvNcPKRxMjKSKU X0C6NSUaScxGReA=; b=O61c4ONM0tnP0q0jvvFpTq1Rg7rRWBHR6k6VxGPbbl0c hwhRYQr8DJBZJls89vIzCqYkFepi2Noqy+XGKEgmHBumpgAde+GznESwD96qGDev kxLUiAbTe38VT8iv2j9snpArIkYRx85LYK3NioPjTm5rN570TEO+VIoMY0ipeRT2 iW+zFMJAH+8It767JBLD1S79xR4JpO4NhxSqSWKPGmx1UqEqBPck9Wk0Kcwh2BlY 9XK0BRHzOpgKwNBIZIUajLByLL3JNQ7glCDAsTMj2ojCkJAF/kZOOe9BMJmn+R// i4TQP6HodGZttFt+oCmXTLqIL1VgYYySct1GZNabPg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:12 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f786c936 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:38 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 01/20] mailinfo: fix leaking header data Message-ID: <69e30ea5179eff6472be54ebba64ebca3e562f32.1724315484.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 populate the `mailinfo` arrays `p_hdr_data` and `s_hdr_data` with data parsed from the mail headers. These arrays may end up being only partially populated with gaps in case some of the headers do not parse properly. This causes memory leaks because `strbuf_list_free()` will stop iterating once it hits the first `NULL` pointer in the backing array. Fix this by open-coding a variant of `strbuf_list_free()` that knows to iterate through all headers. Signed-off-by: Patrick Steinhardt --- mailinfo.c | 17 +++++++++++++++-- t/t5100-mailinfo.sh | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mailinfo.c b/mailinfo.c index 94b9b0abf22..a4fa64994ac 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1290,8 +1290,21 @@ void clear_mailinfo(struct mailinfo *mi) strbuf_release(&mi->inbody_header_accum); free(mi->message_id); - strbuf_list_free(mi->p_hdr_data); - strbuf_list_free(mi->s_hdr_data); + for (size_t i = 0; header[i]; i++) { + if (!mi->p_hdr_data[i]) + continue; + strbuf_release(mi->p_hdr_data[i]); + free(mi->p_hdr_data[i]); + } + free(mi->p_hdr_data); + + for (size_t i = 0; header[i]; i++) { + if (!mi->s_hdr_data[i]) + continue; + strbuf_release(mi->s_hdr_data[i]); + free(mi->s_hdr_data[i]); + } + free(mi->s_hdr_data); while (mi->content < mi->content_top) { free(*(mi->content_top)); diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index c8d06554541..065156c1f39 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -5,6 +5,7 @@ test_description='git mailinfo and git mailsplit test' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh DATA="$TEST_DIRECTORY/t5100" From patchwork Thu Aug 22 09:17:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773047 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 EE08E17BB19 for ; Thu, 22 Aug 2024 09:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318238; cv=none; b=Hbq44KBEqwngM4zyOK3fJC4p9NAjbl8PwhGjlLMBnfCBdjp6T/WfiV+Cd0EVK5jbe6mkJihPoetBa67BFX52n8CwhIxTMVvgCUFZPuFOVmmtkypNi0cLTxu8G1cw13bgicQ45ACaNb9UIQ80vKwd1NEYnwKElHlulbhu5Z4tAtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318238; c=relaxed/simple; bh=otBYJDTv0gRId/5uczKSEggpmDaJ+3GgLHUhS1ux0sg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=txYJwigpQyStZc8GUcqwBML+6ZkZjW6GNY29tj3JgCnleK0eGrSebo4tiAYDeq+vGcDDjkuMfk0AE0rojDdOIa4XjNTA0O0a2rM+1TCzrRMSov/K8CPtJI5vQRl2vrlErcC6ZL9JdeqghwN1E5IfpLC91bnJzrWWdmLuYOo0Lmk= 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=V/7JPfwR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=onICFuIY; arc=none smtp.client-ip=103.168.172.151 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="V/7JPfwR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="onICFuIY" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 1542D138FF3B; Thu, 22 Aug 2024 05:17:16 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 22 Aug 2024 05:17:16 -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=1724318236; x=1724404636; bh=dn6/T2X+tl LtK6xfey+zjja8ro5u/5BaC0FCx5P/YkM=; b=V/7JPfwRVNKdZKW0HtuLwYWiWx VIxfQUmmsG84LQpbS8E51imPJmydaLyv/PDYam8PjREHiaI3ExU8aWGvCamzEJZi /IBZ8MiFxB8A6rlWIs5MW1ZnFXBRjQq0AlJGf3hbKjtY1WE23Q34uutCS5dJkRqV 6q0FCxF+UU3VIujIve8V3YFWhFAMq+qnkd93AoKCLadDbMh3kPKwasX7raoHCMzj qKxBjUo6RKIed7Fc6LaXYNledNi3wzgb29cWyPbRMGVHSyPVwneaTHJppbd6G5pg 6JSuQCr0LXfrwKiZg996VJ1TZoci65ODeyHTogxrwF3ykArXlMVcreCnES+w== 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=1724318236; x=1724404636; bh=dn6/T2X+tlLtK6xfey+zjja8ro5u /5BaC0FCx5P/YkM=; b=onICFuIYvDXj1NtD3yFoaSWnvoSZTdfB6F8ec/cJ0anH nEglcDaCDMQPImFhd8TszQ0mW9jy5KQoEPmy4fW8RMD4c9IgqxUw9veummychWCs rOEBt6lX7jUq9Is/oIlrQc13SKIlpBHFYDPElb9akz5XHFjuW2JgffOrMcdmr5fx /uyQROkWx/0J+tWw7podJ8Y3CqFcXMslY6pZZzVLTtVOsawItn3hXX+BhNwwveYe ayqHWaQJt57Bx5mcluXpMLfFL1xaFA67EwltsQqRCyVLWNUP9212hOyQnLxikFjQ 6AMoW2jiE7xX/Y1vpD70KKaB6+pyfNdnN7ajoaOA/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:15 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 76a48da9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:40 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 02/20] convert: fix leaks when resetting attributes 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 resetting parsed gitattributes, we free the list of convert drivers parsed from the config. We only free some of the drivers' fields though and thus have memory leaks. Fix this by freeing all allocated convert driver fields to plug these memory leaks. Signed-off-by: Patrick Steinhardt --- convert.c | 3 +++ t/t4150-am.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/convert.c b/convert.c index e6184d21f26..c9a31eb4f03 100644 --- a/convert.c +++ b/convert.c @@ -1371,6 +1371,9 @@ void reset_parsed_attributes(void) for (drv = user_convert; drv; drv = next) { next = drv->next; free((void *)drv->name); + free((void *)drv->smudge); + free((void *)drv->clean); + free((void *)drv->process); free(drv); } user_convert = NULL; diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 5e2b6c80eae..232e1394e8d 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -5,6 +5,7 @@ test_description='git am running' 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: messages' ' From patchwork Thu Aug 22 09:17:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773048 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 021C217DFF5 for ; Thu, 22 Aug 2024 09:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318241; cv=none; b=dMuJWuMpUPFOSQiYqqkxNOZzZpqUrSuEA2PJfA5mTR5jLTdIE9VMMFB+fdVczl0ONjSENOrrXTRALcqiSVdlFYnEWbkqz5mrLcaHdnypFnBa18CwFwuZq1w946U9lltANIpHWIeNrTnxMdm2bdfzK22iHG2yaTwQ3PlOgQsPFKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318241; c=relaxed/simple; bh=pBE8DpSvADQS90zjfMIk60gizQly99VD9eNn1SMkJpQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=umpBGUcQ2/gDnn/ilmf5nKwgoqwmZxGBOCLmYP8RPys2KwC+quElhvtnA5L0FT4YV4daAGGXqbE5+1mO2qeNbpuevSdjz35t/juRtiXl+sICor0qUky0j1rass849TD5kTfmDHoTf9Y1CcAR7NdYO1gJCeKlFR4OFvMblR6A+hk= 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=oImLs3Mn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EafBKEk1; arc=none smtp.client-ip=103.168.172.151 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="oImLs3Mn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EafBKEk1" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 24231138FF3B; Thu, 22 Aug 2024 05:17:19 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 22 Aug 2024 05:17:19 -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=1724318239; x=1724404639; bh=5seFfBAru9 ++D3GpBhHiohA0nwaxb4Q0IbTVGtzw/kQ=; b=oImLs3Mnm7elu8Evmer2Hk2tLW LN3ktsZEWcoTX3ZP98hnVr9TL8b64PeSIuvoU+OKyZvppEfXxUUoZ+jP7wnCCiWg Gwo7bt8U8gMP5BdBXY6gRAcF0EvQqQd+Lb4V06QDg0GyoZtAIy9+xv+ZhXqzdtYJ NmEYwgRywyvguEQCZqVEx2z7utNaH14fnpAOHg9LfgUvYG0Bc3HaONWpzNNKElfG sVxpVNgoYUIGjZEcY+7vPdLbDNUebXGmp80bNGPSq1WupIkr2vzBy4v7GwWu17ej Eg64xcNmK1vP3TSWklyyDZ876xmn66jKoXBBpp8GglB8MGR/7UK7d2gOKkUw== 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=1724318239; x=1724404639; bh=5seFfBAru9++D3GpBhHiohA0nwax b4Q0IbTVGtzw/kQ=; b=EafBKEk1PoWzofMVAFTgHbe7V3M8BtxLZm5sKdUekx4I 2IECCIhhscg+0kKrbMvWatcpIQf91/CqYwwyg+XZR1AQH0KOcnLYaFaSezloiZrg jzLD54r1rEGGL3LUHHT2XwrbvnCbsWsrnHQP9rEOV38lnV0lnP7n4d1b+sHkNNFk WYFuChtLbOkIVb7TA3NhED2FRaodKA2xh9fiQpvxDTDMosvgvNdhBs/nsr9SUKXS SHcB6f2bKm/licihIsnl/1taIOp99Sp9zoIV1R7fPIBbQVdc5LyQwzhwKdsnBM0X Q/04MBxTGBo+vVxTfB5hQTyAHlFS7Vy9EDONXtT6sA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id df486a15 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:43 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 03/20] pretty: fix memory leaks when parsing pretty formats Message-ID: <8a1963685e73fecb64bebb1154ad6205caf09a8d.1724315484.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 parsing pretty formats from the config we leak the name and user format whenever these are set multiple times. This is because we do not free any already-set value in case there is one. Plugging this leak for the name is trivial. For the user format we need to be a bit more careful, because we may end up assigning a pointer into the allocated region when the string is prefixed with either "format" or "tformat:". In order to make it safe to unconditionally free the user format we thus strdup the stripped string into the field instead of a pointer into the string. Signed-off-by: Patrick Steinhardt --- pretty.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pretty.c b/pretty.c index 44222fb83c6..5e162d7204d 100644 --- a/pretty.c +++ b/pretty.c @@ -63,7 +63,7 @@ static int git_pretty_formats_config(const char *var, const char *value, void *cb UNUSED) { struct cmt_fmt_map *commit_format = NULL; - const char *name; + const char *name, *stripped; char *fmt; int i; @@ -90,15 +90,21 @@ static int git_pretty_formats_config(const char *var, const char *value, commit_formats_len++; } + free((char *)commit_format->name); commit_format->name = xstrdup(name); commit_format->format = CMIT_FMT_USERFORMAT; if (git_config_string(&fmt, var, value)) return -1; - if (skip_prefix(fmt, "format:", &commit_format->user_format)) { + free((char *)commit_format->user_format); + if (skip_prefix(fmt, "format:", &stripped)) { commit_format->is_tformat = 0; - } else if (skip_prefix(fmt, "tformat:", &commit_format->user_format)) { + commit_format->user_format = xstrdup(stripped); + free(fmt); + } else if (skip_prefix(fmt, "tformat:", &stripped)) { commit_format->is_tformat = 1; + commit_format->user_format = xstrdup(stripped); + free(fmt); } else if (strchr(fmt, '%')) { commit_format->is_tformat = 1; commit_format->user_format = fmt; From patchwork Thu Aug 22 09:17:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773049 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 1FF5617DFFA for ; Thu, 22 Aug 2024 09:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318243; cv=none; b=babpVNl46r22A/q8DWcvxdLqMOZEw9To1NMFbDNDzm2WGV5If0yaILZaf6Y18wFFBk01Vl3+G8VHDCF9oHzOoqRpu/3HC1URwM7MZ6RE6IPdZA54AQ1a/UGGh0ecijoUwDMGbkAuX7Vusq+d94Lz0T1+WAnU2zq9K41gpaIdGYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318243; c=relaxed/simple; bh=fuuaad+LzJ9J1ACv7inm/m10mCKweBOzjIGwHn49G1E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uTpvdaoL2/czyFVt28ypnB2McG5leXgbwIiSIpuctCLmQ3N8HHA9ze3weK3QQv0iNPkOXK/7io75agcRTRYX84naT/1dTq4K6KtwxEwxAy/IwcdWG69QZPHNCzGC2wEJ0ae3dPbCEQOGdGq1wlJr6v7uzDdJAPQfbd+ZpXoBq6I= 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=teCrfAA1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CZVsbe7p; arc=none smtp.client-ip=103.168.172.154 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="teCrfAA1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CZVsbe7p" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3330A1151BBC; Thu, 22 Aug 2024 05:17:21 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 05:17: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=1724318241; x=1724404641; bh=MCNmPwlZVK aOUdZLbwJsg8dSauQ89p0CarHzsRUi4qA=; b=teCrfAA1oixzAxQIKXaVPLChJ+ U8ISILtOgHJIkVZyzq3twmP9sOQphzshKqWZe/fSja1VUtqZtKmB5qukoABtHPYo S3R9v+D4zCniGt/d3WJVNlVJMCimMELlxCTLf4vI0ukvKASwGS9WcJtmJpHoso7e Ss3iYL7f56D8C+mSEFqspGEDDOin/PhXBs8XlORg1aspZ2rQ9CjQEEGsZVz+V0u1 /QC7SKfPpWSdixEYZ3XL5sXIOoDfADWrevu12Vb6iICQlT2zW/pAtpLIU+/8RH1T FZ/fWib3E2FS/Jd81DDZUmZqjLlGl2T/TyeenymZSDhz8Et753PjkRWDfZcg== 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=1724318241; x=1724404641; bh=MCNmPwlZVKaOUdZLbwJsg8dSauQ8 9p0CarHzsRUi4qA=; b=CZVsbe7pK03soVn7UT13xZdUVh0zZVB/kaqs7zQZZvwe MZQ9Xa2g6KiNJR03r8bg8yuDdpjMr8Z1LMKK0ySDrCXuJ2gz/K50pJ5/cq9B2nYL LaE92EljXrJd1Fk18shshMCDBXX5kBz4k3VezLEwXuDBmq6yo1WiNPM+YYyaT1KJ t6qQZiBZUlj+KVzgda9ga5S3SELkgy/jFgXd/rDUlf2ZeDilHkQcrhX2V2yXOv9N vPW11jvXyGJkkernqCh25NcUWI1bQRQy2WJW/ntQRvxIsg/VEhsNhrtgprXQ6+Ce vvNzKdK4KSpupep/ylN+VZdmjYAChpQYtbYHD2x1WA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:20 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f348494b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:46 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 04/20] pretty: fix leaking key/value separator buffer Message-ID: <1c368a4489a23e258ad66b2b10ec8721f7409b3a.1724315484.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 `format_set_trailers_options()` function is responsible for parsing a custom pretty format for trailers. It puts the parsed options into a `struct process_trailer_options` structure, while the allocated memory required for this will be put into separate caller-provided arguments. It is thus the caller's responsibility to free the memory not via the options structure, but via the other parameters. While we do this alright for the separator and filter keys, we do not free the memory associated with the key/value separator. Fix this to plug this memory leak. Signed-off-by: Patrick Steinhardt --- pretty.c | 1 + t/t4205-log-pretty-formats.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pretty.c b/pretty.c index 5e162d7204d..5e5ae452530 100644 --- a/pretty.c +++ b/pretty.c @@ -1776,6 +1776,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ } trailer_out: string_list_clear(&filter_list, 0); + strbuf_release(&kvsepbuf); strbuf_release(&sepbuf); return ret; } diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 158b49d4b60..eb63ce011fa 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -5,6 +5,8 @@ # test_description='Test pretty formats' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Tested non-UTF-8 encoding From patchwork Thu Aug 22 09:17:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773050 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 DE78017C7C6 for ; Thu, 22 Aug 2024 09:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318249; cv=none; b=rKAez2KNkUVf70xGCqwIc3WhmreceFAJlY1HgQqHvkf6r13SuvzjkclLdusnqya6HaUdnX6e+ZVPZE3CqMPy+q8ojyRubrd/lmEV4BpNh4o32aOEsOaCvZwTYlXqX46L5BtCpK1SW9QbD9obg9J55yL4sLssBRUleFb3aEF7JqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318249; c=relaxed/simple; bh=mcRQa9G7hy7QauywfNNmby8ICn9wUCkZYmWcBv9yqGE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L4pEzfGMFhhRgdupgmQ3PkAIzfJPpxaOtTIUA3n4OISD6FHrA7YTf9U11AFC3EsTq/MlpqTHEOGMU/gulxX2KDodxGtZJDhZzYDLEGOWr+UbVgYtUjhNH1Xi0OGtkOOQt+wfX6vN5HIDOcLx5CyDwfkh9qmwTtGqZiLyOcbctMs= 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=jv6GbxXM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bWTrq9+u; arc=none smtp.client-ip=103.168.172.151 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="jv6GbxXM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bWTrq9+u" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 430841390049; Thu, 22 Aug 2024 05:17:27 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 22 Aug 2024 05:17:27 -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=1724318247; x=1724404647; bh=HX6AGxmsBS j0RUbqpwNe1xuthWI35IE6uoPJO6H0/dQ=; b=jv6GbxXM6R2mx1jdoAH1Ri7eIf P27bYDJDLcMSA+JT1QH/0p7btTkSlYUogdPdKehuNfH5vIrs+iULojcIx3CNNOoS K1OkABO5tNYFxAuoiH8kasnQUrlVxtCmxPR65hvUNxpD6JHeUuJaYabIyIHff88Q E65BKa9J+hB660qXdZWwtshww+wdzKdknHuth1IHfsvJfCkfgd1rsK07oVJ7CRH2 8NAp5WGTM9oJ3UB8lEx4CrkpJE+sjRFA3DSZDEWXemXbPGS5MNbsV4nOQMMZa6N4 +6+0DtQd6AJfzvVGvwes7X/fHJ+sVpUIQtCzZZFFb3P4l9NlcSGSs/4vj7Rw== 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=1724318247; x=1724404647; bh=HX6AGxmsBSj0RUbqpwNe1xuthWI3 5IE6uoPJO6H0/dQ=; b=bWTrq9+ulLwGg6o3+uMSPgSQhNJXxdnJS3f6sNprpUDx 40Gd4pf5CtKG3AmBFsEX/UhXP8RbNFMsn1WPBFVf27g3iCX05HYNlLio0HeFC7FF hIBrZAjWE5+C59EXLhmLHq7sBNu9WZmortNxgz5JRinZ2g4jN/efg2Z0/GriPAvm wUw3YiBu6Ejh0iXv66VAgdtqZu2MGR3yI96rjyzwmQUoUZir/XDILLFjrfj36+XT hdpnjrVJSVuS9jVLvlKbvbrHp9PDzAsheck9a7MRUcUvLydTVQ98sgNm6jjN6e6e AuGhHxiklvt08AlGJ7pL6k9DbREb+BoVc1i90uoMXA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:26 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d079212c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:51 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 05/20] builtin/merge-tree: fix leaking `-X` strategy options 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 `-X` switch for git-merge-tree(1) will push each option into a local `xopts` vector that we then end up parsing. The vector never gets freed though, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- builtin/merge-tree.c | 13 ++++++++++--- t/t4301-merge-tree-write-tree.sh | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 9bca9b5f33c..c00469ed3db 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -533,6 +533,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) int expected_remaining_argc; int original_argc; const char *merge_base = NULL; + int ret; const char * const merge_tree_usage[] = { N_("git merge-tree [--write-tree] [] "), @@ -625,7 +626,9 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) strbuf_list_free(split); } strbuf_release(&buf); - return 0; + + ret = 0; + goto out; } /* Figure out which mode to use */ @@ -664,7 +667,11 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) /* Do the relevant type of merge */ if (o.mode == MODE_REAL) - return real_merge(&o, merge_base, argv[0], argv[1], prefix); + ret = real_merge(&o, merge_base, argv[0], argv[1], prefix); else - return trivial_merge(argv[0], argv[1], argv[2]); + ret = trivial_merge(argv[0], argv[1], argv[2]); + +out: + strvec_clear(&xopts); + return ret; } diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index eea19907b55..37f1cd7364c 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -2,6 +2,7 @@ test_description='git merge-tree --write-tree' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This test is ort-specific From patchwork Thu Aug 22 09:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773051 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 E3F4117CA04 for ; Thu, 22 Aug 2024 09:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318252; cv=none; b=AIE7igk65/EXM+K/qpb7MRRLMNDMZfrg3OTF7nydPvAkikmfu2D+vmGjm3kTS4HutlQtCgcgOREkerazPjiRgjKkAc2WqIbVGACMY8ovKl0D7RXSZseRyVYBlnXsOg+LLjrpKkLUV2zEPMWeBO2SoFmYItMMXNo7UD1GhdfdkW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318252; c=relaxed/simple; bh=RD/cK3mC4lUaj4UwE53PpF5kS6UriEKuPl2+kl278jc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s/iU8bccKZ8F5YLh2bDPsNLn93IPD8hgNgVW22DT3Y4mHi9QIv4XgVXdiXvz1wdYWa2MXtu8Ziqb5+77e3aGGuR2JJuHTwAy6700hLexg36M5DUEoHm6wPMFDE0dYDwikRPQ5xzvAkHe+Y6xvDqYlt7LW0i/CL2Q2KDu6EnHVGg= 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=LJOEEHN7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WGLcyxkH; arc=none smtp.client-ip=103.168.172.154 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="LJOEEHN7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WGLcyxkH" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3EA0F1151BBA; Thu, 22 Aug 2024 05:17:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 22 Aug 2024 05:17:30 -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=1724318250; x=1724404650; bh=TkdvvUFQnX JW9DvvlXb0iAfv/ehBZynAZUdHVdUP3yA=; b=LJOEEHN7gNE+A4QEPJaQLCApwG iqcvKWYcYJ7KkGEtb3F6ElpUfICkYxL8zDV6xgl7DIIR2kPvrb3ASSpqpHuGvs0t pi2GHNJ7Df1hw9aPLMRdLc8iaCjIDyQgfrUivruwpmvtXNBAU+33q2qnvrLZ6GQm cHVuCtUNDO4ZBc7OctdWTN9UdxOfM4idB3R9Wz/f7ZbWPe4+LzSZDLfbBWjTGziO VvbQPMRDOKj9zTfYk6j83j1bIWINFroSnrgSj8fJjn+ujZNSFzy/X6yEY2ZR4rO4 Ac/96GaL2SQxJkbp2MovxXstUCNw5v05HVICHd2m13g7MYpI4qtAYa8/sM9A== 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=1724318250; x=1724404650; bh=TkdvvUFQnXJW9DvvlXb0iAfv/ehB ZynAZUdHVdUP3yA=; b=WGLcyxkHjN/k91m1w7MrEaFGpNDKdk2ioOogs+F9GiWF LLnEq+pnT4TTgrFJa6m5VzFXaYPv204frA3EO7D91Xlco6a48EUNS5ZpaVn8kiUi HQDO/YijAG+B5sgx0miXuSX2aP7BNXrdPCf/P9QPgN1uB/tSFWNi8oS5gss+B4uh usEki35DkNUxEphlSLBQobZhNvV+hxx/ISCTUgzJYM3X6V/k1ABxiamYvad4SDT4 U9Spp1Uzi2mJGSu+dg1VPtvvjdMU/PrVct40LfuheFqxyLqMVft/OkspbzNtDYhE ThR0IXS58ifTzoeOzF8D2NVy+Dd+30pbXzSv/4Hn1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:29 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c699e63c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:54 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:27 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 06/20] builtin/upload-archive: fix leaking args passed to `write_archive()` 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 git-upload-archive(1), we pass an array of arguments to `write_archive()` to tell it what exactly to do. We don't ever clear the vector though, causing a memory leak. Furthermore though, the call to `write_archive()` may cause contents of the array to be modified, which would cause us to leak memory to allocated strings held by it. Fix the issue by having `write_archive()` create a shallow copy of `argv` before parsing the arguments. Like this, we won't modify the caller's array and can easily `strvec_clear()` it to plug these memory leaks. Signed-off-by: Patrick Steinhardt --- archive.c | 10 ++++++++++ builtin/upload-archive.c | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/archive.c b/archive.c index 7bd60d0632a..9ba96aae4f7 100644 --- a/archive.c +++ b/archive.c @@ -736,6 +736,7 @@ int write_archive(int argc, const char **argv, const char *prefix, struct pretty_print_describe_status describe_status = {0}; struct pretty_print_context ctx = {0}; struct archiver_args args; + const char **argv_copy; int rc; git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable); @@ -749,6 +750,14 @@ int write_archive(int argc, const char **argv, const char *prefix, args.repo = repo; args.prefix = prefix; string_list_init_dup(&args.extra_files); + + /* + * `parse_archive_args()` modifies contents of `argv`, which is what we + * want. Our callers may not want it though, so we create a copy here. + */ + DUP_ARRAY(argv_copy, argv, argc); + argv = argv_copy; + argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote); if (!startup_info->have_repository) { /* @@ -767,6 +776,7 @@ int write_archive(int argc, const char **argv, const char *prefix, string_list_clear_func(&args.extra_files, extra_file_info_clear); free(args.refname); clear_pathspec(&args.pathspec); + free(argv_copy); return rc; } diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 1b09e5e1aa3..313a8dfa81c 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -22,6 +22,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) { struct strvec sent_argv = STRVEC_INIT; const char *arg_cmd = "argument "; + int ret; if (argc != 2 || !strcmp(argv[1], "-h")) usage(upload_archive_usage); @@ -46,8 +47,11 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) } /* parse all options sent by the client */ - return write_archive(sent_argv.nr, sent_argv.v, prefix, - the_repository, NULL, 1); + ret = write_archive(sent_argv.nr, sent_argv.v, prefix, + the_repository, NULL, 1); + + strvec_clear(&sent_argv); + return ret; } __attribute__((format (printf, 1, 2))) From patchwork Thu Aug 22 09:17:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773052 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 0575517C7C3 for ; Thu, 22 Aug 2024 09:17:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318255; cv=none; b=SVJwU45U26jWIBdXglf6yhZEKM5KtC7SXynmTdtrTTo4pK++VblwXqHmky0u/93ztknWskqx6OUks4w7JlssAw1OH3ZAFQ25cynRyyzGy+t7wNCtRd8zlhsahpfJ0pfYrZp7wTxXpSiKqJ0rUFGBoGCtzJSkOAc4H2/DfiR3UT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318255; c=relaxed/simple; bh=+efCFzN5AJynIXOyAn8If4Vqm3JpKtRIWXMyvKo6mk0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bhDhTTp4O6bfrVWtZyI76cIHVCQjA7+JIgH9H69bfVfGhKZPpZqlDe6Xjaxn6v/4p6LIoqNuMn0+6G5yNaKblvMzxQweKKOu2zqZ5ocdgpTCFopjr56FYsk+TTs4ltVRLBjPZPfcLjZmB2F2tiQDCEo+H42g9qe3ySdEgLwo/Yo= 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=PoYreMbh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oo4Y98YR; arc=none smtp.client-ip=103.168.172.151 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="PoYreMbh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oo4Y98YR" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 55539138FF98; Thu, 22 Aug 2024 05:17:33 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 22 Aug 2024 05:17:33 -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=1724318253; x=1724404653; bh=bAkMX/B++S 8eeyt+CSPR2tJB/BpVSX65rkau1VWDiR4=; b=PoYreMbhG9eaDVAh6VaX4Dvl30 1Pwv1TDMkM3HhY59UtntmkRHTuTErxePjvOIFXSWxqqXL56A3ygHsVXxxcv/lC8g bUT9M2/kx30iwPdoUrifXLrikLN9yTqREqh5BtCA85sxv5liBocqbBTOsZ4h3R0h IVI3Py0A9vHY856+VrZ3neznGYEn8mb62G67/dKIbgzdoKiTqi5rE2/BQpDiCfx9 hym8QQUP+K7gorPIQyaHD7GQnV6zjEfbRhGlzg8gSSQ5HfFMtlZ8VIM9Zi5K1G1N p7FVFcIhcX5f/0HLu//KSCJUrp+SrlNoy2l4v4oANb3irKE/wnVrGJjCO+lA== 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=1724318253; x=1724404653; bh=bAkMX/B++S8eeyt+CSPR2tJB/BpV SX65rkau1VWDiR4=; b=oo4Y98YRmzuAgAdzkz/dda4tbdsjgFBHir8fXIbYqMBt 5ZM81bhGb3agNblPGuUQ1mbe6LJMYv2p7RbZwt0OdHefylEiNT9uhm5Ge+W1K2LJ PPWZiNY0a1PnAn0J4NQD3TWn7oWFpcNNDubIqyxnZKhmsPbZodUxseTvEl2/LYGX +R/IRJq8tBu4MgzNmiJrq8A5ArWX87fxmXk511+aqs9HQ6KvSunxDhDjdzjhyddt v8F1MWE5ivmT53bhv6i0siNal+Md4YSp86bkWXr5GhZCayLQiKaeVVvUsNwWtEUI iIU+KDH11iOq4cWRureoCKDzq8CQ8vGaIkH//FJkGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4a988ed0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:16:57 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 07/20] builtin/archive: fix leaking `OPT_FILENAME()` value Message-ID: <38487f3f65b7ab0aa1351a15efa8494b6e040f8e.1724315484.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 "--output" switch is an `OPT_FILENAME()` option, which allocates memory when specified by the user. But while we free the string when executed without the "--remote" switch, we don't otherwise because we return via a separate exit path that doesn't know to free it. Fix this by creating a common exit path. Signed-off-by: Patrick Steinhardt --- builtin/archive.c | 7 +++++-- t/t5000-tar-tree.sh | 1 + t/t5003-archive-zip.sh | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/builtin/archive.c b/builtin/archive.c index b50981504f3..63f02990d11 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -100,13 +100,16 @@ int cmd_archive(int argc, const char **argv, const char *prefix) if (output) create_output_file(output); - if (remote) - return run_remote_archiver(argc, argv, remote, exec, output); + if (remote) { + ret = run_remote_archiver(argc, argv, remote, exec, output); + goto out; + } setvbuf(stderr, NULL, _IOLBF, BUFSIZ); ret = write_archive(argc, argv, prefix, the_repository, output, 0); +out: free(output); return ret; } diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 72b8d0ff02e..7abba8a4b20 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -25,6 +25,7 @@ commit id embedding: ' TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SUBSTFORMAT=%H%n diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index 961c6aac256..01f591c99b9 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -3,6 +3,7 @@ test_description='git archive --format=zip test' TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SUBSTFORMAT=%H%n From patchwork Thu Aug 22 09:17:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773053 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 3E71717CA1F for ; Thu, 22 Aug 2024 09:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318257; cv=none; b=dSgcBFlIqA9Bt3MmQ5P/DRO2lMGjEWaDfMj9dIoAkorf5R5658k1oJL0bOgrMmBOWnGN3LhMrhQeh/B8l/kxWhd3gBCGdpaUM//MDwjspfP4OwLWAfu53jcfLREsU2giIdAMZXUMCYnCLAXfcAFv/L1R9krnY2Qylr/jNpyP1RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318257; c=relaxed/simple; bh=IBaND85xDInviqKYQgaqKTVmM+3mOwvES62yg0Af6js=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E4tiGyZQrR5TfYtx1PCQ+a4KGs/6LM3O0fAb/nykdcF5A33gsWNXiD/LCPHOvYAD4mePLYaTicewZ9vQY+X6AwMYMPyiCc3LX0QeP1bB9prDISaxdlWErWS9TKL6F0+XA9ZUjrj42OZ47xf/t0A/wIGn/aqXHG0Zy+2BvHPKdSc= 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=klmtR3Q0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YJn6FloK; arc=none smtp.client-ip=103.168.172.151 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="klmtR3Q0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YJn6FloK" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 60BDA1390067; Thu, 22 Aug 2024 05:17:35 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 05:17:35 -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=1724318255; x=1724404655; bh=a9qZNEVrVl ZXZ7pzxUKhGs9dQNL6o6tYDl5LR+6ljVI=; b=klmtR3Q0smzB2c4YjzD+oDeYGz LPhunwLwdu5MwbFIflSBIlnWbejCtNz5dfyCtpjQoikOcF0WEsbsm8P+JJ7TEfLG aYDEkmNcNlKN/j+Ex9loNfyi7YouPfngsRSNFbmWxo7wVuXjv0tq1guxL1Kp087i djrpy1baEfGB4Acgl4DO+48BkZce86CSTE3lQedQx5wkVNtKxnCEOH/opZ/cP5Eq o/Jl18/sDbC/PIbdoVgqfQu7JUptNJ6DyaJUvl1tCBHq+eP1q4tdJXJniXjPb3F2 n2A513aqx+m5ZuVtJIZv91Gpau4Er3pewmRY97TvvIJbPVwPKRPeCbNorEYw== 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=1724318255; x=1724404655; bh=a9qZNEVrVlZXZ7pzxUKhGs9dQNL6 o6tYDl5LR+6ljVI=; b=YJn6FloK75Np5UGcmCe5DgTk0tDxzMyiNT9bzDZZEFxu QSbP4pxtHiaXYDvDGhn/ynyLlvnJF9TIN/twlheKUND3MYQVrmj8UcgWCuNC1+An GCPgV5lhLqWES+xUd4yePDSLfpfP9Y56VXKMaoFwiJSOtAwFUHSquo/1E/OXJrVw ZgnyIn9VfSBdSXShU0RSQ8xXIqlDfKW/qj63Ge6LPnaThjyGSNDADewHrk5RqDJ8 Z3dJ4Og8LrCr3D3BZAR6mHgTLl6+VgMD+tqVDngHXeR2h+wLgOYOLrjSKLFDuzQv dK/Dr3VPmGwGydsqHIp7jj/hJby5gyMYyr/WEyWpTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:34 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id db4f5e96 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:00 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 08/20] midx-write: fix leaking hashfile on error cases Message-ID: <693c93ddbf761202bff2d7a3213b7afd80049174.1724315484.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 writing the MIDX file we first create the `struct hashfile` used to write the trailer hash, and then afterwards we verify whether we can actually write the MIDX in the first place. When we decide that we can't, this leads to a memory leak because we never free the hash file contents. We could fix this by freeing the hashfile on the exit path. There is a better option though: we can simply move the checks for the error condition earlier. As there is no early exit between creating the hashfile and finalizing it anymore this is sufficient to fix the memory leak. While at it, also move around the block checking for `ctx.entries_nr`. This change is not required to fix the memory leak, but it feels natural to move together all massaging of parameters before we go with them and execute the actual logic. Signed-off-by: Patrick Steinhardt --- midx-write.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/midx-write.c b/midx-write.c index e3fa33203fa..07d98d494aa 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1308,6 +1308,18 @@ static int write_midx_internal(const char *object_dir, pack_name_concat_len += MIDX_CHUNK_ALIGNMENT - (pack_name_concat_len % MIDX_CHUNK_ALIGNMENT); + if (ctx.nr - dropped_packs == 0) { + error(_("no pack files to index.")); + result = 1; + goto cleanup; + } + + if (!ctx.entries_nr) { + if (flags & MIDX_WRITE_BITMAP) + warning(_("refusing to write multi-pack .bitmap without any objects")); + flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP); + } + if (ctx.incremental) { struct strbuf lock_name = STRBUF_INIT; @@ -1333,18 +1345,6 @@ static int write_midx_internal(const char *object_dir, f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk)); } - if (ctx.nr - dropped_packs == 0) { - error(_("no pack files to index.")); - result = 1; - goto cleanup; - } - - if (!ctx.entries_nr) { - if (flags & MIDX_WRITE_BITMAP) - warning(_("refusing to write multi-pack .bitmap without any objects")); - flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP); - } - cf = init_chunkfile(f); add_chunk(cf, MIDX_CHUNKID_PACKNAMES, pack_name_concat_len, From patchwork Thu Aug 22 09:17: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: 13773054 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 172AC17F394 for ; Thu, 22 Aug 2024 09:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318260; cv=none; b=nNkSD4G0LZKnlaH046VOeqiktnLjgNK2iAMc+WaG2G4VIiXcDTKZRMxh9EJvUWtdH45HUrtSOXSQmuOzrGGd4Wyr309CjzfDs/Ac1m0jIk3Kt/vsWFSLWbK+6RbOjjjMlLorGYhXpUuUk6B6Sq9K1gt+8gRykzxWspMmyy1DLqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318260; c=relaxed/simple; bh=DEea8iumaiIyTjdVibVHbZDBXPo2P26lnOzw+eVBliw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KzitB8H6koF6lscRFR2Q4kex+dFpNItTIXFZ4NhKfiP+DRz+qx0qqQ5oc31vjOU9zGUugJq3P0hruV3j6vFfvbskKnNgq6u6SJ/EYT4CH1Z8Na+pBprDB0h/4INAPoJFnK7V1cuXjEljbpN/kCXtEhdep6mdo1ZiQMaGnG1XsTY= 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=mURU4J69; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZjwGRyK+; arc=none smtp.client-ip=103.168.172.151 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="mURU4J69"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZjwGRyK+" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 65440138FFF2; Thu, 22 Aug 2024 05:17:38 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 22 Aug 2024 05:17:38 -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=1724318258; x=1724404658; bh=TBKopDpBE3 gNhl9eJ/7zC7QF/PLppGWTdOdaR3zQNxY=; b=mURU4J69bsEtD+n9z+1iNIhxJK +ASLhNZFva6WB+RRlFOBsvuVDjFM5ttLT+v7q9dcyRfkipacf2a8USC0majjrww8 p4j3DekGQeNus+Vu8cuFLeW4VQlzFNV7ScKQOWiciHj7JUgn/R2cqowvCWex1ELl 4IBKjQnEfJ8vSR7+7HKoZYywcU5x3BCDmHR9IQbKkRsekxvpzJ77+fhaEpad0xfi axCqKRrNQDPqJdhdvNBE0RYH1rxAp8B1gVbYdE4KxXFmrZEXGEguAjEggT3RAMJd UPdtX74DOqHU4ferUR4CuiSjjlu/CeaCBtO5BN6Di9gkYEAzc1m63kCHM6cg== 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=1724318258; x=1724404658; bh=TBKopDpBE3gNhl9eJ/7zC7QF/PLp pGWTdOdaR3zQNxY=; b=ZjwGRyK+bjSLCLSt1CZgxojMj90Ps6r+wG3d2Y22bfV/ aZScMxXAxKo3IIzVgiBhJjjC+WZrv50XCSQCacefgkwG0AEr+xlBToyybovqlqg/ nhZ+i2vWLn3tF5u45rCBdWEmfx+t+1zt2uQfAWfpWi5csFRDFRWH2jRXyPF1P7el 1+jnrz+s2LVCYxNPeMOcVsMezd+rvz1fFLZC8ZPHz3ZBqHiUuGpKxaAUxwQP3co1 2yRIhiQQT3kcUUXkjD1EwB5pq15cKA12nHcxpo2dp5YhkCGfUe38LC/WaudUa5rc eX8+B9/YNVZ8CW1nc3GRHbJn2XLOkTN0glE3CfCjgg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6c048520 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:03 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 09/20] builtin/repack: fix leaks when computing packs to repack Message-ID: <6bca72e5c574d5f930c9cefe7fc803ac30e0c28a.1724315484.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 writing an MIDX in git-repack(1) we first collect all the pack names that we want to add to it in a string list. This list is marked as `NODUP`, which indicates that it will neither duplicate nor own strings added to it. In `write_midx_included_packs()` we then `insert()` strings via `xstrdup()` or `strbuf_detach()`, but the resulting strings will not be owned by anything and thus leak. Fix this issue by marking the list as `DUP` and using a local buffer to compute the pack names. This leak is hit in t5319, but plugging it is not sufficient to make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/repack.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index 62cfa50c50f..8bb875532b4 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -732,14 +732,23 @@ static void midx_included_packs(struct string_list *include, struct pack_geometry *geometry) { struct string_list_item *item; + struct strbuf buf = STRBUF_INIT; + + for_each_string_list_item(item, &existing->kept_packs) { + strbuf_reset(&buf); + strbuf_addf(&buf, "%s.idx", item->string); + string_list_insert(include, buf.buf); + } + + for_each_string_list_item(item, names) { + strbuf_reset(&buf); + strbuf_addf(&buf, "pack-%s.idx", item->string); + string_list_insert(include, buf.buf); + } - for_each_string_list_item(item, &existing->kept_packs) - string_list_insert(include, xstrfmt("%s.idx", item->string)); - for_each_string_list_item(item, names) - string_list_insert(include, xstrfmt("pack-%s.idx", item->string)); if (geometry->split_factor) { - struct strbuf buf = STRBUF_INIT; uint32_t i; + for (i = geometry->split; i < geometry->pack_nr; i++) { struct packed_git *p = geometry->pack[i]; @@ -754,17 +763,21 @@ static void midx_included_packs(struct string_list *include, if (!p->pack_local) continue; + strbuf_reset(&buf); strbuf_addstr(&buf, pack_basename(p)); strbuf_strip_suffix(&buf, ".pack"); strbuf_addstr(&buf, ".idx"); - string_list_insert(include, strbuf_detach(&buf, NULL)); + string_list_insert(include, buf.buf); } } else { for_each_string_list_item(item, &existing->non_kept_packs) { if (pack_is_marked_for_deletion(item)) continue; - string_list_insert(include, xstrfmt("%s.idx", item->string)); + + strbuf_reset(&buf); + strbuf_addf(&buf, "%s.idx", item->string); + string_list_insert(include, buf.buf); } } @@ -784,8 +797,13 @@ static void midx_included_packs(struct string_list *include, */ if (pack_is_marked_for_deletion(item)) continue; - string_list_insert(include, xstrfmt("%s.idx", item->string)); + + strbuf_reset(&buf); + strbuf_addf(&buf, "%s.idx", item->string); + string_list_insert(include, buf.buf); } + + strbuf_release(&buf); } static int write_midx_included_packs(struct string_list *include, @@ -1476,7 +1494,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) mark_packs_for_deletion(&existing, &names); if (write_midx) { - struct string_list include = STRING_LIST_INIT_NODUP; + struct string_list include = STRING_LIST_INIT_DUP; midx_included_packs(&include, &existing, &names, &geometry); ret = write_midx_included_packs(&include, &geometry, &names, From patchwork Thu Aug 22 09:17: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: 13773055 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 417D017F505 for ; Thu, 22 Aug 2024 09:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318263; cv=none; b=oQXN5o7PCWuBAboRpMXYQhb3QFRWNij3qbjHXmSXIPl4D3pH6f+5tPBGZfxQpTSNAkQ88+bz7THbdCMjMzqzgW//MqxThhnzTURDT9LbXFrHT7H5cQb7dUjqlya9lkBUrgqJFsqXr+vXsKJGayKtfcrAWqniHEcc1KSQMBMeJko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318263; c=relaxed/simple; bh=y8K1KjuELFVbwthYQp2OWFJiyd6MN6eKlIY3ZWYPOlo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NMOK/YQkIKIwpeZtf3JbSjQeLTtEjUkE27526O77VM7MRx2KQTCEvfdqc/IR7sZoge2xcOUZfAXyLuAOvYGGP3C51wVvlSuBX2AudJGzDLEc5StLtvkfc1ex7wVkWqz8rOr2J82vQGyYgXba/ngDUBFmf9toMd4APh743YSzDXo= 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=YQYTaq5v; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CDHHQURq; arc=none smtp.client-ip=103.168.172.154 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="YQYTaq5v"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDHHQURq" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 723E41151BB5; Thu, 22 Aug 2024 05:17:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 22 Aug 2024 05:17: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=1724318261; x=1724404661; bh=O8QXy96Qtf R6mQErCqM+V1HmQQkJtD/I900UtsWbPr0=; b=YQYTaq5vwDYIt82QJDmmVUv6yc /1uDx5eSB3bKlS6NdNkWomrvlWsDvgl/BVYC2rLb06K2P/kIhqyqeoyvYUImOxad 342gxvP2ekoYk0dVq8HeAcKoSxXGL273h+WiyktLq9Pk6zfWBF9KLgOV3JwwaobK ZeiLqwWzYUv8Y0BHGsR3SUmR4ZKkBLuPzh8dFUpBu+J/VB6+gOp5OoOSsStC/sjA 88fnViRCxM8cE/7SFYUD0JzFFthuVrDIlZ/dOgM6tHYHTnWmLt/UiLx9ZFqR5QLo EIyuv8qWsmxtG3NLJdJZFnqGxdKNpWn5LMaleYZt7Dj191u+dsVbVvcM4WRQ== 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=1724318261; x=1724404661; bh=O8QXy96QtfR6mQErCqM+V1HmQQkJ tD/I900UtsWbPr0=; b=CDHHQURqz4JIJKM8GmeqrKXNxuFlcx1edEyMoH8XXKNw JFOnwCTNS3HyrGH2M3B1t5tKmZj6Swl/DvVnNb2k4RBAKjqQqv+WJfrDb3PpPPNO RY/9qVGm+EpPh7mmtfbEdc3lkzszk/sYXx6RXLmUhrzXeiy+gO6wEA5c9DFN2Tqv ugO8bdS6YB1q9czNTmfYoYydxJPhMeMH3bsQwEco4RqKnex95y+CydJ7xg13SS/4 8+AMgkvam/UcGOInXEbwg8iA9GjSZMxn3L5Eo9KxaHOBwtTInuCjlcUzWvfCNLst 4VNBPnQeMo3m4YhEwTh0iRIWeHZFNFrrZAoGkv5U3A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id cbf20266 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:05 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 10/20] t/helper: fix leaking multi-pack-indices in "read-midx" Message-ID: <48b60279d18ced93614c15772a9344ab7e337b6f.1724315484.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: Several of the subcommands of `test-helper read-midx` do not close the MIDX that they have opened, leading to memory leaks. Fix those. Signed-off-by: Patrick Steinhardt --- t/helper/test-read-midx.c | 8 +++++++- t/t5319-multi-pack-index.sh | 2 ++ t/t7704-repack-cruft.sh | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 69757e94fc2..438fb9fc619 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -86,6 +86,8 @@ static int read_midx_checksum(const char *object_dir) if (!m) return 1; printf("%s\n", hash_to_hex(get_midx_checksum(m))); + + close_midx(m); return 0; } @@ -102,10 +104,12 @@ static int read_midx_preferred_pack(const char *object_dir) if (midx_preferred_pack(midx, &preferred_pack) < 0) { warning(_("could not determine MIDX preferred pack")); + close_midx(midx); return 1; } printf("%s\n", midx->pack_names[preferred_pack]); + close_midx(midx); return 0; } @@ -122,8 +126,10 @@ static int read_midx_bitmapped_packs(const char *object_dir) return 1; for (i = 0; i < midx->num_packs + midx->num_packs_in_base; i++) { - if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) + if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) { + close_midx(midx); return 1; + } printf("%s\n", pack_basename(pack.p)); printf(" bitmap_pos: %"PRIuMAX"\n", (uintmax_t)pack.bitmap_pos); diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index ce1b58c7323..fbbc218d04a 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='multi-pack-indexes' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-chunk.sh . "$TEST_DIRECTORY"/lib-midx.sh diff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh index 959e6e26488..5db9f4e10f7 100755 --- a/t/t7704-repack-cruft.sh +++ b/t/t7704-repack-cruft.sh @@ -2,6 +2,7 @@ test_description='git repack works correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh objdir=.git/objects From patchwork Thu Aug 22 09:17: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: 13773056 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 3301617DFE8 for ; Thu, 22 Aug 2024 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318268; cv=none; b=iqXRkN+sN99tj6SGYc0/C4V0/+v9D+srCwSsJTdV8BmzoimeHLRXdG/DxF9VJEg7p4lVX19rbkmALiYvQu6sn+ljXp6nWRUR1G/9tPfBSsCbrbmzqNIJdAW74ln3RHlrfORK182Zt8bpaTj2TXo0Of9ABaTh9K4WCstXca7/Uo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318268; c=relaxed/simple; bh=frzfgQegaiMTWqYDcpcJFAN6SevmLupG95bK/iyYZMU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oiJisM2o9GmtAvlhKlAYHg83gRjQZ3IRUv4p45AHvqKpVuaZWLcXINy9TWP1p/axM06Y1cerktsqGurEr9XOx/hoYy6D+H/Dy3s0Zz3DPtV4l9YA3IPNn+eu9NHcLnDQi8laS+R5rbCMoqWpl7sT0JdHd0AvfPw2Op1z3cfFIAA= 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=D/NL0iIF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=J6HyoH5N; arc=none smtp.client-ip=103.168.172.151 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="D/NL0iIF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="J6HyoH5N" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 7FB4F1390049; Thu, 22 Aug 2024 05:17:46 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 05:17: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=1724318266; x=1724404666; bh=vXKoifygpu jg1nDhlKxsTPXskdygzLtZUauu5641c+8=; b=D/NL0iIFNXQn6nysYGv3jteEAJ M0ECifeq5ynzGSBKhjCMXE2Ig8KBzATGgmPheTEbE55H1k6ISJxNevlHYBcUGRcZ 4AWietlQ7Xiz/D0EpWR4RXxy/+sp1h+81o/j6gVkqVRfjP6Noob68uHwVpNevWRU MqBG4DjF5erqW6slZijYdnYiOGED4OLc41lMqMthvuILgKXPofL0HtKtLCkG89CQ QdpyMFupPQv64dFXl5w/IGuL28fgcE2NeIebIQtAq/BQK/9FxLP/tmlxkmx9Azsu lAWPd89Pleh/VvkrMSfbpm/cLAne8YlDIZwrPxshowW7OeOw6Gg2HyFUN3nw== 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=1724318266; x=1724404666; bh=vXKoifygpujg1nDhlKxsTPXskdyg zLtZUauu5641c+8=; b=J6HyoH5NHQVdKjofH3FBd6ZPwICQHWNdX5kUXGMjAJPu e/15OG1uNrI4WEmvYeLIyqrEs/b1Hm4Sp/2OSanyUAV0NasA64SV+MrqECM3ROtK q1xOpXGjl8mm0tSMhdW65WEloaRqQn2GZp9Gdaa9nQJdtEbeRaQFuwT4xglcPglb kt48zWv9SAJsG7THCzQpuorMscjg4gZN1K0VJGPtgj1mcT31MfXQsC9uXjsWioVm dH1twT5D9jA7FtAHjytrlj8OwbBF/01MQZDoyzF+euDtvkPCjOXspHFzQv+BNe7b HfxHOrfvBS2o69G3BLZnUzAtslOIEQlu3gL/gs4ahA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 20ce2f54 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:10 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 11/20] transport: fix leaking OID arrays in git:// transport data Message-ID: <0cb440ef6482a09c3b25435bb9f0e9b0088a7b29.1724315484.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 transport data for the "git://" protocol contains two OID arrays that we never free, creating a memory leak. Plug them. Signed-off-by: Patrick Steinhardt --- t/t5501-fetch-push-alternates.sh | 1 + t/t5519-push-alternates.sh | 1 + transport.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/t/t5501-fetch-push-alternates.sh b/t/t5501-fetch-push-alternates.sh index 66f19a4ef2b..0c8668a1b8e 100755 --- a/t/t5501-fetch-push-alternates.sh +++ b/t/t5501-fetch-push-alternates.sh @@ -4,6 +4,7 @@ test_description='fetch/push involving alternates' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh count_objects () { diff --git a/t/t5519-push-alternates.sh b/t/t5519-push-alternates.sh index 20ba604dfde..72e97b15fab 100755 --- a/t/t5519-push-alternates.sh +++ b/t/t5519-push-alternates.sh @@ -5,6 +5,7 @@ test_description='push to a repository that borrows from elsewhere' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/transport.c b/transport.c index 7c4af9f56f2..f0672fdc505 100644 --- a/transport.c +++ b/transport.c @@ -946,6 +946,8 @@ static int disconnect_git(struct transport *transport) } list_objects_filter_release(&data->options.filter_options); + oid_array_clear(&data->extra_have); + oid_array_clear(&data->shallow); free(data); return 0; } From patchwork Thu Aug 22 09:17: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: 13773057 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 565EB17DFE8 for ; Thu, 22 Aug 2024 09:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318271; cv=none; b=UH5d2EPliEcwWSLefVSlPpNityz+7yq+gpg4Q5V4BB23EKLmy0ehq14F3GBFG1nxWScwOVo5veMPZBx6q+YdrMQdVbe1RfxwCW/FFxmyEWfqSCFhrUl/WgV/jXwvEtoHtJdpGtgh5NdJIodoKugChJKyLhCcd8XDI4DUe1pJ67U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318271; c=relaxed/simple; bh=C5cwareO0W7oYeLcgZkeCKuwuCjDCFyEOhsDpvAgKxI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cMkQfBAPfEClYUzMlb2gR2Jow/n17mjsW4weaqHJb4tFJvbZgNsdPVA9aFwn2ZlPryo28o2+aKHYdj7cI6X6A3cu/wLpoRi7q5YWAxXxSE1J7y/mCOT5SMIacV/vfUsIwGtKkodgFY/xCVOE28DPhx+t68uleyFm6lFBQemcR08= 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=TlM49yU6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FlU8nZdz; arc=none smtp.client-ip=103.168.172.151 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="TlM49yU6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FlU8nZdz" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 8732D138FF86; Thu, 22 Aug 2024 05:17:49 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 05:17: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=1724318269; x=1724404669; bh=8MsbH4+FTr HtG/Xv2YoGxlTRjel4tAHFGdg9PDQNSMg=; b=TlM49yU6gOXoan9oqy+jSFp7ir ZIcoKjrTBt2mH+UfvLwmow1Vo5Xvdr+wUqV75PgEdjqqiwADuep+AfusvplUX20g 7HNYxaHYTS9/cUKnu2aBkro0NNHjFfEShYaFNLf+htRAAdBXgbrkC/cj6KDUHorb Otm3BdVPgtOvIq9QvR13Al28jrdUnoYXpR/y6RNZVKZQhiSYtTochyI/6j1qcLXo /opSwsSXkHHOBQqz3tnW6zWptZS9QmfwkhXF2JcwrEPIIf0v7njEApmLXz8yRnXI tUUG0Go/sjW/JQs/Tgl8QPlF/suHo19+PK2dr6HM2qbAWHJaVcAqGB4ZZKlw== 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=1724318269; x=1724404669; bh=8MsbH4+FTrHtG/Xv2YoGxlTRjel4 tAHFGdg9PDQNSMg=; b=FlU8nZdzACPEkVHiyWc3BbjbEb5whOIQLufK8A9H3dr/ hsi+wTzrbNmsRhY4nejqnfA7h0ZLH5w0bu7yFfgN0cZpWgRAzi63PU6xe3Dlwi7Z joSNfEHCFSiYIQADdvRC7TeHpU0F0b8Mhbmb5xi+qImUVxXbqhDKn5XjHLNeSMjD gi2YhDnvsHvFsdL55fMoIiKKFzw5+6TKcK9Qs9Wa1s50z5YT1Sc+H8f+rhALtzdp BSlgRqcLpUC592PldsbZLTh2oLvpJ2MpglRBBbTo3KMu+rQFPDziKVgakfJZICFC X+76zEfhr2RCDKZYBbi0G1HKLrGsfV6AsU6ZH8COQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeethfegfeehhf evfeefleeludefgeegfeeltdejleeuvdeggfehjeduhfevfeehgfenucffohhmrghinhep hhhtthhprdhshhdphhhtthhpugdrshhhnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddp mhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrghdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a41298c2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:13 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:46 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 12/20] builtin/send-pack: fix leaking refspecs 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 never free data associated with the assembled refspec in git-send-pack(1), causing a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- builtin/send-pack.c | 1 + t/t5400-send-pack.sh | 1 + t/t5401-update-hooks.sh | 2 ++ t/t5408-send-pack-stdin.sh | 2 ++ t/t5548-push-porcelain.sh | 1 + t/t5812-proto-disable-http.sh | 2 ++ 6 files changed, 9 insertions(+) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 17cae6bbbdf..ef0df808249 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -338,5 +338,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) free_refs(remote_refs); free_refs(local_refs); + refspec_clear(&rs); return ret; } diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 3f81f16e133..248c74d8ef2 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -9,6 +9,7 @@ test_description='See why rewinding head breaks send-pack GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cnt=64 diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index d8cadeec733..3c1ea6086e7 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -4,6 +4,8 @@ # test_description='Test the update hook infrastructure.' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5408-send-pack-stdin.sh b/t/t5408-send-pack-stdin.sh index e8737df6f95..c3695a4d4e3 100755 --- a/t/t5408-send-pack-stdin.sh +++ b/t/t5408-send-pack-stdin.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='send-pack --stdin tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh create_ref () { diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh index 6282728eaf3..ecb3877aa4b 100755 --- a/t/t5548-push-porcelain.sh +++ b/t/t5548-push-porcelain.sh @@ -4,6 +4,7 @@ # test_description='Test git push porcelain output' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Create commits in and assign each commit's oid to shell variables diff --git a/t/t5812-proto-disable-http.sh b/t/t5812-proto-disable-http.sh index 769c717e88b..f69959c64ca 100755 --- a/t/t5812-proto-disable-http.sh +++ b/t/t5812-proto-disable-http.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test disabling of git-over-http in clone/fetch' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-proto-disable.sh" . "$TEST_DIRECTORY/lib-httpd.sh" From patchwork Thu Aug 22 09:17:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773058 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 7E2AF17DFE8 for ; Thu, 22 Aug 2024 09:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318275; cv=none; b=bhZyyhaWPlByrU1FgXHlOxuO+vbKY5FGcv5JWtU1NmHLEdpUBde0Qk0Xk3cjxvRGPts2R9qNO9YYQyiRRF6lPZt2Wgk1RF/PbrDQBAHJzliw2JCh27yjq2r4ad4igxRdxMFGn51t0u+iMR2rdQ2H4At5ATUgcFKC1ocHdU0KySM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318275; c=relaxed/simple; bh=4Y4zeuGh7V0E83InyVTCDl1J8f90huuPPuiwEZnG/3E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DRLqxSGhhRQboSnu3yA6B8Qng+CiFhnV5Mw1XFCXurplzEABx36OMoZgxK9Sw3/LAIw0T6DDyPRpFJv/DmwAdvWQkbEEsiL0H3GBIGUhwxIbwdTA6Y8L19hdYQYar0S/nnW5UF0UmS8IXDOdgfyVH7lcS8tfXVcctOtSHqwxAic= 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=TQQHn35b; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CbheaVkl; arc=none smtp.client-ip=103.168.172.154 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="TQQHn35b"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CbheaVkl" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 959DA1151A66; Thu, 22 Aug 2024 05:17:52 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 22 Aug 2024 05:17:52 -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=1724318272; x=1724404672; bh=OT/ILweivx G7JsgdgnAFGi+dS6Stjb4IqAXdKHsxg1Y=; b=TQQHn35bbVF622UBT2fZ3hl4Qv 5mSaLx1aT0YfF2GWMbXNNfdkC+577ORLuxJateNqqsU4pLjarJetNMwCbn+EcEfP GZrmio/69NKF51ewCvn7350nXtlBLrEUZzpPmi9YpsSGV/vCwR093KjUvwY7ZNB9 VOo6MpvIp1wz7dP7lvm3jMbh7S8fFsTMqYclnAZp+UfqKqB93UufuN2uo77AsyY9 hERu/hmP51eP1NKnxeUPvBY36m2ykScLG54UX6CUGDdDOxVCjZoWmsdm0s89decR 5J3IepZE/b9nZbwZCM2CNR7aqk8Zkft5gI2U87KAqsBsPDhnfxbuGs9+16Jg== 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=1724318272; x=1724404672; bh=OT/ILweivxG7JsgdgnAFGi+dS6St jb4IqAXdKHsxg1Y=; b=CbheaVklvLZmeczcPCG1X0E6kwkjay32lF7Wy0LU03UL ArOOLfB8Tg2AdML/3vLCeFEWgHX5rV2zHBdrr7HQLn5TtMFT+0feuKMDeAhrEJQt H/4wMPmRr8DWuKBfZzsLd2J8BPs7uVAqAYERR+1RyS9hEKZlcbgFGrD88BGH1Ngu +q08Mkgnb41zyaoagh8IICeY9ygfwpB1kJKLkF/dpKt38R56O7o03t/0sSh6p/sV ohoKZeBKdXkTl9jYyVGgGNX5xjjgOjo0nxeJa8HD6Qg79NnsJVcjgkOHZVLylnVb GdkbW3DHhI4/E8F04XT8ZnkW58kx7yqnm5fb4eAY2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:51 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 57e234e2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:16 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 13/20] sideband: fix leaks when configuring sideband colors Message-ID: <28805c15a425f822ef1851affa14803a5499b6d4.1724315484.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 read a bunch of configs in `use_sideband_colors()` to configure the colors that Git should use. We never free the strings read from the config though, causing memory leaks. Refactor the code to use `git_config_get_string_tmp()` instead, which does not allocate memory. As we throw the strings away after parsing them anyway there is no need to use allocated strings. Signed-off-by: Patrick Steinhardt --- sideband.c | 15 +++++++-------- t/t5409-colorize-remote-messages.sh | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sideband.c b/sideband.c index 5d8907151fe..27853736901 100644 --- a/sideband.c +++ b/sideband.c @@ -30,28 +30,27 @@ static int use_sideband_colors(void) const char *key = "color.remote"; struct strbuf sb = STRBUF_INIT; - char *value; + const char *value; int i; if (use_sideband_colors_cached >= 0) return use_sideband_colors_cached; - if (!git_config_get_string(key, &value)) { + if (!git_config_get_string_tmp(key, &value)) use_sideband_colors_cached = git_config_colorbool(key, value); - } else if (!git_config_get_string("color.ui", &value)) { + else if (!git_config_get_string_tmp("color.ui", &value)) use_sideband_colors_cached = git_config_colorbool("color.ui", value); - } else { + else use_sideband_colors_cached = GIT_COLOR_AUTO; - } for (i = 0; i < ARRAY_SIZE(keywords); i++) { strbuf_reset(&sb); strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword); - if (git_config_get_string(sb.buf, &value)) - continue; - if (color_parse(value, keywords[i].color)) + if (git_config_get_string_tmp(sb.buf, &value)) continue; + color_parse(value, keywords[i].color); } + strbuf_release(&sb); return use_sideband_colors_cached; } diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh index fa5de4500a4..516b22fd963 100755 --- a/t/t5409-colorize-remote-messages.sh +++ b/t/t5409-colorize-remote-messages.sh @@ -2,6 +2,7 @@ test_description='remote messages are colorized on the client' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Thu Aug 22 09:17:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773059 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 77E03181B83 for ; Thu, 22 Aug 2024 09:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318276; cv=none; b=ZbDD+1f2SaEZTiU8z8UJ7Wla3vET+0xK3KZFupEN/hEiQMbp2r7Q4Zzxo+vFIQqig+G4DDmDNO0deL5gF3nJiMbhLxFYVRX5CuFB7Bd9eHDt19mwUmo1abbI2OQlgIpJo3jIbYvrevyS1Gyvgd+iKW86fjXRgkgpTPs6Og5agFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318276; c=relaxed/simple; bh=9wQt4BHiI/bt4NyKITEtRjgp3D8b62VJEnSMyDCYMkQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=raCos67MGaMi1y7SSQ313AmOfW2Y+T+0qEh1FlvtTbpblm3ZrooPFcXG7TUfblSIzLuS/VRAjYogK7Z5iVXOlob3oceKs6Ywn4eOp/TBO/UKfV+IwZlIk11AgM3A3sV7ObT1gS2OvTQncwXQbSY/7hMOqalPkuXbHWpsZ0387lY= 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=IQcQ7KvJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lPtKRjjV; arc=none smtp.client-ip=103.168.172.154 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="IQcQ7KvJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lPtKRjjV" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A1BE61151ACA; Thu, 22 Aug 2024 05:17:54 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 22 Aug 2024 05:17: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=1724318274; x=1724404674; bh=jJaGu/U2tT ESezbyhYQIMT3CF0nv9IjwY5IFbxYDrss=; b=IQcQ7KvJna8yD+BEZT/snQXqc6 e8WfMqHkmUvTAxtSiF4ASoCKqzx31UhBkP3X1Vom7hcMQcS3EXiH2prtvpwUcTqC oqx+uZ1xVtHspvIi2kpZL97bCq35Wdh7V2IbMi2pg0V4ZAwHzq/v+UPXdSJuf53U fc+qNVmXp3h//qXaFp3m8+VOS3vGI3nXyVxjGulpD/7p9CKI8Dz76V2ck8ebCYNN PhaMb6tYlKpf3EuQDdiBhG0vCYwS/AKtKBsLLuyGTg4XOpYYlOcfR76vOGwwZebb gqKQE105yLIVP62l3uGeWoFAOPo7ZKPfP2IiuYgOY5dgu4irBG0orHVg7kzg== 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=1724318274; x=1724404674; bh=jJaGu/U2tTESezbyhYQIMT3CF0nv 9IjwY5IFbxYDrss=; b=lPtKRjjVNW5+2/Y+5w19kbfN34ul5OmXd7GI1sWiFwoL TYqojm8fB7awgCM0YKdCH6uw1aVtxgECGKNi66wFXgujnys1wsb2i7sOsa02wo6l nTCK3/2J3QGie1PlzWueViWaYwyEs6JjeV40rV/IgebhbdN5wkFfSliZxxXwk8vj 9yzEW3yvveC1X1DgDXV1DGsjPnuvgacBCAIyv/MJ0jvHZrbNaBHqstUSc1rNxarD aoTF987d+uqGvL2ScnrzEAiFlPFHn1kYGZBaLo1pIVW7iJABdIRv9tcFUBCdIjqW fzgvd0y4r9qUhuoF5TmzLZiGhwNMaomjALDSwgt/Xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fffbd242 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:19 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 14/20] builtin/fetch-pack: fix leaking refs 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 build several ref lists in git-fetch-pack(1), but never free them. Fix those leaks. Signed-off-by: Patrick Steinhardt --- builtin/fetch-pack.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index af329e8d5cf..fe404d1305b 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -46,7 +46,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc, int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) { int i, ret; - struct ref *ref = NULL; + struct ref *fetched_refs = NULL, *remote_refs = NULL; const char *dest = NULL; struct ref **sought = NULL; int nr_sought = 0, alloc_sought = 0; @@ -228,19 +228,20 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) version = discover_version(&reader); switch (version) { case protocol_v2: - get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL, + get_remote_refs(fd[1], &reader, &remote_refs, 0, NULL, NULL, args.stateless_rpc); break; case protocol_v1: case protocol_v0: - get_remote_heads(&reader, &ref, 0, NULL, &shallow); + get_remote_heads(&reader, &remote_refs, 0, NULL, &shallow); break; case protocol_unknown_version: BUG("unknown protocol version"); } - ref = fetch_pack(&args, fd, ref, sought, nr_sought, + fetched_refs = fetch_pack(&args, fd, remote_refs, sought, nr_sought, &shallow, pack_lockfiles_ptr, version); + if (pack_lockfiles.nr) { int i; @@ -260,7 +261,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) if (finish_connect(conn)) return 1; - ret = !ref; + ret = !fetched_refs; /* * If the heads to pull were given, we should have consumed @@ -270,11 +271,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) */ ret |= report_unmatched_refs(sought, nr_sought); - while (ref) { + for (struct ref *ref = fetched_refs; ref; ref = ref->next) printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name); - ref = ref->next; - } + for (size_t i = 0; i < nr_sought; i++) + free_one_ref(sought[i]); + free(sought); + free_refs(fetched_refs); + free_refs(remote_refs); return ret; } From patchwork Thu Aug 22 09:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773060 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 8AACC1836D5 for ; Thu, 22 Aug 2024 09:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318280; cv=none; b=p7e8FjMrSk4ZmR65yUL39lshG/F7H6di0yD/D+aIRZZ2X8odwzNKfrx409isT7RuUw503Fo2lq1eHKLVLf8c1YgHprGvynQHXnXl9bj57+IGBVSpLc75iP96KZSAbSwdmscRCXsUZ8JyG7t19vAbJYw8NxJcnOy+/WlK9vf73IM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318280; c=relaxed/simple; bh=Br3jKC5gK8wl0Mwp21gqIuK66/tgOmHZ8tL7Z58VCHo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lKC/09HsODALwkibpEMud/8z3e1pAHbXy7jv8dVrO6Esp6m3CYNcyNJ9FHm+aoefcpRvkikhZxYTHg8llqSc45Lwxq6mps69fdj7LGFAXkmlnUzkNJAqfcx1gcLpz7M76eFYiNMdo9Pd2JYvLRJqvP2pz+uzSFxCM7SXdc99FvI= 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=VJ9P3WDv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=f9u8rm7u; arc=none smtp.client-ip=103.168.172.154 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="VJ9P3WDv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="f9u8rm7u" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B20B11151ACA; Thu, 22 Aug 2024 05:17:57 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 22 Aug 2024 05:17:57 -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=1724318277; x=1724404677; bh=5y/4KdAzaD VUjmsq6cdSaKltOTfA6iBNuSaHl1RINP4=; b=VJ9P3WDvdZ+VfugAzgB2Ci+HZP Lcx5aE8ayw5+pfD7Zy/lqbSwx/ANcvneoaZkVFJz3kZh06R6YdT/sl6jp5Hi+ZWN WyQ6X6JWfwLRl4t+bFhAk/LBRPc62xQ/sq7i77QFRUiNyzTUkMFsV2iw1jkZ9k5i KWMoFT1KjC3wX5WuNp3qX4jIhs34LYpOMBD8m946xyhVrnl5r9hDsmdgxnnr3f5S OCfO3hPAZPz14mM9AtNf8HLZFMTKaUo905BU2G0ck4za2LwRGOBFnXJ/m4mkz0CL kSRTxpnVQAmKiqTJXDTCg8EeC514ej6guZDlqO6eOPVZOHjzJTdh8nN2KDKw== 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=1724318277; x=1724404677; bh=5y/4KdAzaDVUjmsq6cdSaKltOTfA 6iBNuSaHl1RINP4=; b=f9u8rm7uICHjdPl/+Ig8/RsGfF2gfU+aMqddU8kh3Uyf uzEVWJ9vDyQalVCPPjdqlBQfWkvbeeSy3lyE1pZS4VS7HMsiXNR6GK5TFsjiS+x4 rEav1m++izvEntpgifWfesgClTcYPeYW/C1M3xvXDdZGOq8H8xIStwV+hP7+l0qZ EVxuQZShuHCbKAHQq4sBBqJfSDT6rGWRc1UUhCzsF3VbovbRhRzubQNL2KdDAVFH bspu5T4RTVMC35uDRWOZ28EoRXWqI353hm9Dm0SWittAodCNXFi8Iro3yuSi/lTe lZB11gCXUZfbxBoGVTdegniskIYUlTR3Gz3umFKODA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogi drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:56 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 45affc52 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:22 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 15/20] remote: fix leaking config strings Message-ID: <532328b78140620549385c7e2dff3ecc98036593.1724315484.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 several config strings when assembling remotes, either because we do not free preceding values in case a config was set multiple times, or because we do not free them when releasing the remote state. This includes config strings for "branch" sections, "insteadOf", "pushInsteadOf", and "pushDefault". Plug those leaks. Signed-off-by: Patrick Steinhardt --- remote.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/remote.c b/remote.c index 7d5b8f750d8..2c52119bbb2 100644 --- a/remote.c +++ b/remote.c @@ -243,6 +243,17 @@ static struct branch *make_branch(struct remote_state *remote_state, return ret; } +static void branch_release(struct branch *branch) +{ + free((char *)branch->name); + free((char *)branch->refname); + free(branch->remote_name); + free(branch->pushremote_name); + for (int i = 0; i < branch->merge_nr; i++) + refspec_item_clear(branch->merge[i]); + free(branch->merge); +} + static struct rewrite *make_rewrite(struct rewrites *r, const char *base, size_t len) { @@ -263,6 +274,14 @@ static struct rewrite *make_rewrite(struct rewrites *r, return ret; } +static void rewrites_release(struct rewrites *r) +{ + for (int i = 0; i < r->rewrite_nr; i++) + free((char *)r->rewrite[i]->base); + free(r->rewrite); + memset(r, 0, sizeof(*r)); +} + static void add_instead_of(struct rewrite *rewrite, const char *instead_of) { ALLOC_GROW(rewrite->instead_of, rewrite->instead_of_nr + 1, rewrite->instead_of_alloc); @@ -373,8 +392,10 @@ static int handle_config(const char *key, const char *value, return -1; branch = make_branch(remote_state, name, namelen); if (!strcmp(subkey, "remote")) { + FREE_AND_NULL(branch->remote_name); return git_config_string(&branch->remote_name, key, value); } else if (!strcmp(subkey, "pushremote")) { + FREE_AND_NULL(branch->pushremote_name); return git_config_string(&branch->pushremote_name, key, value); } else if (!strcmp(subkey, "merge")) { if (!value) @@ -406,9 +427,11 @@ static int handle_config(const char *key, const char *value, return 0; /* Handle remote.* variables */ - if (!name && !strcmp(subkey, "pushdefault")) + if (!name && !strcmp(subkey, "pushdefault")) { + FREE_AND_NULL(remote_state->pushremote_name); return git_config_string(&remote_state->pushremote_name, key, value); + } if (!name) return 0; @@ -475,12 +498,15 @@ static int handle_config(const char *key, const char *value, else if (!strcmp(value, "--tags")) remote->fetch_tags = 2; } else if (!strcmp(subkey, "proxy")) { + FREE_AND_NULL(remote->http_proxy); return git_config_string(&remote->http_proxy, key, value); } else if (!strcmp(subkey, "proxyauthmethod")) { + FREE_AND_NULL(remote->http_proxy_authmethod); return git_config_string(&remote->http_proxy_authmethod, key, value); } else if (!strcmp(subkey, "vcs")) { + FREE_AND_NULL(remote->foreign_vcs); return git_config_string(&remote->foreign_vcs, key, value); } return 0; @@ -2797,16 +2823,26 @@ struct remote_state *remote_state_new(void) void remote_state_clear(struct remote_state *remote_state) { + struct hashmap_iter iter; + struct branch *b; int i; for (i = 0; i < remote_state->remotes_nr; i++) remote_clear(remote_state->remotes[i]); FREE_AND_NULL(remote_state->remotes); + FREE_AND_NULL(remote_state->pushremote_name); remote_state->remotes_alloc = 0; remote_state->remotes_nr = 0; + rewrites_release(&remote_state->rewrites); + rewrites_release(&remote_state->rewrites_push); + hashmap_clear_and_free(&remote_state->remotes_hash, struct remote, ent); - hashmap_clear_and_free(&remote_state->branches_hash, struct remote, ent); + hashmap_for_each_entry(&remote_state->branches_hash, &iter, b, ent) { + branch_release(b); + free(b); + } + hashmap_clear(&remote_state->branches_hash); } /* From patchwork Thu Aug 22 09:17:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773061 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 9D807183CBB for ; Thu, 22 Aug 2024 09:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318283; cv=none; b=Jd4YZDWuYtkzIhHq3jCCQ4saGw97+iCLb/uHkfEvLuJ7RFkv8dtGDBtJIg1znvbNOQgUtPcx5+MJehhAOANXos3eAD716nNTK6GIXzxgMvaQaWew0DL65f2Q9AdWAL6ErhrCTKK6S0h2JhWKe+e/f//ypaHuar8MjvaqPBoRb38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318283; c=relaxed/simple; bh=jAXZqjKBd2lnb1NJkLguqIf3Np+pHY/i8dlkw+R1REI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EwrXTef9WeJfAdM/UJY6xOZzI66pnWD60jZimq4Kmw1X4vH0X7z2JDZFS6d2CZyyHpJ3U1IYhuGtdrmnizbS1rfsdtzZ4E9NN/akK+z3zsIO7KcBRuoBQJO+rgar5tjMRUx+Aq5TqtyY0VcRLIE7tMab8O9lYrb9YKzQmxEuGQU= 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=oL21ymw2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OAskiTBL; arc=none smtp.client-ip=103.168.172.154 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="oL21ymw2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OAskiTBL" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BF7711151AAF; Thu, 22 Aug 2024 05:18:00 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 22 Aug 2024 05:18:00 -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=1724318280; x=1724404680; bh=ifLKllzCxc GOnMh8nEjf1em21EvBrqzrhAwyaz8Z5KM=; b=oL21ymw2ewpVMS/QvR5xWkgW4R vtTVdiE3Z2TN2pMGQMtVOa2CkDjHFUm7MHQr68jjzf5u7eJzEX7DQLWNaf4lNIWI bmuJknBFREIU/j5rr4Lzuw55Q4jV85ZhaynUu28era18y0V3EF7IzGpFhBn4kdOQ /B3srJ7YO4PholTsoSuZNtIqzC7nazHfkdBqGua1tf7+5bOs7RKi4f8bWixRcpnr Ddooqsy4i4sKDEPL4xtIdCH0a9g6GRzYRszuJ96uDOqivBTnuir1VmHcXSNG1wKl E6p6kjaQAn2GdhSI1E5HgonVjqiW3sD0FnsXl0vOC9UuHfPpdXAX3NfEGDtg== 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=1724318280; x=1724404680; bh=ifLKllzCxcGOnMh8nEjf1em21EvB rqzrhAwyaz8Z5KM=; b=OAskiTBLGrQ+WRRKXSPCk7HVWHyhgfazj1Tq0v86mzO9 7aoNPD1iyaJ1xWQn489vBLa0e54SizsroCFNpCp8u11HdD7E0TC8BgJrNoKeok+4 xZTyTk3NIDLf4HmQx1DbLIyFXf+9jdRULffCLBrWvfrfSbDkCc4tL18FJI+eFprZ jt/dudbOMEbnaet+MN7MUt8CYDGMt8RDD2m0+RP1cCoKk3JgH1aDFaEhOOWvqOng Xr/g6o6xTQzgyb/kVG7JvYzSTszFSBPEDHQzI8TTYJGCgvfDeINWXso7xwBxgVXP 9ynPb5G8Yb1C/otI2Vh0ZdxO5S7DLXqFQzfzsjuDNw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:17:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id cf33b870 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:25 +0000 (UTC) Date: Thu, 22 Aug 2024 11:17:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 16/20] remote: fix leaks when matching refspecs Message-ID: <440b3d993724c465971628e9548c4937a7cd0833.1724315484.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 `match_explicit()`, we try to match a source ref with a destination ref according to a refspec item. This matching sometimes requires us to allocate a new source spec so that it looks like we expect. And while we in some end up assigning this allocated ref as `peer_ref`, which hands over ownership of it to the caller, in other cases we don't. We neither free it though, causing a memory leak. Fix the leak by creating a common exit path where we can easily free the source ref in case it is allocated and hasn't been handed over to the caller. Signed-off-by: Patrick Steinhardt --- remote.c | 43 +++++++++++++++++++++++++++++-------------- t/t5505-remote.sh | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/remote.c b/remote.c index 2c52119bbb2..6ea81f9665b 100644 --- a/remote.c +++ b/remote.c @@ -1344,18 +1344,21 @@ static int match_explicit(struct ref *src, struct ref *dst, struct ref ***dst_tail, struct refspec_item *rs) { - struct ref *matched_src, *matched_dst; - int allocated_src; + struct ref *matched_src = NULL, *matched_dst = NULL; + int allocated_src = 0, ret; const char *dst_value = rs->dst; char *dst_guess; - if (rs->pattern || rs->matching || rs->negative) - return 0; + if (rs->pattern || rs->matching || rs->negative) { + ret = 0; + goto out; + } - matched_src = matched_dst = NULL; - if (match_explicit_lhs(src, rs, &matched_src, &allocated_src) < 0) - return -1; + if (match_explicit_lhs(src, rs, &matched_src, &allocated_src) < 0) { + ret = -1; + goto out; + } if (!dst_value) { int flag; @@ -1394,18 +1397,30 @@ static int match_explicit(struct ref *src, struct ref *dst, dst_value); break; } - if (!matched_dst) - return -1; - if (matched_dst->peer_ref) - return error(_("dst ref %s receives from more than one src"), - matched_dst->name); - else { + + if (!matched_dst) { + ret = -1; + goto out; + } + + if (matched_dst->peer_ref) { + ret = error(_("dst ref %s receives from more than one src"), + matched_dst->name); + goto out; + } else { matched_dst->peer_ref = allocated_src ? matched_src : copy_ref(matched_src); matched_dst->force = rs->force; + matched_src = NULL; } - return 0; + + ret = 0; + +out: + if (allocated_src) + free_one_ref(matched_src); + return ret; } static int match_explicit_refs(struct ref *src, struct ref *dst, diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 08424e878e1..532035933f3 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -2,6 +2,7 @@ test_description='git remote porcelain-ish' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh setup_repository () { From patchwork Thu Aug 22 09:18:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773062 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 A666D17C7BF for ; Thu, 22 Aug 2024 09:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318288; cv=none; b=kgJe8pV0kYBFlENDHs8kmDSO+3odye80PiD7M98l8Wz9ua4U5SrypN2tBG4Vb6uX3TVeLa6CNIFWYUMeGpgnVvKvhKePgya25U2jGVXtwab6badQnaRvFxskN0YE3Xel+XSqnki4NMHB6crYVt9sQ9gHDoj+bEvdmnV6SFgIs5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318288; c=relaxed/simple; bh=Yv2LFQ9ioVW6DdtzwAVt41x9Yh8dQVMyRci6CX3f9k8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bi+WPSq30LIlV12b+8/zTyFcfuN1OVAmfsafNdV3Cj4dzq4ta6HyT4udb12bbFxVfaa/8PXo37fWMilyx9P9qj9FHAPVmtMwRT0XY8MNgfDMoIg9gnbezHhwtfe1YBG2x8jYrv96MgI70N7L9SKNSYq9vOwqbNCJX84j8rmsbGI= 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=lyhKS0WB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ldOmxkAc; arc=none smtp.client-ip=103.168.172.151 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="lyhKS0WB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ldOmxkAc" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id CB45F138FFF2; Thu, 22 Aug 2024 05:18:05 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 22 Aug 2024 05:18:05 -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=1724318285; x=1724404685; bh=cbwJi4s7i9 nVCQ+fBAzIe7l3AWVi4WR8/NABSIWwcVw=; b=lyhKS0WBcyl7ZkFj+06G59Nxe7 P20kR/ncyKvAQouTIbxXjRNxPZzLI7/Xz4x7/AIgn2dtGjtBB2uYypvxbIfn49fA EMTXImrz6hLjLjBfSHSE0JDwWQkN78ho4iKliCXfBMAMzsxGEUMg/m4A9lABIuSQ Ab5QFLbDYEKummx00FO+xmxdtWPtwZBivYtqZj0h6HR4clfFYNU02js3YDh6R9lE gk4aCQAe3pOFMwgFyxp9jegiu297RAxnbhNGGqc1glbhVSSJLZ5RGHwLbpr16KDy UrFFHEy4Pj0a/tJeIL91cIuKHruVshnLa2Rrt2x98y+wdOyHaX+DfKx6C4CQ== 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=1724318285; x=1724404685; bh=cbwJi4s7i9nVCQ+fBAzIe7l3AWVi 4WR8/NABSIWwcVw=; b=ldOmxkAcyJLKUT08HBZTAIlXkVyE+jrb2fpL2N7MIEjU 5QdIArKjsrTLkvXAHtnes7/3LPEXYPrb/zvRWTKvhQZoVbCpredMsImk/y8dQyG6 OmNDyPUmpZ42VPMt2a6zUZ6HIOgo/vCK63TTGRqHqmqVa4/q3DItzWuT5pWN8pVs CIwnlWiFvYoef9LQGHLSC5+DVTeYLZCSa8j+eNRmqhcEuW/LNK5EdeO+lHzX7fjE Idmz1b5ivt7ga/hqbOuK8EVp3CVYlWfXg7CjXBjSe9DhqQVpjYD56mExIkiVLoOX +aQZw99PSOKie5gSmABbTZ+LzzMM7cYevCB7FBwWkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:18:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 80322b2c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:30 +0000 (UTC) Date: Thu, 22 Aug 2024 11:18:00 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 17/20] remote: fix leaking peer ref when expanding refmap Message-ID: <662ec4e6484aa7fc495d528a0b58ef18e3be1953.1724315484.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 expanding remote refs via the refspec in `get_expanded_map()`, we first copy the remote ref and then override its peer ref with the expanded name. This may cause a memory leak though in case the peer ref is already set, as this field is being copied by `copy_ref()`, as well. Fix the leak by freeing the peer ref before we re-assign the field. Signed-off-by: Patrick Steinhardt --- remote.c | 2 ++ t/t5536-fetch-conflicts.sh | 1 + t/t5553-set-upstream.sh | 1 + t/t5703-upload-pack-ref-in-want.sh | 1 + t/t6050-replace.sh | 1 + 5 files changed, 6 insertions(+) diff --git a/remote.c b/remote.c index 6ea81f9665b..8f3dee13186 100644 --- a/remote.c +++ b/remote.c @@ -2081,6 +2081,8 @@ static struct ref *get_expanded_map(const struct ref *remote_refs, !ignore_symref_update(expn_name, &scratch)) { struct ref *cpy = copy_ref(ref); + if (cpy->peer_ref) + free_one_ref(cpy->peer_ref); cpy->peer_ref = alloc_ref(expn_name); if (refspec->force) cpy->peer_ref->force = 1; diff --git a/t/t5536-fetch-conflicts.sh b/t/t5536-fetch-conflicts.sh index 23bf6961700..2dcbe790523 100755 --- a/t/t5536-fetch-conflicts.sh +++ b/t/t5536-fetch-conflicts.sh @@ -2,6 +2,7 @@ test_description='fetch handles conflicting refspecs correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh D=$(pwd) diff --git a/t/t5553-set-upstream.sh b/t/t5553-set-upstream.sh index 70e3376d31b..33e919a17e1 100755 --- a/t/t5553-set-upstream.sh +++ b/t/t5553-set-upstream.sh @@ -4,6 +4,7 @@ test_description='"git fetch/pull --set-upstream" basic tests.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_config () { diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 191097171bc..f75fae52c83 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -2,6 +2,7 @@ test_description='upload-pack ref-in-want' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh get_actual_refs () { diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index c6e9b33e44e..d7702fc7562 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -7,6 +7,7 @@ test_description='Tests replace refs functionality' 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 Aug 22 09:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773063 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 823DB183CC8 for ; Thu, 22 Aug 2024 09:18:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318290; cv=none; b=AdumALrrbPdt+Wk2+yW6pJjTRKjv3pWZs3IhO75YPw7BNTpz+1aRWWf5zuvyZktlN21tQ3wCPKJp4nw5Ge79fzfknmU4qB+wNl4trCP0LkCJkDI60NUU36YSDETZro7yMTVICYO0HNxexACdB7wcvAxIlp2oV5dJeU1RGIKv4bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318290; c=relaxed/simple; bh=QLPG/ImQs2pcRSbXlKo57qxLPs1KHvNODyorTa4JRDI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MCphEn4dP/T1abTnwPbU8WKgvwtfnJK1KwL9eAZOZ5infX2KoG08TaoneXCz3wHYVK0MhcbopWBA/JaaiWYEKo9CZ3k/KiTKTew7m/jqsAcPJ7hbR2rK3vTKX3zULj/jcGDCNIJnFeDgBGv9hyBNeZO80DNHtwTTU5End47DzJw= 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=tl42Dyu8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=l0rNv/6/; arc=none smtp.client-ip=103.168.172.151 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="tl42Dyu8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="l0rNv/6/" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id DAA031390056; Thu, 22 Aug 2024 05:18:08 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Thu, 22 Aug 2024 05:18: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=1724318288; x=1724404688; bh=LmZRIKtX9a uGvNsTj8OGDyx1pMfRoPXBFiMIdsEFrXY=; b=tl42Dyu8SA+5QDe+yCZsfQZUAE IdA9sCK+60J2Y0+AE2jjy6qDFOUfQ8OCIxzW+EzkohTMvv6iK2zuZI4af7UzyhLe hHpZ4sfcmxehUcfrVHvrKTNFQgxyFTM9FrWLerLIxOVXGLgqLtFVLUyzb9562OKP qCYLXrNLLYP9xweNoFv83O9lSa2JMX3BNfgGRRCtDqfLJL9X00kjD1f/bUJKJOgV 7nAA2I9zJ/FoMrzNStEAx8Cmf0sa98KKevWUPfD8qP0d8WpjGHghh8KeJd47x0jH 9nJG4Wld76Ha9wQlFbRpPtZAkOYmDC8eqRE+npZCCOf1/EoA+tX72O0EjtBQ== 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=1724318288; x=1724404688; bh=LmZRIKtX9auGvNsTj8OGDyx1pMfR oPXBFiMIdsEFrXY=; b=l0rNv/6/zkhXOyY6NPFsZclbd1F0qvhVS3yyYXnEdxzt GWFYI6qC+6kddleR+S/rBB6ufVfoSgyaw3oWsRD+8wcPo0mKRzbeyogjSKUuyE4I gu+dg0G0ohKFkGSEkeYT+KyG7TLV2PB1sMiK+zd5+cN9bM/t62kGsKXjqKgBluIc +hjhGZgA61NQc0LPST2HGY3sdUPjEB7a3lt9cTjmpaUzdBEn1wgRDK/CZaenQfjZ ZJgVoLuukag9Yj3p18g0GMUTgucocRdLQqh38vuKN0ej1GqMGRkOdpQU/5ULv0kp buJKfLJdcUY9Nws94G2y8GIrv7QsTDF3l5MlMnUwDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:18:07 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7e07a510 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:33 +0000 (UTC) Date: Thu, 22 Aug 2024 11:18:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 18/20] builtin/fetch: fix leaking transaction with `--atomic` 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 the `--atomic` flag, we use a single ref transaction to commit all ref updates in git-fetch(1). The lifetime of transactions is somewhat weird: while `ref_transaction_abort()` will free the transaction, a call to `ref_transaction_commit()` won't. We thus have to manually free the transaction in the successful case. Adapt the code to free the transaction in the exit path to plug the resulting memory leak. As `ref_transaction_abort()` already freed the transaction for us, we have to unset the transaction when we hit that code path to not cause a double free. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 8 ++++---- t/t5574-fetch-output.sh | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index c297569a473..0264483c0e5 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1731,11 +1731,8 @@ static int do_fetch(struct transport *transport, goto cleanup; retcode = ref_transaction_commit(transaction, &err); - if (retcode) { - ref_transaction_free(transaction); - transaction = NULL; + if (retcode) goto cleanup; - } } commit_fetch_head(&fetch_head); @@ -1803,8 +1800,11 @@ static int do_fetch(struct transport *transport, if (transaction && ref_transaction_abort(transaction, &err) && err.len) error("%s", err.buf); + transaction = NULL; } + if (transaction) + ref_transaction_free(transaction); display_state_release(&display_state); close_fetch_head(&fetch_head); strbuf_release(&err); diff --git a/t/t5574-fetch-output.sh b/t/t5574-fetch-output.sh index 5883839a04e..f7707326ea1 100755 --- a/t/t5574-fetch-output.sh +++ b/t/t5574-fetch-output.sh @@ -5,6 +5,7 @@ test_description='git fetch output format' 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 'fetch with invalid output format configuration' ' From patchwork Thu Aug 22 09:18:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773064 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 8C693183CD1 for ; Thu, 22 Aug 2024 09:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318293; cv=none; b=Tm9+rQyrDSPIUqmVhOESJKP6ge0/UIrpgkq61IaghxUFfnAcIhd3Z7WzZXKdeLg1jTAUwSEkFOL85TFH2JajAK/R1EpDsqks9Wdff8Cp/QNfQWKfAOW3A72ZlhrmOam+4IvoDRDlY0fGlVlimvBQ4l20fnUUmcZG/nEol/beaq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318293; c=relaxed/simple; bh=KGTrF1nVZqe0T4wrRT9oC8ZfdyUCevGPeGA/nLh1AOg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SGgmN/f29NrkUYpJYpkRFsdd66qayHZRaZnWUAhV1iHFTwvRrnWvgP0eUgiY4FOQ8SPizLxYH/VuM6PYtj0uWgv83nqAPbjyDF0icrkKrB3hM3db7balAsmt2EJXfCmEGSgvwO763FsQGRiqFrmX+MP0QgbsDDDFm5mBgUFT+R4= 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=l+FjFwS6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=G5Khqy+u; arc=none smtp.client-ip=103.168.172.151 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="l+FjFwS6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="G5Khqy+u" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id DC598138FF98; Thu, 22 Aug 2024 05:18:10 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 22 Aug 2024 05:18:10 -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=1724318290; x=1724404690; bh=/TZfNtkh/g qpjSQj9MHYC9i3YyUq1cTJJ2xITw17alM=; b=l+FjFwS6DR2K1H1TOErz9HRxPy zOGDWt9BlDpMyUFUc3k+szQMvCbgpvzo+ZAk29lHpFcwN0w3ZWljCSYx0eP+cHW4 pdyMmU9ZwmCmnpPwMdyIp8/899ZXL6jqU1x8G/T0ePv/7ztEIZ/nOrwBUaZKzj3H Vt5Orke2A+cUXocY6t6mF5KFZTcdviGGm9/RcNicf1UPgJmwaoCa+tgL9jZd93dy +sRnFwB1yqe58m2xcBL+tCbz3YspxqQMHLZ/RsRTxLgpE8Gnkqx0an3lhwAhqR0i 0EsT+JSnbVUcHp+6BGISHLhk5qMOD3UPPxw8FW0ouCtH1pMXW9EkreV+jzZw== 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=1724318290; x=1724404690; bh=/TZfNtkh/gqpjSQj9MHYC9i3YyUq 1cTJJ2xITw17alM=; b=G5Khqy+u016k762VteNlFsT+ULBKxay099Z+QjRQ898H vJQpIn5dk5fKmooAwo63ScpHZMnS1UIORYUuPNxSGfj0HBm6NR0E6SluMLyAiwys lIYaMH8Nkpx7TVcA8kytrQmKqdYGWCX0+pgqnRH93RjTdLdXcXgGlqsy2xy2Pz7R ul9thsJ+p3VgMZljWu/sul7e4nZRbUG8L2TGIq6vH/wG++NrgxI6S/Sspy5vTAMu d3fkmJNqW4kku1aAwsIifWYyMt9azRy6QQF+6asOxIM0ykdt8mVn4+InXPc06wXc b4N03gF31g1Kutxd9/A/rrbQ9RdUnKcria7P3qr2TA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:18:10 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 03b96ae9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:35 +0000 (UTC) Date: Thu, 22 Aug 2024 11:18:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 19/20] transport: fix leaking arguments when fetching from bundle Message-ID: <4c5740afe43c3bb619a9cba0c1634097c27ed33f.1724315484.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 `fetch_refs_from_bundle()` we assemble a vector of arguments to pass to `unbundle()`, but never free it. And in theory we wouldn't have to because `unbundle()` already knows to free the vector for us. But it fails to do so when it exits early due to `verify_bundle()` failing. The calling convention that the arguments are freed by the callee and not the caller feels somewhat weird. Refactor the code such that it is instead the responsibility of the caller to free the vector, adapting the only two callsites where we pass extra arguments. This also fixes the memory leak. This memory leak gets hit in t5510, but fixing it isn't sufficient to make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/bundle.c | 2 ++ bundle.c | 4 +--- transport.c | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/bundle.c b/builtin/bundle.c index d5d41a8f672..df97f399019 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -220,7 +220,9 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) &extra_index_pack_args, 0) || list_bundle_refs(&header, argc, argv); bundle_header_release(&header); + cleanup: + strvec_clear(&extra_index_pack_args); free(bundle_file); return ret; } diff --git a/bundle.c b/bundle.c index ce164c37bc8..0f6c7a71ef1 100644 --- a/bundle.c +++ b/bundle.c @@ -639,10 +639,8 @@ int unbundle(struct repository *r, struct bundle_header *header, if (flags & VERIFY_BUNDLE_FSCK) strvec_push(&ip.args, "--fsck-objects"); - if (extra_index_pack_args) { + if (extra_index_pack_args) strvec_pushv(&ip.args, extra_index_pack_args->v); - strvec_clear(extra_index_pack_args); - } ip.in = bundle_fd; ip.no_stdout = 1; diff --git a/transport.c b/transport.c index f0672fdc505..da639d3bff0 100644 --- a/transport.c +++ b/transport.c @@ -189,6 +189,8 @@ static int fetch_refs_from_bundle(struct transport *transport, &extra_index_pack_args, fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0); transport->hash_algo = data->header.hash_algo; + + strvec_clear(&extra_index_pack_args); return ret; } From patchwork Thu Aug 22 09:18:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13773065 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 96265184532 for ; Thu, 22 Aug 2024 09:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318296; cv=none; b=owNQDA77GqRb9d0JS6IOpO0gnFKSQmvxJXb27zM+3RFY3pkjj2Ls2/wsuP563isqUGuphQgc4eLhsSgCXCEbsVXp4jav/TOdscY9YTEOnqEtmWjenzVPjKCBskWKGwrcBPJiVG0ccd7fAK2jGa2XzArWuMfHqSfbALhZp9KuKHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318296; c=relaxed/simple; bh=zwg0kB4Rcsb8XD2nW8KQ2yJ+gZvuwV/Z3iVedjkkw2c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R9VclsmUo5SrcROzmbzj7UCjUed/MQLlwew/23ZT0kHAN4MDzzJxFTBwkXKnkZvHtMIPtfftJm3gVVr44Vn0e0DUDSovqcnSuEF8ZkNw1WLb7m8Bm/Ovd4F+zwqZkTUkD1j3hvynSQl7QJ47ic+DDdDrjx9x+XUS31ZgXLmqtoA= 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=nnS+AQCy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PLOWr/sd; arc=none smtp.client-ip=103.168.172.154 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="nnS+AQCy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PLOWr/sd" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E52221151BA8; Thu, 22 Aug 2024 05:18:13 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 22 Aug 2024 05:18:13 -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=1724318293; x=1724404693; bh=Fx58xHcaAV XHT+2XgotGrdn2miPfx3kVxV8MC6HNayM=; b=nnS+AQCyOmpU3ElFQOweEEoIBv xpDGUoEsWLl95dXMGyouw3X7Ol6IP4hhdw8cl1dZBpPPl6vqm7KwBClqYUCMN5l2 bwSVpV50mLFyEnwUm/8wIFht7VpsijBkBDvbXdArfqN7eETu97sdYUJo10coZN80 DqvmgRLVH+sLS2hj4XcvGOBPDniyctwuLfVOiXxhACISZhsiDAtm6QucKPpQN3S9 O7N8mB1guToaYx0BEK2IAOKYOdkREGW6o5eHjwaI6927Jg23sz7FIl1tv17jq/ez FUWX6nwvp5PwZC26NHqRqZv+LOor9+/ZfRhc9Hr250YJiFpMmNDvC1INA1Aw== 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=1724318293; x=1724404693; bh=Fx58xHcaAVXHT+2XgotGrdn2miPf x3kVxV8MC6HNayM=; b=PLOWr/sdSH6gJhglZDH1tQyhtBggUUdhg8pPuCRnJKB7 pEh0w9yHRBHCD9nHGQz9oXyv7Pl3EU/qF2pb7x9NjY8BMmwJWBxN7ziOalsK3yRu XclJ6QDcmMMoad5KyhNFJY9EydYyIX9wMRd1+6fDlX9tosC682NPaxFWpdwc/My9 1W379VOFxod5wiGaesMiTn6NCWBooAW0HMkeq7T9OYj7TVRy56RuQHZN9XcBde2J GGSHEAVFA7RN+L4Obvn/exT30iU+Pdk5azNHkhhWq2O+biMuxVBDlzk4sl1DA6+M XzQQJgqpHNxYLbyB8pQlOIkNPjME/RGHk7+YOh8neQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvtddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvve fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevkeekfffhie dtleduiefgjedttedvledvudehgfeugedugffhueekhfejvdektdenucevlhhushhtvghr ufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtshht vghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 05:18:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6570c4c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 09:17:38 +0000 (UTC) Date: Thu, 22 Aug 2024 11:18:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH v2 20/20] transport: fix leaking negotiation tips 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 negotiation tips in the transport's smart options. Fix this by freeing them on disconnect. Signed-off-by: Patrick Steinhardt --- t/t5510-fetch.sh | 1 + transport.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 3b3991ab867..0890b9f61c5 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -5,6 +5,7 @@ test_description='Per branch config variables affects "git fetch". ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-bundle.sh diff --git a/transport.c b/transport.c index da639d3bff0..0f20fc56e40 100644 --- a/transport.c +++ b/transport.c @@ -947,6 +947,10 @@ static int disconnect_git(struct transport *transport) finish_connect(data->conn); } + if (data->options.negotiation_tips) { + oid_array_clear(data->options.negotiation_tips); + free(data->options.negotiation_tips); + } list_objects_filter_release(&data->options.filter_options); oid_array_clear(&data->extra_have); oid_array_clear(&data->shallow);