From patchwork Tue Aug 13 09:31:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761646 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 06E1C17C235 for ; Tue, 13 Aug 2024 09:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541470; cv=none; b=ggoVH1dPiO1eivflhdSzv5+Zo6o5war59mXStkBa7GS+wPvzGE/L8IfIgs1a6pQh0x9R531ABNlmskiwMnRh0mO5L6bb7V0zbSLvc8QOhF9Lc1No35z6B9XqKRI0zpqIBc5KB/5Ec3tZ7FmHvpFvMw3OVtYYKQ9rwBAu+9AaSMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541470; c=relaxed/simple; bh=libDPasjwERHGMXBJcJ0Dh5QJzvBfdxylv8HNoT6a+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fac0yB31ShXAfEk70GZoDaJLfhEYA8gJ2oNvoLycePH6+OU4qO2+S1HnOoQAa7ZFfvnY79vd7v8EtxdZhxld1zKgSSB9L+ErNnAYpgEBn+V8v60sYHzbp1DlA+/+4LpRANN7tK+C4XBdh7tbyWaHup47G++Sxk2T74KCx7D5kkw= 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=P016BOYw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XXRbYAzS; arc=none smtp.client-ip=103.168.172.146 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="P016BOYw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XXRbYAzS" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 1A164138FCFE; Tue, 13 Aug 2024 05:31:08 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 05:31: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=fm3; t=1723541468; x=1723627868; bh=vWD7zvYfuB lMluFTJnwI+L7GOLzXt6QD1KyiY7vDzFY=; b=P016BOYwTqnYMfsHzitdDyP0y4 384A0XGerDClovdKEU2AGU9FEaI8yYwaEYeS3216KoZLAjVSTZSq1eGDj4e875wG Zy/vOKpgKmAfZgztAMXUOZMagDJ8Fs2Q7UcLLkTTM0HH6VdBJlWiphJq7KHQrdk1 tehIcDV1ipFCXSFmmAm4vc5RQYr7lFuwEP2bWR2Q/4UhdZTJucOcxZHBaRAh6QDr x6lsRtvwm+AxmCp6DGTJTuDJVh5s9sRYadWG5INTKuL1aG8B5Azi+zs2UTsjrC0w lXS8u5T/HvrOKM8WywT16jSb6MjS0DIPr4fLv/POqbmeUZGjmdFEFTJOj7zg== 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= fm3; t=1723541468; x=1723627868; bh=vWD7zvYfuBlMluFTJnwI+L7GOLzX t6QD1KyiY7vDzFY=; b=XXRbYAzS+/6c3CpsHVF2EbuJZrF7FicD+nP+chs8aIz3 UGDpPUzF9tu4dMtlo/sN5zsW1lv6tVSkeGa0rzj8bDU6wD6wAQ9ystDSMC9W8tEu 5BD2h/OCSZaV2jrG8JYIYK0PuSVWp7wYNYJbeC/OZbJ7fojMqvk0nSu0EYKSH6v/ ecu6xSFAYRNeF3rae1VRULPcEvbxoZ8NntgsMOm2dcqg7vNRPybGEwlur9fqzWZN eShF10h2K0qKMq55QDCSXGImIKeBYtYCQaRurlfH81exuxFbCgCzNMXDsFxEO+5l 81AweFnxfY2o1zsV1R9dlOxk72mrITQUB5s/F6/fJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtph htthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrdgtohhmpdhrtghpthht ohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehmvgesth htrgihlhhorhhrrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdr ohhrghdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3607a6b0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:30:50 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 01/22] remote: plug memory leak when aliasing URLs Message-ID: <02f6da020f083b3cedcdff192595438ecf82bf56.1723540931.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 we have a `url.*.insteadOf` configuration, then we end up aliasing URLs when populating remotes. One place where this happens is in `alias_all_urls()`, where we loop through all remotes and then alias each of their URLs. The actual aliasing logic is then contained in `alias_url()`, which returns an allocated string that contains the new URL. This URL replaces the old URL that we have in the strvec that contains all remote URLs. We replace the remote URLs via `strvec_replace()`, which does not hand over ownership of the new string to the vector. Still, we didn't free the aliased URL and thus have a memory leak here. Fix it by freeing the aliased string. Signed-off-by: Patrick Steinhardt --- remote.c | 2 ++ t/t0210-trace2-normal.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/remote.c b/remote.c index f43cf5e7a4..3b898edd23 100644 --- a/remote.c +++ b/remote.c @@ -499,6 +499,7 @@ static void alias_all_urls(struct remote_state *remote_state) if (alias) strvec_replace(&remote_state->remotes[i]->pushurl, j, alias); + free(alias); } add_pushurl_aliases = remote_state->remotes[i]->pushurl.nr == 0; for (j = 0; j < remote_state->remotes[i]->url.nr; j++) { @@ -512,6 +513,7 @@ static void alias_all_urls(struct remote_state *remote_state) if (alias) strvec_replace(&remote_state->remotes[i]->url, j, alias); + free(alias); } } } diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh index c312657a12..b9adc94aab 100755 --- a/t/t0210-trace2-normal.sh +++ b/t/t0210-trace2-normal.sh @@ -2,7 +2,7 @@ test_description='test trace2 facility (normal target)' -TEST_PASSES_SANITIZE_LEAK=false +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Turn off any inherited trace2 settings for this test. From patchwork Tue Aug 13 09:31: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: 13761647 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 9921416BE2A for ; Tue, 13 Aug 2024 09:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541474; cv=none; b=Ng4TtI1SDBYOJVVBkJcbLr9KWB4TPny+Rpxf40UCu2DzqaVRTXevE5NUNCDvY6R69bAjL4ZWktcWVI04nUPOi+ZE8BmCdfEvye1ri/AiZRSdm23zJdjzKVMEZcF2wm2bVfxGLu/lIhdDyMHXJobOZkTyJbN/A2mQpMPDtkmGdk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541474; c=relaxed/simple; bh=AzUj8spFAxsKjMaTFz5FGByM6NOtBXz8D0GKavJxcGo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d27GLSPcdAVpxZ7Ij0zG+BUX4x5NtwyvuvSfIDxH7HHDE967iHr/Xn8vMQ9luYB9J/+ZZOunHe1d/jgaIhtn1IQR12jSFYMcXmIFPyif9zyyVKDziAVnl1W+rOKgNffyFJ3tLinKXplC7TDIUdHax8SOTEoGkNlZHbGUTgcZ/W0= 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=NdWpEiXc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=n8y2+zsp; arc=none smtp.client-ip=103.168.172.146 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="NdWpEiXc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="n8y2+zsp" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id A0C3A138FD2D; Tue, 13 Aug 2024 05:31:11 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:31:11 -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=fm3; t=1723541471; x=1723627871; bh=ZCyjENfYzz oX+ZOFJv6cSiPv2bzvUen9/0czNnq2aA0=; b=NdWpEiXcmzP0uoMf2tUBkEbnM9 V3wNQTBzCZLuwmyXMby0JknoDaIbAnT8KXjogvX/lvJ5UayFllIFZ7Qna0afGew8 /clM5HwVhPDdn6SMmEX7eiTAP1FuYt8ZAaNwKN19t9uhkVXkMYkoB/Yeq0d6l0xx NgctC6lwegNCH/jJNlmbsuZgGBxVOpddfB2c3k90EuvgSTnpNMpH1b2Kq0T12Sfo 7UKRr7O5u+QKzxua0RlsH1DXvie/uuS3DD0jYURjp0RgLSu4mOqrhwjxsmO9bkf8 6ZsFeFqyFQ7gbHooxblb730anCN1LE0x5Rw82c0j4nhMi81CM9mPZqGPQM0A== 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= fm3; t=1723541471; x=1723627871; bh=ZCyjENfYzzoX+ZOFJv6cSiPv2bzv Uen9/0czNnq2aA0=; b=n8y2+zspWDtLDXuer+HXY+bIOzA5SfkkC53Qq3b8uv9Y 2rQ23cv5Krnd522mwQVCFV90ntX3kJJ6i8IWej41zOFG3DW6tYoEqbXOwR+nqx24 acit6IzXw4QMmLLGHEV6tlZO9x6oi1gawbQ4tzGjHiI6qNx83b/Zh/9cxYDR4ajt eXljTRX37GgL+AxNGvtnWwzh7WqNOoLG4KazGJyJKqdT/+bggyZ8iWifVpeF8qxS VEIvgi8sgUeVq8iscJiynZDzMMglFqRIgBc8Quf+K4exzaSIlrizB2dxNwZZlwu7 4hrmtKIh7rN+HWmqLObANOFplIV7fjy4qwSUXWHrmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepkhgrrhht hhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorh hrrdgtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtphht thhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:10 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eacd7e1c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:30:53 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 02/22] git: fix leaking system paths 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: Git has some flags to make it output system paths as they have been compiled into Git. This is done by calling `system_path()`, which returns an allocated string. This string isn't ever free'd though, creating a memory leak. Plug those leaks. While they are surfaced by t0211, there are more memory leaks looming exposed by that test suite and it thus does not yet pass with the memory leak checker enabled. Helped-by: Taylor Blau Signed-off-by: Patrick Steinhardt --- git.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/git.c b/git.c index e35af9b0e5..9a618a2740 100644 --- a/git.c +++ b/git.c @@ -143,6 +143,13 @@ void setup_auto_pager(const char *cmd, int def) commit_pager_choice(); } +static void print_system_path(const char *path) +{ + char *s_path = system_path(path); + puts(s_path); + free(s_path); +} + static int handle_options(const char ***argv, int *argc, int *envchanged) { const char **orig_argv = *argv; @@ -173,15 +180,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) exit(0); } } else if (!strcmp(cmd, "--html-path")) { - puts(system_path(GIT_HTML_PATH)); + print_system_path(GIT_HTML_PATH); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "--man-path")) { - puts(system_path(GIT_MAN_PATH)); + print_system_path(GIT_MAN_PATH); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "--info-path")) { - puts(system_path(GIT_INFO_PATH)); + print_system_path(GIT_INFO_PATH); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { From patchwork Tue Aug 13 09:31: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: 13761648 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8A7E186E52 for ; Tue, 13 Aug 2024 09:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541476; cv=none; b=f+m49yT6SSgMZM+XHNUxq/owOinJNqamqrnIKsTI+pzx1paCgd3hBnq9f3fwns6vmX/WXP3ACOH4BSOoTEKrz1y5HSA361ywbCOXZAOMdQ1qiB+zdw5VjV6wB2neiW8D4UQakysHXQVuhlA3vCAaHMNzqR4vF8R8Wz/soh77YVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541476; c=relaxed/simple; bh=hoFFcWuv/vPMkUdi5Yo7jCwyC10IxIxjt9eqsrkZNsg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P9dO7hIvYXH+NMYief+l+r6q9eDno2Wo2ctlLIXPLV+1H0C7mAX5UencZMrfnCTsWNraDc226WFOBHaTgaLIWePewEud3W7hAEqKEyAa23aQCvppmS2zgaK2MbAbFtSweqicBS4CljkQz7eje73LZfW6dUq44SCbPVxq2r45gFk= 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=B7mBrfuu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BTOMTlD/; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="B7mBrfuu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BTOMTlD/" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 36996114EA7D; Tue, 13 Aug 2024 05:31:14 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:31:14 -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=fm3; t=1723541474; x=1723627874; bh=zF6cR7mg03 Nqj6lX7Glae3/XyFq1o41rAfNOBYrNcFA=; b=B7mBrfuuZi9u/kVHrZgAkOcynl QVNbHFpobmN9zWxIOu7IFNa61fsiXEBDJX4pLAVn/M3Uye+REEgZk/SQop5g16LG +9t03Z5Y1K77HY5+ywPgB+wQ9Cih4VmU58lj/bqM3ZAk9jMDg1Q7ScaqdO0HJg1P XLkYNllCjXsbjyN89eefuStBdtih3BJ7i66GOl/Ghrcu46y9QGdVnLYxobOrAgNt KiGUlOXywwuzbhy4riyPa+Fyjlr4u8UXiSg+ARKD7zVk51wnnRXIBYV9fjDFKQ90 HYHK50d+rD8uiBXtvyz/ouQPw1fscSrYgraGmZvv6LzEw4N4dqfBRKHl3eEA== 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= fm3; t=1723541474; x=1723627874; bh=zF6cR7mg03Nqj6lX7Glae3/XyFq1 o41rAfNOBYrNcFA=; b=BTOMTlD/zVT7oqGRN+z1rXXQfi8SXkQg6NKsIz96Z07u zWFgGq01i+r4dnTL9hgLtcQeK4IDFkl01+ZAwZ8bkPbOeiEsqeANouxS5r8Qgzxc VP6KcsvlyBRYG5o1OVqVHDL8FFEXBbezckF1gRRt1KOBst0a7RPBiErsuWn4xs3s cscBhQxOs+sjlWs0rx8D2LOVGpjGjMKRWDEouLKm2z/IK/CImimAeDDAMoRRIGZH KnDoq8bcnm9J6ttMrDoWK7AhJwmsfji4wRfo9QuRCqBnLMd3QpzdhGPsYYzojfhM 2Z8UaJ+Y1Mkn1VM6VZr8kUfrdlqYZ85jJzdkAre6lg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthhtohepmhgv sehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehphhhilhhlihhprdifohhougduvd efsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:12 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1d342611 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:30:56 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 03/22] object-file: fix memory leak when reading corrupted headers Message-ID: <0415ac986dc8c04917502a1bb0b03afcca47ec67.1723540931.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 reading corrupt object headers in `read_loose_object()`, we bail out immediately. This causes a memory leak though because we would have already initialized the zstream in `unpack_loose_header()`, and it is the callers responsibility to finish the zstream even on error. While this feels weird, other callsites do it correctly already. Fix this leak by ending the zstream even on errors. We may want to revisit this interface in the future such that the callee handles this for us already when there was an error. Signed-off-by: Patrick Steinhardt --- object-file.c | 1 + t/t1450-fsck.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/object-file.c b/object-file.c index 065103be3e..7c65c435cd 100644 --- a/object-file.c +++ b/object-file.c @@ -2954,6 +2954,7 @@ int read_loose_object(const char *path, if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), NULL) != ULHR_OK) { error(_("unable to unpack header of %s"), path); + git_inflate_end(&stream); goto out; } diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 8a456b1142..280cbf3e03 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -6,6 +6,7 @@ test_description='git fsck random collection of tests * (main) A ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' From patchwork Tue Aug 13 09:31:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761649 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 C018518950A for ; Tue, 13 Aug 2024 09:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541479; cv=none; b=p5+SreC8sAQXdQ/j0Fuhyaz3T9OL54ALIbL7lHh6yTGzvI+peZusBDv5ThNItj2WSQtSpph+fjUs8v133Maj+YxIy3wm0FE1dQNoyIvKBo9on4bdDsRbWczEupt1Q9kO9Cu1q5pdN/obUSc74kPXNQmQBOOLuzy7ziuLJWBfydE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541479; c=relaxed/simple; bh=luZlTz2hTI8YLT4pNO5tz0if96yQMyYh73CZ46a0rCk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hVkMPPreCSbNE91HJreeg3qbtHpnRqWO2FIRojt1n5nHkOsslZ2zsaSXzC2UviURGzT9n/75+sPE4mUtqnref9VfiBjO+3klrARhX9I+WmQ3wdFfLRwll+Ra5ppEk9P81ljbPzPGumqgzZHaEVGE0/MWqbCofiECaRCGNmbi8Hw= 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=MCtk8QGP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BpVceFSj; arc=none smtp.client-ip=103.168.172.146 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="MCtk8QGP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BpVceFSj" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id CD366138A055; Tue, 13 Aug 2024 05:31:16 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:31: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=fm3; t=1723541476; x=1723627876; bh=vAJymv3/2V GXDhjMfmXOqsXr79Vg5+j45QHKvwZBsks=; b=MCtk8QGPS9EeJIF9xNV+Qv0YX6 pkzj3byRAdGDkVuwvff6E4SxVJALsGXSeAF3f3OsPU/kBf1naJ/PaUZeIN14R11X 3+v27iDfoGEHx5YE0w3tThtLnRGdQsfpWVc/HbgXv7zQekXSv8Ti3yTXUE3wm4fi sqgXeESSENQ08oaWJpLVYcx6Wh2ou9kLKoSGSA+wkaXXqHJ62U4OfxjtJT2K1k75 Mg08aEvlP2zUHggb+agb16Bt8qwQwduouWlHWWtOK5zhoGcSShsOdQbIdUSutmOc n4vbpTRuqEH7BrsHEthlYy0Zo1ZSuUctEuXCcAvctCRWUCQPg0RuwtQ89PHA== 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= fm3; t=1723541476; x=1723627876; bh=vAJymv3/2VGXDhjMfmXOqsXr79Vg 5+j45QHKvwZBsks=; b=BpVceFSjaycB2Z2UK8aCYSZ+PttS4v/wqOzgk8gEDNlU 0DVpIwrbmdK2QyoMS4NibIX33m6AdqNqToyBspQZ1pu7GluzWF04dA3LcwTaRyAY oSx0AxAJVQXcCOosoY7uu83NeH17V8o0YGajjnY6QpL1jCjwx5K+Bc7Jq8PoDMwh X5TbVjyx1CzpveguE9einadEO5chZKYiLQnMmEiQZlFQvQl950085eLSlzDL/RsW KhJkhZSXl/skLq0pxU4v5SynI7Uvx+HXwJUoaONMZ9qCRC4a8tfeELhpnLl0TsPC 3ysf3e6T/0oiV2YrWgfDFfiG0BwJZav4o8nP7LF/WQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtph htthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrdgtohhmpdhrtghpthht ohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrh drkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdp rhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:15 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b0193331 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:30:59 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 04/22] object-name: fix leaking symlink paths in object context 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 object context may be populated with symlink contents when reading a symlink, but the associated strbuf doesn't ever get released when releasing the object context, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- object-name.c | 1 + t/t1006-cat-file.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/object-name.c b/object-name.c index 240a93e7ce..e39fa50e47 100644 --- a/object-name.c +++ b/object-name.c @@ -1765,6 +1765,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name) void object_context_release(struct object_context *ctx) { free(ctx->path); + strbuf_release(&ctx->symlink_path); } /* diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index ff9bf213aa..d36cd7c086 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -2,6 +2,7 @@ test_description='git cat-file' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_cmdmode_usage () { From patchwork Tue Aug 13 09:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761650 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 496F1183CB0 for ; Tue, 13 Aug 2024 09:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541484; cv=none; b=UsNBbBZz7vA1D+8wExIgEiBJZFrXiz+OyHEzZyXuaxxnm1SyTIKZWxa50cyqIwogydVbXLJ/6wO+Dzt4HGGhQ40UrbwkVjullmz2AgthM5SirtmSv8EJm4A7rHXqbPWM+Ptr3mbaYbnUOXGsQRCz/8/9RSkNH+AS0+mR6ycZ6js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541484; c=relaxed/simple; bh=JUm3lsJilsFV1O2dMe3PbxtbybHfB4GcBuGmCDuimkw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O9yJpx0bg1kZ+VkWaR4TAbwXsd5FO9aWMj8NchWbbdUkaH2xQDqaquj6UBxC21UoRmmtWIQCgPZqz509PMpPXYeiziD8qFnkQs/IL//WkJJD7yLNOKtBTS9JkZo02B1comKYdZZ7Sty7hQWMumsp0AEbZNNhvNJbXdxuh4Zirx8= 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=qdK5fvLd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fx5CSK4l; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="qdK5fvLd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fx5CSK4l" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 732BE114EA7D; Tue, 13 Aug 2024 05:31:22 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:31:22 -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=fm3; t=1723541482; x=1723627882; bh=iKG4mzjCkG I7jcaSdTJ/I0imjWoGH0ua/2Y5iqWAZio=; b=qdK5fvLdZxmZhNcShVb0OPr6o6 cBVk9OIUd7mJBWB6p2NPTz/HOKXxnR/JivCEesw76Mpgm143SmSs1adf69fzOeaE cn3bn7Y+qswc3W1p/oaRD2uDfYZ0nwjZhJWfStqTPES/BsUigHIRS+VfQgR+/m8x pTbGVT4qN5j9ymDu8sxcvFlYhfIyQCd4hDIJQq9G+tDwoQsoC2Al/MivC8t7X1wn V5xvb8z6AOPVi23UIHD/Lr0gPrABDTx4e6R84uuTTbHNZO0gmu4GRRpCq68rStfH 1zOoTuheTbpqhRUyMSsVBrkhsDGqpa2S7mEOoC+XwxG5RJV/o0ZrjaVC3cgA== 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= fm3; t=1723541482; x=1723627882; bh=iKG4mzjCkGI7jcaSdTJ/I0imjWoG H0ua/2Y5iqWAZio=; b=fx5CSK4lGTsbDrQEF9qNGFKOuIu2giQ03JST77Ux+w/y 9ZBe+WUSIhLRWXt4mCImJqpofgmXCHb5WRQV0A6RH3Pu5+JbgLYRpJpaJEWAzF5Z NQSOgJYW6R6SrXd76IkRJD3i9IapLvfDuVHCCT9gh0gsEeBKiKuZLZU/tsX3Kkmf 1fEuCVDQV1NUys0awFVbHZPVLn68HYx0mvCsuPsZQJ/AGchkVQ2mf1ltR8PTobnv u0G7kbuK2BdRkoOilZyTYvtBnvk+vwdnN64ebTl4+oI+ehLZS49xySGDIqxR3ULH LBzM5HgZ7zc0oVaEHo3oQzqjNnm0VsKRFLprypgjOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepphhhihhllhhi phdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtshhtvghrse hpohgsohigrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdr tghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e62fa2cd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:04 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:17 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 05/22] bulk-checkin: fix leaking state TODO Message-ID: <276c828ad18c422c7cca0503e336c8aee8aeb149.1723540931.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 flushing a bulk-checking to disk we also reset the `struct bulk_checkin_packfile` state. But while we free some of its members, others aren't being free'd, leading to memory leaks: - The temporary packfile name is not getting freed. - The `struct hashfile` only gets freed in case we end up calling `finalize_hashfile()`. There are code paths though where that is not the case, namely when nothing has been written. For this, we need to make `free_hashfile()` public. Fix those leaks. Signed-off-by: Patrick Steinhardt --- bulk-checkin.c | 2 ++ csum-file.c | 2 +- csum-file.h | 10 ++++++++++ t/t1050-large.sh | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bulk-checkin.c b/bulk-checkin.c index da8673199b..9089c214fa 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -61,6 +61,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state) if (state->nr_written == 0) { close(state->f->fd); + free_hashfile(state->f); unlink(state->pack_tmp_name); goto clear_exit; } else if (state->nr_written == 1) { @@ -83,6 +84,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state) free(state->written[i]); clear_exit: + free(state->pack_tmp_name); free(state->written); memset(state, 0, sizeof(*state)); diff --git a/csum-file.c b/csum-file.c index 8abbf01325..7e0ece1305 100644 --- a/csum-file.c +++ b/csum-file.c @@ -56,7 +56,7 @@ void hashflush(struct hashfile *f) } } -static void free_hashfile(struct hashfile *f) +void free_hashfile(struct hashfile *f) { free(f->buffer); free(f->check_buffer); diff --git a/csum-file.h b/csum-file.h index 566e05cbd2..ca553eba17 100644 --- a/csum-file.h +++ b/csum-file.h @@ -46,6 +46,16 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *); struct hashfile *hashfd(int fd, const char *name); struct hashfile *hashfd_check(const char *name); struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp); + +/* + * Free the hashfile without flushing its contents to disk. This only + * needs to be called when not calling `finalize_hashfile()`. + */ +void free_hashfile(struct hashfile *f); + +/* + * Finalize the hashfile by flushing data to disk and free'ing it. + */ int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int); void hashwrite(struct hashfile *, const void *, unsigned int); void hashflush(struct hashfile *f); diff --git a/t/t1050-large.sh b/t/t1050-large.sh index c71932b024..ed638f6644 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -3,6 +3,7 @@ test_description='adding and checking out large blobs' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'core.bigFileThreshold must be non-negative' ' From patchwork Tue Aug 13 09:31:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761651 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9769184554 for ; Tue, 13 Aug 2024 09:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541487; cv=none; b=SaymJNc4ieeGQJixaiD+hCUG1SMt/Tauv+C0EXjF54n0CUZaB5DQQ8O833fwEGF0GXxxXArQJPG4uY4n9IZ8tqw08tqFh6lrIw5O4YI7RVkjmHBmNj+F7g8rc50sMattKY5RMG3jnKBnMs2ui8NZow2ZR9wUXTB58w3oDfRGUyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541487; c=relaxed/simple; bh=dAZYz0j98vNnestOGKXW2iOYHIoBsZx/oj1Z4PZF0eQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Vzt4VN8qgsfjpl8XYJFnSWBFlkHRQX3QvQWI7lyv1VTEgyPTBvN7TnbE3wIGHnwCgIbCZf7/Pt9XvuVV5G0Fq753yQLnbxf4JAJ8iJSKrUifSsqkrsiKr0qZkST/M2oEDh/nZXaPTCidrUZ1Q+Zxc7cWEh6NXUUlsM39PBdN7HA= 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=mFoQcFZg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=boYNA9BD; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="mFoQcFZg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="boYNA9BD" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 162C41151B39; Tue, 13 Aug 2024 05:31:25 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:31:25 -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=fm3; t=1723541485; x=1723627885; bh=95K6mA5Ybu 4amAaRvVVRKZHzdzJH9x1N6WV3yk/phGA=; b=mFoQcFZglPzPewHkFsz7O++bNn avf4VJioMuu1PgjgzwemItauc0Hq08MILeMdbSo13/yKYUlSrRQ1jtPO1+ThVt5x 8d156iK1wHgBnItsgS7i8iyPLRbez0LgPUqUPgTmWuRO7tSVSN/g3wq03Hmmv5UQ fkmH+z5376P6CGbrjx4/fcKOTUMwjBuddsHAXzw5sL8sydr4SzCR5USaEeF8M7Fe vtwrxl/88nPAVJ80eB55LykSTA74qzn/9yfRnwY3j6MmRrVqdWxc9j0jZ4aV4mql xbVXZBBniynm7Ef6dQbWVbH/29j0zcPGf/gUrvZYoghhrI0FnG6TU75X1naw== 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= fm3; t=1723541485; x=1723627885; bh=95K6mA5Ybu4amAaRvVVRKZHzdzJH 9x1N6WV3yk/phGA=; b=boYNA9BDCgDvGcrFahyqhKUZepcat9mVmwW/OUBHNOi6 wcca8XphYSFnjZ7/J/vMDKVxOQu/lFyK32TnJluwhYOGopsWK+IRq37L005O11/U SG17TJvcjSUrNflLw63F3kUs7XH/JfNuXLrW3h5UwmL3nZJxPhuXHL3LPHOu9Va5 h3Pjf3UCOu/ulR7U2ithfekfwqUeLmP2N5FwS0LTJrjJgYdLCV99aCuyaM89HlZn SlQL+UxeKHgjx0tDNu3hPwvoe2p1ckrClmaBOYBtObPjC5brownTbpnRAw1h5vFs 8ppNyYlwkNmRKQBuMdB0k9dx29gEYyPM0xrhStEVzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorh hrrdgtohhmpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdr tghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:23 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 61643a3e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:07 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 06/22] read-cache: fix leaking hashfile when writing index fails 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 `do_write_index()`, we use a `struct hashfile` to write the index with a trailer hash. In case the write fails though, we never clean up the allocated `hashfile` state and thus leak memory. Refactor the code to have a common exit path where we can free this and other allocated memory. While at it, refactor our use of `strbuf`s such that we reuse the same buffer to avoid some unneeded allocations. Signed-off-by: Patrick Steinhardt --- read-cache.c | 97 ++++++++++++++++++------------ t/t1601-index-bogus.sh | 2 + t/t2107-update-index-basic.sh | 1 + t/t7008-filter-branch-null-sha1.sh | 1 + 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/read-cache.c b/read-cache.c index 48bf24f87c..36821fe5b5 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2840,8 +2840,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, int csum_fsync_flag; int ieot_entries = 1; struct index_entry_offset_table *ieot = NULL; - int nr, nr_threads; struct repository *r = istate->repo; + struct strbuf sb = STRBUF_INIT; + int nr, nr_threads, ret; f = hashfd(tempfile->fd, tempfile->filename.buf); @@ -2962,8 +2963,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, strbuf_release(&previous_name_buf); if (err) { - free(ieot); - return err; + ret = err; + goto out; } offset = hashfile_total(f); @@ -2985,20 +2986,20 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, * index. */ if (ieot) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_ieot_extension(&sb, ieot); err = write_index_ext_header(f, eoie_c, CACHE_EXT_INDEXENTRYOFFSETTABLE, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - free(ieot); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_SPLIT_INDEX_EXTENSION && istate->split_index) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); if (istate->sparse_index) die(_("cannot write split index for a sparse index")); @@ -3007,59 +3008,66 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, write_index_ext_header(f, eoie_c, CACHE_EXT_LINK, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_CACHE_TREE_EXTENSION && !drop_cache_tree && istate->cache_tree) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); cache_tree_write(&sb, istate->cache_tree); err = write_index_ext_header(f, eoie_c, CACHE_EXT_TREE, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_RESOLVE_UNDO_EXTENSION && istate->resolve_undo) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); resolve_undo_write(&sb, istate->resolve_undo); err = write_index_ext_header(f, eoie_c, CACHE_EXT_RESOLVE_UNDO, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_UNTRACKED_CACHE_EXTENSION && istate->untracked) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_untracked_extension(&sb, istate->untracked); err = write_index_ext_header(f, eoie_c, CACHE_EXT_UNTRACKED, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_FSMONITOR_EXTENSION && istate->fsmonitor_last_update) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_fsmonitor_extension(&sb, istate); err = write_index_ext_header(f, eoie_c, CACHE_EXT_FSMONITOR, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (istate->sparse_index) { - if (write_index_ext_header(f, eoie_c, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0) - return -1; + if (write_index_ext_header(f, eoie_c, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0) { + ret = -1; + goto out; + } } /* @@ -3069,14 +3077,15 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, * when loading the shared index. */ if (eoie_c) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_eoie_extension(&sb, eoie_c, offset); err = write_index_ext_header(f, NULL, CACHE_EXT_ENDOFINDEXENTRIES, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } csum_fsync_flag = 0; @@ -3085,13 +3094,16 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, finalize_hashfile(f, istate->oid.hash, FSYNC_COMPONENT_INDEX, CSUM_HASH_IN_STREAM | csum_fsync_flag); + f = NULL; if (close_tempfile_gently(tempfile)) { - error(_("could not close '%s'"), get_tempfile_path(tempfile)); - return -1; + ret = error(_("could not close '%s'"), get_tempfile_path(tempfile)); + goto out; + } + if (stat(get_tempfile_path(tempfile), &st)) { + ret = -1; + goto out; } - if (stat(get_tempfile_path(tempfile), &st)) - return -1; istate->timestamp.sec = (unsigned int)st.st_mtime; istate->timestamp.nsec = ST_MTIME_NSEC(st); trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed); @@ -3105,7 +3117,14 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, trace2_data_intmax("index", the_repository, "write/cache_nr", istate->cache_nr); - return 0; + ret = 0; + +out: + if (f) + free_hashfile(f); + strbuf_release(&sb); + free(ieot); + return ret; } void set_alternate_index_output(const char *name) diff --git a/t/t1601-index-bogus.sh b/t/t1601-index-bogus.sh index 4171f1e141..5dcc101882 100755 --- a/t/t1601-index-bogus.sh +++ b/t/t1601-index-bogus.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test handling of bogus index entries' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'create tree with null sha1' ' diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index cc72ead79f..f0eab13f96 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -5,6 +5,7 @@ test_description='basic update-index tests Tests for command-line parsing and basic operation. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'update-index --nonsense fails' ' diff --git a/t/t7008-filter-branch-null-sha1.sh b/t/t7008-filter-branch-null-sha1.sh index 93fbc92b8d..0ce8fd2c89 100755 --- a/t/t7008-filter-branch-null-sha1.sh +++ b/t/t7008-filter-branch-null-sha1.sh @@ -2,6 +2,7 @@ test_description='filter-branch removal of trees with null sha1' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup: base commits' ' From patchwork Tue Aug 13 09:31:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761652 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9515318991F for ; Tue, 13 Aug 2024 09:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541491; cv=none; b=OvUbZh/ATnPLljRh7BAYePXmTgKYVlm0U2LIf741bVIijW/H6Tdb28vuTXUFzzwGgmd5IUGTOgNLDb0GbpQG+gRrgf6huv5Q6UElT0IInPZPm7ZIp0YeGFs0ZzYZxNla2HBIPOPEpjetDkJGnfB/q++iuoBSnYG+/zu6fe3VUHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541491; c=relaxed/simple; bh=CaOKLE2CK9G7u392qJvsw2Dbm3caVNaWCGfMUY2S+3A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oc4N+C1YTqZSYq1xZcgvZeckjk8LUGuV0TVMUU7JC5ex+MJYj0JnPBkWnjbgiti3ulkIMQ9L+gUh63sGf2qdT6Ji2SSbIwBCqwJDPCA3TfypMMI3Z04DaZytQBjsxBec671t/JPxLRyg63YzHBlTizBap9XZ5ctjkqAMSry06BM= 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=HOAiMaq1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QFlEf6BL; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="HOAiMaq1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QFlEf6BL" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B251F1151A09; Tue, 13 Aug 2024 05:31:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:31:28 -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=fm3; t=1723541488; x=1723627888; bh=7Brhjh8WAs xHHK5TQO3EKm2eiNXT7xyJHDErGuFzrck=; b=HOAiMaq12EM3HG78LuR2/inkaH YHdhN5l3frx5oLXhRVh7uU8wE++KYfJXcAzH1cKosUG+26fPHvJtDcR4zyOzUYqQ 1tYJ98SjQTGSz6y5Wk8zKQ7s6iKYHA5eRRk6VnFSDcbCCazjboaYE9eWKSqvYosG fNuq+Qm5pQkbvIscqui8e96JhGxZiFpgIezs0DmuPgU5uoNbmV1/Gma6IJOkWrDN L+EpFUd2n9P+anTapI96kONc84NGvvMl97o195dH0qAi4TvjsXUcVB1BnvFyitFG NXd1lpSNyWEV0SkJ+Coz1Sv6SuC88VZA7v+So6dTVN2ulRnz9OOgYPYd95FQ== 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= fm3; t=1723541488; x=1723627888; bh=7Brhjh8WAsxHHK5TQO3EKm2eiNXT 7xyJHDErGuFzrck=; b=QFlEf6BL2gVRpq4Pn/KqWVmVKFjCWFsyexZq0m5SztbJ mdVylYLWXODr1MzeR6Bg2DdMZnkzlz/NKnJS1scUjjlEePWI7G9UEQh1nd/DenW1 fM+nDDaFRE0OSBu4FNLa45x/VDodbJ0VN4MplriTb4PMDP8o0FLbvYpGmOpVihlG dftg1nq5HMu5GycevFtQbqglkI5A22VMzM5GBGyQac3mwBaPuikUQCli7B1ZJSSR AVPYwPDvMoP78eYUr8aVJWCpBPOTTUbpKyAjI8TPieARJhtC7NbCSFJvykhRtxGw ZilcAdNmLcihB49gXPMhF3x91CQ2NPTNycN3dqXuTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtth hopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgrrhhthhhi khdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehphhhilhhlihhprdifohhoug duvdefsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhu rdhiohdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id db9c568d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:10 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 07/22] submodule-config: fix leaking name entry when traversing submodules 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 traverse through submodules in the tree via `tree_entry()`, passing to it a `struct name_entry` that it is supposed to populate with the tree entry's contents. We unnecessarily allocate this variable instead of passing a variable that is allocated on the stack, and the ultimately don't even free that variable. This is unnecessary and leaks memory. Convert the variable to instead be allocated on the stack to plug the memory leak. Signed-off-by: Patrick Steinhardt --- submodule-config.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/submodule-config.c b/submodule-config.c index 9b0bb0b9f4..c8f2bb2bdd 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -899,27 +899,25 @@ static void traverse_tree_submodules(struct repository *r, { struct tree_desc tree; struct submodule_tree_entry *st_entry; - struct name_entry *name_entry; + struct name_entry name_entry; char *tree_path = NULL; - name_entry = xmalloc(sizeof(*name_entry)); - fill_tree_descriptor(r, &tree, treeish_name); - while (tree_entry(&tree, name_entry)) { + while (tree_entry(&tree, &name_entry)) { if (prefix) tree_path = - mkpathdup("%s/%s", prefix, name_entry->path); + mkpathdup("%s/%s", prefix, name_entry.path); else - tree_path = xstrdup(name_entry->path); + tree_path = xstrdup(name_entry.path); - if (S_ISGITLINK(name_entry->mode) && + if (S_ISGITLINK(name_entry.mode) && is_tree_submodule_active(r, root_tree, tree_path)) { ALLOC_GROW(out->entries, out->entry_nr + 1, out->entry_alloc); st_entry = &out->entries[out->entry_nr++]; st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry)); - *st_entry->name_entry = *name_entry; + *st_entry->name_entry = name_entry; st_entry->submodule = submodule_from_path(r, root_tree, tree_path); st_entry->repo = xmalloc(sizeof(*st_entry->repo)); @@ -927,9 +925,9 @@ static void traverse_tree_submodules(struct repository *r, root_tree)) FREE_AND_NULL(st_entry->repo); - } else if (S_ISDIR(name_entry->mode)) + } else if (S_ISDIR(name_entry.mode)) traverse_tree_submodules(r, root_tree, tree_path, - &name_entry->oid, out); + &name_entry.oid, out); free(tree_path); } } From patchwork Tue Aug 13 09:31:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761653 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 0960C18991A for ; Tue, 13 Aug 2024 09:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541493; cv=none; b=fS21eO/usGQNkFBtp/1rwQNFJc/7C1FTuJmlRjhfJ9xiCTRbbOER/2ebMkElWyFGCkaZu7xZ+WfLuAC+qXR3M4QribLkZ/huJRTVBwcUf3x6nfNjAfRBvbNNrmUip2b3yEu4AxMt1ZaC4NTJS85qBthENgWrRIhrpDKsEeEj00s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541493; c=relaxed/simple; bh=JU+n7Yx3jSr8AyZIV6SJuxZrhmweAHgRqO0ZPi6qHDk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oGAb7COjAS5JayhNjviRAA3YIWSEU/H6e29JjbZeIzK9gIuy4fsjUZqZaDcXK6zHA8Nm5oq6WrEgs3CQZLsIicjgNKCf/En5ICarT+Lwp84NuVB+ye3P+WdyXXmDDxdxg1ihFCQeGpMIVYsIwGTlgSLBiWyQe5u66Y0bVL8DrBY= 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=NEQ+GFgs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Tefj+3kn; arc=none smtp.client-ip=103.168.172.146 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="NEQ+GFgs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Tefj+3kn" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 4A1D4138FCF9; Tue, 13 Aug 2024 05:31:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:31:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723541491; x=1723627891; bh=LakOwOwaVp c6934Z2Z9eCyYXy7OVRrlsGgNCDtQF08c=; b=NEQ+GFgsTGjPnAjfjf7QFqChG2 r0W0YQQ9iAL3dnsTOnX28Q96zqSwL6UkXGjeWI5Hhn3SmrM7XtHPgFZiTPVdKHPf 2OG0EidCQLzNAiuQD7aWVeNZupOCgo7URBO+XzX5DccQTZuDUEUC/aND5P91CG1S 0lFlKYakBkmxGcouJagfOk7h/RbZguCW/OxzUzYsc/Fth0sGUMDSufJ6QOkuHf4A fpSN4uUrDtd/qgJuh6nd1x3NIISbOgO775qJ4ved+ZsNWcpiuFuMt63QwYyD+RCd IY9PVGP978HREhbpWeoI/cjN+JoXlgsRP/YSR4HirRj7wwLXFobuqmefcx4A== 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= fm3; t=1723541491; x=1723627891; bh=LakOwOwaVpc6934Z2Z9eCyYXy7OV RrlsGgNCDtQF08c=; b=Tefj+3kn47iMykTbMnfpIZFC2lJvyAZJc1A+yd4LKr2Z 3radkIBD57+tttxh3MCXQlDjlzcAdPvkEhw3iTvKZN4WBhl2JGx39UW9s2jwpzas 7gUpSRJvb/XZfYaZQfial5P/3ZNNIxyUES6jA3A0az25WgMmv8oLdDQVPpKFRgKa eEiTIjLK/v2sXRNaZNlHgaZLrWYKmhhyBrTciI69EMliOkTvKmGjZWpXwPX+q6Uc n69xuXriHNwHWUKpjqLoc734+1i1vS0a4+bTqt3oKQV/3PdiWSRcnFDIsEbJy1c1 zldSy6APS0EGtuPFqH6+HgjqXWBbw9YIISzzg8Fk6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtph htthhopehmvgesthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepghhithhsthgvrhes phhosghogidrtghomhdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmh grihhlrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:29 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ec16b4b5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:13 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 08/22] config: fix leaking comment character config Message-ID: <9054a459a1419e333ae8f950b9c9c2bf894c55f5.1723540931.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 the comment line character has been specified multiple times in the configuration, then `git_default_core_config()` will cause a memory leak because it unconditionally copies the string into `comment_line_str` without free'ing the previous value. In fact, it can't easily free the value in the first place because it may contain a string constant. Refactor the code such that we track allocated comment character strings via a separate non-constant variable `comment_line_str_to_free`. Adapt sites that set `comment_line_str` to set both and free the old value that was stored in `comment_line_str_to_free`. This memory leak is being hit in t3404. As there are still other memory leaks in that file we cannot yet mark it as passing with leak checking enabled. Signed-off-by: Patrick Steinhardt --- builtin/commit.c | 7 +++++-- config.c | 3 ++- environment.c | 1 + environment.h | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 66427ba82d..b2033c4887 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -684,7 +684,9 @@ static void adjust_comment_line_char(const struct strbuf *sb) const char *p; if (!memchr(sb->buf, candidates[0], sb->len)) { - comment_line_str = xstrfmt("%c", candidates[0]); + free(comment_line_str_to_free); + comment_line_str = comment_line_str_to_free = + xstrfmt("%c", candidates[0]); return; } @@ -705,7 +707,8 @@ static void adjust_comment_line_char(const struct strbuf *sb) if (!*p) die(_("unable to select a comment character that is not used\n" "in the current commit message")); - comment_line_str = xstrfmt("%c", *p); + free(comment_line_str_to_free); + comment_line_str = comment_line_str_to_free = xstrfmt("%c", *p); } static void prepare_amend_commit(struct commit *commit, struct strbuf *sb, diff --git a/config.c b/config.c index 6421894614..205660a8fb 100644 --- a/config.c +++ b/config.c @@ -1596,7 +1596,8 @@ static int git_default_core_config(const char *var, const char *value, else if (value[0]) { if (strchr(value, '\n')) return error(_("%s cannot contain newline"), var); - comment_line_str = xstrdup(value); + comment_line_str = value; + FREE_AND_NULL(comment_line_str_to_free); auto_comment_line_char = 0; } else return error(_("%s must have at least one character"), var); diff --git a/environment.c b/environment.c index 5cea2c9f54..1d6c48b52d 100644 --- a/environment.c +++ b/environment.c @@ -114,6 +114,7 @@ int protect_ntfs = PROTECT_NTFS_DEFAULT; * that is subject to stripspace. */ const char *comment_line_str = "#"; +char *comment_line_str_to_free; int auto_comment_line_char; /* Parallel index stat data preload? */ diff --git a/environment.h b/environment.h index e9f01d4d11..0148738ed6 100644 --- a/environment.h +++ b/environment.h @@ -9,6 +9,7 @@ struct strvec; * that is subject to stripspace. */ extern const char *comment_line_str; +extern char *comment_line_str_to_free; extern int auto_comment_line_char; /* From patchwork Tue Aug 13 09:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761654 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF90217E8EA for ; Tue, 13 Aug 2024 09:31:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541497; cv=none; b=Fd8TFfDnOzrnBvZ06pI0kQEjeOuaDaFL2qXcYyf7XKdDOwSCf6omzOxk9JSKtI8dhH/1xrOGI6+dFka0kBlPtAPaarC0fLHUueWXvCr5TWcuFtFwPsspbe5PMPkiSbnHEji3phy1cdkTfDigg/eBRdfKQcMTqnfjtvKQ3bYXeRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541497; c=relaxed/simple; bh=i+z0Ja1UQC9OBf3tk7CNnJA2y7Cbl+JFKmwwPYAvNuM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LT9zzCzFzqkUDjcUgAfi6pWVGF8abloaQinZtD9CM5pZpy8+g+EfZCjlmqfv8A4MHdgE8uTw0bGlWL6eLVqWVMtwktOIi2qLjyKKjAcPRqS5ol3+ZRIwoYhWriNHJHFbCjHUTOeV69T12B5FIBu0CEap3QMAgYTqG/eckwSvjhY= 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=S9XNQJ0Z; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cox3naoP; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="S9XNQJ0Z"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cox3naoP" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D849E1151B39; Tue, 13 Aug 2024 05:31:34 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 05:31:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723541494; x=1723627894; bh=BOqUsUHyb3 BpG8+cATWFsGtJ7YKoNLA0txlZw8OisMA=; b=S9XNQJ0ZuiWtWEJeK9P8SwdBB/ HVz1PYJPA4d6RmBRVL5H3FOhC3oUrd/bGQ54vhDZFuaMYg6jr8ly36jmelobnzxq LCefuHYeo1hsgZM3FlFjvmb4WQ3ni5V49ZsATcyZoCdw8TyzwWxJ9/AnNIlVe2DM brHO0izRc5DqjtFSSTSu/GbptwlVB+RKSdvEmqvpXPc2DekBhpwLqsw4IEC8GJ6X s/MO1qtYdbQcVJ2brRoo2Pag6GMnAku1pMsU2A/Xd8a19Caa/6RbR3OAzprKwDtE 6lBB+LIHoadnLo78Vn9oa297mnC+xPoJ3sbmZj742OXG83n0VafXyg3/RX1A== 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= fm3; t=1723541494; x=1723627894; bh=BOqUsUHyb3BpG8+cATWFsGtJ7YKo NLA0txlZw8OisMA=; b=cox3naoP+0dQykRVJ6GI+aLDb6CD9NU64LcDgJ1SB+qS lKjPsSz4lA/6E4N/b4L9xDEwRamlC7pZ4qSI1/zf5BnTzaLGvGPXBLA2vaqCXQxw uXA75MfhaXF6fLI744jzZBfSmE1JmCLeb14WqeeDkyvKKzchSOI5M3MGmXwOJ0jA 1i+VisB3rGaxrALL828fbgro0wRpFgPApQiPqDgEVmUWQi7PQx9qT29nGer4DXmV 0rnAcKAXc065a1K+/7fWXfknQHHQiR0tQuk5TGuZADFJqXczEP+Y8ZjuCmmabsaL XNS0R3CKHs702vzTxQv7/V/eO4b+CEOLRnMnBLtuxQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthht ohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtphhtthhopehmvgesthhtrgihlh horhhrrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:33 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 253c7f1a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:16 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 09/22] builtin/rebase: fix leaking `commit.gpgsign` value Message-ID: <1d3957a5ebb527d672a66f6f6226b6668924a2fa.1723540931.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 `get_replay_opts()`, we override the `gpg_sign` field that already got populated by `sequencer_init_config()` in case the user has "commit.gpgsign" set in their config. This creates a memory leak because we overwrite the previously assigned value, which may have already pointed to an allocated string. Let's plug the memory leak by freeing the value before we overwrite it. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 1 + sequencer.c | 1 + t/t3404-rebase-interactive.sh | 1 + t/t3435-rebase-gpg-sign.sh | 1 + t/t7030-verify-tag.sh | 1 + 5 files changed, 5 insertions(+) diff --git a/builtin/rebase.c b/builtin/rebase.c index e3a8e74cfc..2f01d5d3a6 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -186,6 +186,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.committer_date_is_author_date = opts->committer_date_is_author_date; replay.ignore_date = opts->ignore_date; + free(replay.gpg_sign); replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); replay.reflog_action = xstrdup(opts->reflog_action); if (opts->strategy) diff --git a/sequencer.c b/sequencer.c index 0291920f0b..cade9b0ca8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -303,6 +303,7 @@ static int git_sequencer_config(const char *k, const char *v, } if (!strcmp(k, "commit.gpgsign")) { + free(opts->gpg_sign); opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL; return 0; } diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index f92baad138..f171af3061 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -26,6 +26,7 @@ Initial setup: touch file "conflict". ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3435-rebase-gpg-sign.sh b/t/t3435-rebase-gpg-sign.sh index 6aa2aeb628..6e329fea7c 100755 --- a/t/t3435-rebase-gpg-sign.sh +++ b/t/t3435-rebase-gpg-sign.sh @@ -8,6 +8,7 @@ test_description='test rebase --[no-]gpg-sign' 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-rebase.sh" . "$TEST_DIRECTORY/lib-gpg.sh" diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh index 6f526c37c2..effa826744 100755 --- a/t/t7030-verify-tag.sh +++ b/t/t7030-verify-tag.sh @@ -4,6 +4,7 @@ test_description='signed tag tests' 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 Tue Aug 13 09:31:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761655 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 3648917E8EA for ; Tue, 13 Aug 2024 09:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541501; cv=none; b=m5M0jiaR/naBCHr7BA6Aw2fU+Jex51GuYhNxHphSTjwmdDxzZtkeHcOV9MgDFPeLGVCOksp3T7s4EroqwDumO+DqGkWaeYxd9ZBf7NLS6qt18yiBaLOWqim2So/ZXnE6kiaZKX5Gf6RGR+eZy7ZTj0gCb8HQX+PEB2pLH8SDvJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541501; c=relaxed/simple; bh=bRWVYqnjVu+N5NHbN8oxZtS1NQshG1QSH2y1ChqmUVQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fL5im6cZ9+dNpo7EwzBQNrXaJ6CYsDWMJy0xxr5M9sMXFZ+4RCwvxrohIz/2XYPA3NtBu+a4fl0CmoZfEPD/CcKL357El2/1dfO1buVQsFeYfZ78bfoJM/e/r4A7Qa1+9iO9MJ9ZN1D9vSZEfhSQA0yTfScni4iaHke1Tr3Opoo= 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=Pffsi3tx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Onj8s/iF; arc=none smtp.client-ip=103.168.172.146 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="Pffsi3tx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Onj8s/iF" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 777DD138FCEA; Tue, 13 Aug 2024 05:31:39 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:31:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723541499; x=1723627899; bh=fY3QklG+5J 9bg7jitVmt2MFrjB4EdA04boCX2CSDFj0=; b=Pffsi3tx9J3Gc/htBZcz3nMCOq xzPTi5l07776ftydRQYCINDFyWDO2YHkm2LdMMs+qLB+PQBs97erNNwJ41ZqCi+t t6lav3TrSivWiGLTpts0siUG9hRn32PaVtuDkvkJVsKf01LOgzKdkKjGBIMcrcPl 8kt+TncW7zkqkOuhGIr2DILhDeoX6JELYBJuk6x3tk2cUgeGAbVymgaIW4fCJEh/ J/3gcZVo2PhD0CX7purnbUaR1ro+qzmm+F4pSN6ysVEyHYI9KW2sfETDrCHl2S3I 3zav7h6agpol8/QfKn4Gtc2TU9wh+pRrh+fzjI1DzkOTnvzY4yl2+iT0CxfA== 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= fm3; t=1723541499; x=1723627899; bh=fY3QklG+5J9bg7jitVmt2MFrjB4E dA04boCX2CSDFj0=; b=Onj8s/iF5OpgVUS4YDFNauEeQuTQnjYQC4BU/vAtbOYB uoR1wh2jaGExZwKGW2GJZauhMuJ2lTk/SfC2U3rQKVb/L3XS6ZnBSY1SKKkhLXkD NNpxt3DMo2nv35TOWXSkIPpn60xHoiYfiy4A7Jzi1Hzl+M2O08hzYEOw21JCGG31 HVn34DDjokl7/pthbXIsbzzHiDQ4GhTRam8QrVQuw38p/3S7AipNPO4XAAV15tOu 4O10Vvw9zq5IIvUr7AGhLFZJUs+960zubjAopAUGbscjThLQA/eb4IHlaa8jYOf7 Lp0qmp5bAinFqxPb4bQV/CQ0O2R9jFdbekpCJfQ6VQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthhtohepkhgrrhhthhhi khdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrd gtohhmpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:38 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6caa586e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:21 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:34 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 10/22] builtin/notes: fix leaking `struct notes_tree` when merging notes Message-ID: <0af1bab5a1432eb636dc0fa7b538fa39661cb34d.1723540931.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 allocate a `struct notes_tree` in `merge_commit()` which we then initialize via `init_notes()`. It's not really necessary to allocate the structure though given that we never pass ownership to the caller. Furthermore, the allocation leads to a memory leak because despite its name, `free_notes()` doesn't free the `notes_tree` but only clears it. Fix this issue by converting the code to use an on-stack variable. Signed-off-by: Patrick Steinhardt --- builtin/notes.c | 9 ++++----- t/t3310-notes-merge-manual-resolve.sh | 1 + t/t3311-notes-merge-fanout.sh | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index d9c356e354..81cbaeec6b 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -807,7 +807,7 @@ static int merge_commit(struct notes_merge_options *o) { struct strbuf msg = STRBUF_INIT; struct object_id oid, parent_oid; - struct notes_tree *t; + struct notes_tree t = {0}; struct commit *partial; struct pretty_print_context pretty_ctx; void *local_ref_to_free; @@ -830,8 +830,7 @@ static int merge_commit(struct notes_merge_options *o) else oidclr(&parent_oid, the_repository->hash_algo); - CALLOC_ARRAY(t, 1); - init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); + init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); o->local_ref = local_ref_to_free = refs_resolve_refdup(get_main_ref_store(the_repository), @@ -839,7 +838,7 @@ static int merge_commit(struct notes_merge_options *o) if (!o->local_ref) die(_("failed to resolve NOTES_MERGE_REF")); - if (notes_merge_commit(o, t, partial, &oid)) + if (notes_merge_commit(o, &t, partial, &oid)) die(_("failed to finalize notes merge")); /* Reuse existing commit message in reflog message */ @@ -853,7 +852,7 @@ static int merge_commit(struct notes_merge_options *o) is_null_oid(&parent_oid) ? NULL : &parent_oid, 0, UPDATE_REFS_DIE_ON_ERR); - free_notes(t); + free_notes(&t); strbuf_release(&msg); ret = merge_abort(o); free(local_ref_to_free); diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh index 597df5ebc0..04866b89be 100755 --- a/t/t3310-notes-merge-manual-resolve.sh +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -5,6 +5,7 @@ test_description='Test notes merging with manual conflict resolution' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Set up a notes merge scenario with different kinds of conflicts diff --git a/t/t3311-notes-merge-fanout.sh b/t/t3311-notes-merge-fanout.sh index 5b675417e9..ce4144db0f 100755 --- a/t/t3311-notes-merge-fanout.sh +++ b/t/t3311-notes-merge-fanout.sh @@ -5,6 +5,7 @@ test_description='Test notes merging at various fanout levels' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh verify_notes () { From patchwork Tue Aug 13 09:31:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761656 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 A2EF7188CC0 for ; Tue, 13 Aug 2024 09:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541504; cv=none; b=nCBNaz6l65IxkVf1oL4VqSS0WhaBcBqogx5/rSY6d/hPEqjNF1ovXILsB6uyWCE65ahxbimf02WteSTub2reT7A/ETvIIFUGjtdOKnRFUbVqVyDUw+srOD7SI0efKfYPQ32X6IBIHy7WETAO1oJ1lruHOirVy8AuvMy5ntAdUlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541504; c=relaxed/simple; bh=fHENi47NfIkPY9uLaYewiOQkaHaL1EyfTnxV+ewbN9Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aGsFspKIYwvJPianXvVUhoUHchYapIU8TiSrv6W1U5r81mLVeam7GewQqgXCdpcVWvoJ/m3J1HIN9Jen33KwGj61b0/iASGvGruPyVTEoko7Y2fGfr4+Ew4cQ6Ae3MdhY3EMPLIC/BY6IwzEHW0bcIQZ5mOOaZJsnoYOYwuONuo= 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=IE+biBkS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=H8nfd0kE; arc=none smtp.client-ip=103.168.172.146 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="IE+biBkS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H8nfd0kE" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 052F1138FD25; Tue, 13 Aug 2024 05:31:42 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 05:31:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723541502; x=1723627902; bh=Iavsl7yNoX i27c6wjO4COJj8MMmnHYhMC7QvatEYelk=; b=IE+biBkS6FB7x5CHpHnWfdYNbq hNzvH9h34kpTuljFbSCldLI3zEAZcGPN3oaZuN8RC/2k4+rnFiCUIi/EGE+x5BXs dIivc7knt/Ql+AYh1/pRF4oIrcqOOfiZLzMwjrfLK50hQbJ5/EMke97nqbSsB9FL W1GI66zeY4d/NPAxOPCHSvQ4n7PCyOrGMAQvDr2+c+kAGsp4vvjOWWiRiHV1MAbT zve0GVOJtRhqOfvVm7A9RB7AZSTezBlqNUeB8clRKYWuEpiHoylqWL25qZZoc+8n do3r5L3I+Jepv0BuBbbZBDGHxwX9yaPNAP0iFWR+itHIXL41OTtgocdFqmJw== 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= fm3; t=1723541502; x=1723627902; bh=Iavsl7yNoXi27c6wjO4COJj8MMmn HYhMC7QvatEYelk=; b=H8nfd0kEtWvCuk1gDuP+xCOX0jtuYJYuSfzgDU9khAJ2 Srz2FnP5Pc8DgOwncmS+C0yDuWTYCZTEWQxJ4WCVFq8w0twjE3G3ddthLmR76rYi 0sk7nsB/rVhiRd3y7CrilM3ciEZzVWi7e/MBeSr37mZjTz1e9PYhUpSf7ZgiNUm2 w/oWnpJOyvTzLW3Ee/VmH+UA8Dtzy3BXCqKa9/H37NHTxdg7x2O9ZcJ9Jpukh4Yq i+qm/dplKuH/Ub3/wV+/lmu3IlFrLCB1Srn7xaY4ghE+rGAeNPzXHwJ1ipEANIzV E8s9ykJ+n3VsmMi4kD5E/xRGCijtE3BG6Pw0yJVT7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthht ohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjrghmvghsse hjrghmvghslhhiuhdrihhopdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdp rhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ca301066 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:24 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 11/22] builtin/fast-import: plug trivial memory leaks Message-ID: <30d4e9ed437b70a46d9b625cdb9bc4230aca298f.1723540931.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: Plug some trivial memory leaks in git-fast-import(1). Signed-off-by: Patrick Steinhardt --- builtin/fast-import.c | 8 ++++++-- t/t9300-fast-import.sh | 1 + t/t9304-fast-import-marks.sh | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index d21c4053a7..6dfeb01665 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -206,8 +206,8 @@ static unsigned int object_entry_alloc = 5000; static struct object_entry_pool *blocks; static struct hashmap object_table; static struct mark_set *marks; -static const char *export_marks_file; -static const char *import_marks_file; +static char *export_marks_file; +static char *import_marks_file; static int import_marks_file_from_stream; static int import_marks_file_ignore_missing; static int import_marks_file_done; @@ -3274,6 +3274,7 @@ static void option_import_marks(const char *marks, read_marks(); } + free(import_marks_file); import_marks_file = make_fast_import_path(marks); import_marks_file_from_stream = from_stream; import_marks_file_ignore_missing = ignore_missing; @@ -3316,6 +3317,7 @@ static void option_active_branches(const char *branches) static void option_export_marks(const char *marks) { + free(export_marks_file); export_marks_file = make_fast_import_path(marks); } @@ -3357,6 +3359,8 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list) free(f); string_list_insert(list, s)->util = ms; + + free(s); } static int parse_one_option(const char *option) diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 1e68426852..3b3c371740 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -7,6 +7,7 @@ test_description='test git fast-import utility' 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-diff.sh ;# test-lib chdir's into trash diff --git a/t/t9304-fast-import-marks.sh b/t/t9304-fast-import-marks.sh index 410a871c52..1f776a80f3 100755 --- a/t/t9304-fast-import-marks.sh +++ b/t/t9304-fast-import-marks.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test exotic situations with marks' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup dump of basic history' ' From patchwork Tue Aug 13 09:31:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761657 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 83FEE17C7BD for ; Tue, 13 Aug 2024 09:31:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541507; cv=none; b=X8cVbZfeEBWSn0xiX51DacG6BWPRak0R+ANq9Nzr2ixBoiLHu0e7KTXjj0vUshVdjQAJnnbsjp16EltBdTCAKLcZWv4hNMt8HUKDg4wAJeaDurDSVCnlI6lfmSKgA8vS/Cxd5KK/kNiI/o/74wG0LIymSS++GcIKMVIFIwU95oo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541507; c=relaxed/simple; bh=9SVDC8Iz2csum7pwWZFfj8C6NkQ3os6GlzSSdJXm39A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lvdh1+BT8teH66vbpNrlAf7BuWaAiUHhTnrOy4FaxuY8yy/mrf9kmeloXRSBC0Eqr1BSQcaNqL1xAjBwUooc+R2rCnDdFRQC5a+teQamfkaJaNd1NYX3DfNqztH/dxIf4RSSUkdpRmeKolKQqwZeKC91P61OnhVoqFRlwiByyBo= 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=n93gnvEk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XQHbhWHZ; arc=none smtp.client-ip=103.168.172.146 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="n93gnvEk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XQHbhWHZ" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 8D929138FCF1; Tue, 13 Aug 2024 05:31:45 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 05:31:45 -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=fm3; t=1723541505; x=1723627905; bh=t0cKJCT6Dq 39QHiGDSWrGUXezekt2PtsslEGLNkj8JA=; b=n93gnvEkyDSGOA5FKF6h0b5eKi mhIPsN7Kswmm8kVpDytyhCToBKgYTWQTz4Mb8+VCKbdpohqf9dNv3oRn/YnlYeSc Q66GItpLqxnzf9BHRXKIDOL6NxLqsXndF8eEIV2sGVgd8lOxjBk9Q+L9NGkyA4j6 UF+gREIbos8PtSVIZrHDSlEub4N6B3I/qxt9hiKwsPUz10vnjPaA4ts15Q4n2N7T JCqGY4G7BA1ePDtxg5pbMs9HZ36aW6IuAp9m36WOFHAjjrbLuI/1Ccyh48gP/ReM my1b12LzChzXVy0+Oy6La+DMg+JTZQYncuZyttY21+oSlgfu/89t7gux5VjQ== 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= fm3; t=1723541505; x=1723627905; bh=t0cKJCT6Dq39QHiGDSWrGUXezekt 2PtsslEGLNkj8JA=; b=XQHbhWHZu/HNuuy7Z3q88PDHZDu1HeuoryUijAznIFzC DYzIPc44DrNeR1VAX9fnafY+N17L46CHNZRNoULuRF3T3ORHFnQ35ZOKlvOqnQBc bEbIgnn37r1O9OLNFAKNdtTLYcaMf5Nk3ftokYW455wcAXhW5qWizIzku/PwJ411 VObiyGvz9hchibYzxa09y2PfaQTJVjoHzVZnmAIIPTArh1k9JyMGh8EFvzd9l4ll u8yXUJzozyWJYq5xOoOFKSEwoK1SKkXiVHLR9klLfiFNwMeIO163oi694AlTDfsw G1AlEXWh5jjWZhAa1mto6MOZju5ciolQXn9HfISQJg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepgfefueeltdfhfefgteehfffhffegieeukeevteefvefg udelgeegueevudfhveeknecuffhomhgrihhnpeguihhffhhophhtrdhnohenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm pdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgih htsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgvsehtthgrhihlohhr rhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpth htohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthho pehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthhtohepkhgrrhhthhhikhdrud ekkeesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:44 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e3f03a88 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:27 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 12/22] builtin/fast-export: fix leaking diff options Message-ID: <9591fb7b5e1dac2f989bd10ef2c13a191571a060.1723540931.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: Before calling `handle_commit()` in a loop, we set `diffopt.no_free` such that its contents aren't getting freed inside of `handle_commit()`. We never unset that flag though, which means that it'll ultimately leak when calling `release_revisions()`. Fix this by unsetting the flag after the loop. Signed-off-by: Patrick Steinhardt --- builtin/fast-export.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 4b6e8c6832..fe92d2436c 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -1278,9 +1278,11 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) revs.diffopt.format_callback = show_filemodify; revs.diffopt.format_callback_data = &paths_of_changed_objects; revs.diffopt.flags.recursive = 1; + revs.diffopt.no_free = 1; while ((commit = get_revision(&revs))) handle_commit(commit, &revs, &paths_of_changed_objects); + revs.diffopt.no_free = 0; handle_tags_and_duplicates(&extra_refs); handle_tags_and_duplicates(&tag_refs); From patchwork Tue Aug 13 09:31:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761658 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AF3218453A for ; Tue, 13 Aug 2024 09:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541510; cv=none; b=LjXLhVDIWYtgL8KqifsCLXpSP0LbQ46TpBFOZ7DKdg4POvE8wKJ2DEENYTBvkgyaD5Eb5e3aCHcCFuMIuaWBvSR+a9DH/9yFUEDVs4vBp+JQScXp1o4VpDWp1h5AZD+dzK4A0Ld/D1fibskgzCzku2Mz4p5egvZh3x2neeQ5StM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541510; c=relaxed/simple; bh=8LK3PQrkcHcksC/LiajRYMZKeUMCeOVLEQqUw74jWog=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=axBdIz6ZeHhKchpyu8IGpJ6XDgY0kycVpY+UIGUJvFn6vwqeSnM2rVCsUinwrVJFSAZGaLP9We9JkXSimuMers0W7QloFNBGuaizggzzyq3956H3TN2XbHW5K3T2hANY9/ogQ8G7csvkiWdqrfza4zHeBQ7KDw9EQ5v9HtP6C1I= 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=VZ5n6aQ0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=b7OLVN/1; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="VZ5n6aQ0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="b7OLVN/1" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 33AD4114EA7D; Tue, 13 Aug 2024 05:31:48 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 05:31:48 -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=fm3; t=1723541508; x=1723627908; bh=BMPBENinN4 0NmdvIC0g/9yDOmE53bRPzNitoiMd76Bo=; b=VZ5n6aQ0JYKj4cneGcDGu8VLjs szGjvVZrSLKTRFXulBPmHcn/VbYRaZKk3Co/P/dzlJQpj0CIv0UFXsPK2RdX/tIT S3oweo9R9mFvNMddsTov3gKHfqgZegzO3qCihMo4hHg/kAq7s7WGNiS9MAdh5Er7 WJaio5mjwjkTfgdtUiTXCe1Oz4IBFGepJmy33RehxWeSV9cNEYifAHEczN/FwNEP CP3CCBjt1Wivl6B5jVmeXMLY5Taic1FEUgvtNHNux9l25j/ER/EZUu2ZQGCkUWSX kNI/KGP3LHslpEtfYOGI4+6k77+W1lna2gkv5S4qWfcdCemizkGdAnq1KyEQ== 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= fm3; t=1723541508; x=1723627908; bh=BMPBENinN40NmdvIC0g/9yDOmE53 bRPzNitoiMd76Bo=; b=b7OLVN/1kzvh5YDpFgGjE3a8CZRUUXHGijye8PC+ELhy OEeokCSosp7ScGeNeK/39/D3Z7VXU6vWk3yZpk/sPp7XzMlq4UovzqWi3adRNth6 +Kq1MD8TPWD1KphvMjz5p82RRyJyFW6IToYbAr38rIsz4dIunhnUJYMU43qRSflv vZXi/ZMopyL5cBCQ44BKlcUdqsEzI582fRjwIBThuK+YDnlYUeTz/NCIZF5CPbjc +n2Yq/NGqGefjUaOgXQO01srXOURccFINKmNJex5wjVrif9jbfm+d9K/deSb5Bn+ 3XOC3Azly6wY7K0pg7C41uW3WtgGn2i14ZhrqDCb+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhgrmhgv shesjhgrmhgvshhlihhurdhiohdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtoh hmpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdp rhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:46 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c3a5a977 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:30 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 13/22] builtin/fast-export: plug leaking tag names Message-ID: <254bbb7f6f20ed85b1ec894ffa515ab1ae4f38eb.1723540931.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 resolving revisions in `get_tags_and_duplicates()`, we only partially manage the lifetime of `full_name`. In fact, managing its lifetime properly is almost impossible because we put direct pointers to that variable into multiple lists without duplicating the string. The consequence is that these strings will ultimately leak. Refactor the code to make the lists we put those names into duplicate the memory. This allows us to properly free the string as required and thus plugs the memory leak. While this requires us to allocate more data overall, it shouldn't be all that bad given that the number of allocations corresponds with the number of command line parameters, which typically aren't all that many. Signed-off-by: Patrick Steinhardt --- builtin/fast-export.c | 17 ++++++++++++----- t/t9351-fast-export-anonymize.sh | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index fe92d2436c..f253b79322 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -42,8 +42,8 @@ static int full_tree; static int reference_excluded_commits; static int show_original_ids; static int mark_tags; -static struct string_list extra_refs = STRING_LIST_INIT_NODUP; -static struct string_list tag_refs = STRING_LIST_INIT_NODUP; +static struct string_list extra_refs = STRING_LIST_INIT_DUP; +static struct string_list tag_refs = STRING_LIST_INIT_DUP; static struct refspec refspecs = REFSPEC_INIT_FETCH; static int anonymize; static struct hashmap anonymized_seeds; @@ -901,7 +901,7 @@ static void handle_tag(const char *name, struct tag *tag) free(buf); } -static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name) +static struct commit *get_commit(struct rev_cmdline_entry *e, const char *full_name) { switch (e->item->type) { case OBJ_COMMIT: @@ -932,14 +932,16 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) struct rev_cmdline_entry *e = info->rev + i; struct object_id oid; struct commit *commit; - char *full_name; + char *full_name = NULL; if (e->flags & UNINTERESTING) continue; if (repo_dwim_ref(the_repository, e->name, strlen(e->name), - &oid, &full_name, 0) != 1) + &oid, &full_name, 0) != 1) { + free(full_name); continue; + } if (refspecs.nr) { char *private; @@ -955,6 +957,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) warning("%s: Unexpected object of type %s, skipping.", e->name, type_name(e->item->type)); + free(full_name); continue; } @@ -963,10 +966,12 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) break; case OBJ_BLOB: export_blob(&commit->object.oid); + free(full_name); continue; default: /* OBJ_TAG (nested tags) is already handled */ warning("Tag points to object of unexpected type %s, skipping.", type_name(commit->object.type)); + free(full_name); continue; } @@ -979,6 +984,8 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (!*revision_sources_at(&revision_sources, commit)) *revision_sources_at(&revision_sources, commit) = full_name; + else + free(full_name); } string_list_sort(&extra_refs); diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh index 156a647484..c0d9d7be75 100755 --- a/t/t9351-fast-export-anonymize.sh +++ b/t/t9351-fast-export-anonymize.sh @@ -4,6 +4,7 @@ test_description='basic tests for fast-export --anonymize' 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 simple repo' ' From patchwork Tue Aug 13 09:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761659 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D78817C21C for ; Tue, 13 Aug 2024 09:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541514; cv=none; b=ayMetCbCbkuLVs/DTkCFMjgyEl7lR3ArJCtij3YDq0GbMw7byoMBMds0Kz7J/TgsEqxqi+QBk5Iq9oh995yUxvPDB4ZdJgNis465xyKKMI94/r2+Rp9h2sOdFfe9k7/VY7QnEH4/TZM1n674sWj/sNqR3EPJwRsMM5LMYJRNdZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541514; c=relaxed/simple; bh=Ukaij5hmrPErRpw4QDKh97/DgmHZG0a41YRLxtb5IaU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oNm2XqCReS6K2azq0vygRRfIWEitQHuYiLgyKCLn9Uu0cnFfnGTKAfsxLPCxo5Lo8rUbEdLT1zN59Hn6FqMM+XqeLPJn82eIQe/1L1R/QD++Mx3XV4KqmRF2+2udRDthp/Ft4r2qX2u7ALrLP0wnliYnVjyIJ/0CtExXIH0EaGo= 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=OCasxnQz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NM/WVN6R; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="OCasxnQz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NM/WVN6R" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C452C114EA7D; Tue, 13 Aug 2024 05:31:51 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:31:51 -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=fm3; t=1723541511; x=1723627911; bh=2pdPl8fWIg Pa+FaufSSoP60mf5EmVgiEfhB5i2Ic8MQ=; b=OCasxnQzM3TS1KPtvfS/YhUfNn lqZWNnCNr+FtH5mxGDrLSo4KvH8c61UfADXRsSp6w9xfrPgna1GSLWPHTpx/ZJOC rELnvQNMbGpcgLuwsw5dw7gPWNazlc70ZNniU3g9TwdosSgjj+TLTQdOSimOilfU rmhbHwpS0zsT8/WXCCUmDV6UqD4kfStdW5ZDm6NEEkYZxtTQBqTK526K9lJAyTH5 reDuL7IZ6KKPRv40iI4j6W9Z+moMLmN0auruaR8tIK6s0R/Vk56FDFBy+CcNcjwS wR8QqheQqeO0ijmGUWogI1V/P/lCj6LUB71toqKmUZc5ur8IsQdr2hHuXgng== 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= fm3; t=1723541511; x=1723627911; bh=2pdPl8fWIgPa+FaufSSoP60mf5Em VgiEfhB5i2Ic8MQ=; b=NM/WVN6Rhh032jb9YbldIXmWehgWSzPvgKpN27WchdQP g+FVUaan2PHdyzOeNcOT8NDUMbRXD+pPNKC3OxWtRoa13TCS3+gpEe2epLQm790S x97qlRXKKuX4Mp75lDbrnqWFCjYJor0rk/NcUoR0lU754Ogo1Lm2VRPPh6rGKPB2 1W4vGSZ/Y0jxdNc+ALblfasCwIA/HcJe1QPb8i4ixPDNKGdabgrMstFtMbreMkXp 4PmeD0EsP/M6MDxQ2iGgWnjp8bWaGpd++NL4fOM2uNApbfWafLQ7Eu1+/yNHd9W4 rETmMX0OumsH7iY+Iwwite2KwKdVd6q2JJQXySRgoQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtph htthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepphhhihhllhhi phdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthhopehkrghrthhhihhkrd dukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgv lhdrohhrghdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:50 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 33d96a77 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:33 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 14/22] merge-ort: unconditionally release attributes index Message-ID: <334c4ed71a1e51f9bbbc567e13c10b5fd0c303ed.1723540931.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 conditionally release the index used for reading gitattributes in merge-ort based on whether or the index has been populated. This check uses `cache_nr` as a condition. This isn't sufficient though, as the variable may be zero even when some other parts of the index have been populated. This leads to memory leaks when sparse checkouts are in use, as we may not end up releasing the sparse checkout patterns. Fix this issue by unconditionally releasing the index. Signed-off-by: Patrick Steinhardt --- merge-ort.c | 3 +-- t/t3507-cherry-pick-conflict.sh | 1 + t/t6421-merge-partial-clone.sh | 1 + t/t6428-merge-conflicts-sparse.sh | 1 + t/t7817-grep-sparse-checkout.sh | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index e9d01ac7f7..3752c7e595 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -689,8 +689,7 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti, */ strmap_clear_func(&opti->conflicted, 0); - if (opti->attr_index.cache_nr) /* true iff opt->renormalize */ - discard_index(&opti->attr_index); + discard_index(&opti->attr_index); /* Free memory used by various renames maps */ for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) { diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index f3947b400a..10e9c91dbb 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -13,6 +13,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh pristine_detach () { diff --git a/t/t6421-merge-partial-clone.sh b/t/t6421-merge-partial-clone.sh index 711b709e75..020375c805 100755 --- a/t/t6421-merge-partial-clone.sh +++ b/t/t6421-merge-partial-clone.sh @@ -26,6 +26,7 @@ test_description="limiting blob downloads when merging with partial clones" # underscore notation is to differentiate different # files that might be renamed into each other's paths.) +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh diff --git a/t/t6428-merge-conflicts-sparse.sh b/t/t6428-merge-conflicts-sparse.sh index 9919c3fa7c..8a79bc2e92 100755 --- a/t/t6428-merge-conflicts-sparse.sh +++ b/t/t6428-merge-conflicts-sparse.sh @@ -22,6 +22,7 @@ test_description="merge cases" # underscore notation is to differentiate different # files that might be renamed into each other's paths.) +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh index eb59564565..0ba7817fb7 100755 --- a/t/t7817-grep-sparse-checkout.sh +++ b/t/t7817-grep-sparse-checkout.sh @@ -33,6 +33,7 @@ should leave the following structure in the working tree: But note that sub2 should have the SKIP_WORKTREE bit set. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Tue Aug 13 09:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761660 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AB9118E03B for ; Tue, 13 Aug 2024 09:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541518; cv=none; b=H9rw3852UKyRbaO6/8ah/ElQf1/oknzbj2c2lINqBYnGWGeOaP5LWBpRrH3gXlXOOO3v3NJEIcJ4lx875YG3lJHjGfZdZGw6eE3+kJB2ZrFnLWNY/048dKojLpneaYWevLY/38m2EkJMCZXREza17NHkUpKNYyYo6Ac0BR/o6ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541518; c=relaxed/simple; bh=waks8hoUfznjH12i0vKxdz5LLbjHaWq8lhvqfR9VQag=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LRHyrzrCRUoTyHllGq3/EMm1hzaOmS7lrh5TO8mrvPM+CSs8lTqICWnjyD0nKj0o70+7iZAMGuUCsgmlBbvSrmbgQueJ20IiINeO91Jc6fdRJGT8QWxCzuk7LSz+M3yx/p4hgJO+341W6TCwdxA9SH9PxQzJT7qGHfE6NoDShWo= 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=BhD6VaLM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a8r53hNF; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="BhD6VaLM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a8r53hNF" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 63E601151A09; Tue, 13 Aug 2024 05:31:56 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:31:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723541516; x=1723627916; bh=VsEJeKMeqw r010bAYWR8h0QBoC4ZOScl7Aq4HzEOYMU=; b=BhD6VaLMftzYJAGVsCdZKzHSi1 N5wVbACDiuzwInfpfFaduPBdTWNSurIhXeQaMlL58gz9xTztqAFk6XdunE2tpYdu 3zeAL6AHQUnOPD/jaEwjOy7ktN9Sv1uW5whEdDql4HmE1y8SQSlOM9zDzWfE5v5V E23eOJzz32D4ANJj2c7R8Kb+Qyf4WngrW59FaYLqY8qAkteXvNUMM385PqlPKJ/H G+isbLUzMIvbR2uDac0/rmBVkbIpSZibiNCfbFdAt5ory1l72Usqfc2DuJmYrNtB OwuSUh8FaK6qofd4SgDR7/XK8kC3MckAY8DgZFCs4P8OEyRQ+uhEGW6E11Fg== 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= fm3; t=1723541516; x=1723627916; bh=VsEJeKMeqwr010bAYWR8h0QBoC4Z OScl7Aq4HzEOYMU=; b=a8r53hNFbWjvyM1ad925JKUjo0bFuEgqg86EDLmCXnNH 6W5yQdJrxuMa5SyWeBGSGj8clbmtvzXIHsIMMowDOlCy74aK+6iAyUG8kXxWDBRf CUgSQ459pRS3r3RdyllaHaVKAACSFxrnXyfQL1zxBoENnON81qKxniFkQ5+cr4pK tY9BP7f+xP0n/mF7ddbbMn2414bZWLyIj54KsjutlbdMFP58nwTb5L1qZbQB+dej 2hGilKtt7C4X5iV81MKmMNrcpXPdBaYhAxZeQaNcqa4BTG3WL/E1C1qt4t3T8+vM jwcYZp1dnx1nAdG7wvktSbJ31uHs0erMLORlhxpo8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepphhh ihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthhopehmvgesth htrgihlhhorhhrrdgtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhi ohdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:54 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d1f7c2ad (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:38 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 15/22] sequencer: release todo list on error paths Message-ID: <9f08a859fb7481187310331c008317c4626a3a82.1723540931.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 not releasing the `todo_list` in `sequencer_pick_revisions()` when hitting an error path. Restructure the function to have a common exit path such that we can easily clean up the list and thus plug this memory leak. Signed-off-by: Patrick Steinhardt --- sequencer.c | 66 +++++++++++++++++++++++---------- t/t3510-cherry-pick-sequence.sh | 1 + 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/sequencer.c b/sequencer.c index cade9b0ca8..ea559c31f1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5490,8 +5490,10 @@ int sequencer_pick_revisions(struct repository *r, int i, res; assert(opts->revs); - if (read_and_refresh_cache(r, opts)) - return -1; + if (read_and_refresh_cache(r, opts)) { + res = -1; + goto out; + } for (i = 0; i < opts->revs->pending.nr; i++) { struct object_id oid; @@ -5506,11 +5508,14 @@ int sequencer_pick_revisions(struct repository *r, enum object_type type = oid_object_info(r, &oid, NULL); - return error(_("%s: can't cherry-pick a %s"), - name, type_name(type)); + res = error(_("%s: can't cherry-pick a %s"), + name, type_name(type)); + goto out; } - } else - return error(_("%s: bad revision"), name); + } else { + res = error(_("%s: bad revision"), name); + goto out; + } } /* @@ -5525,14 +5530,23 @@ int sequencer_pick_revisions(struct repository *r, opts->revs->no_walk && !opts->revs->cmdline.rev->flags) { struct commit *cmit; - if (prepare_revision_walk(opts->revs)) - return error(_("revision walk setup failed")); + + if (prepare_revision_walk(opts->revs)) { + res = error(_("revision walk setup failed")); + goto out; + } + cmit = get_revision(opts->revs); - if (!cmit) - return error(_("empty commit set passed")); + if (!cmit) { + res = error(_("empty commit set passed")); + goto out; + } + if (get_revision(opts->revs)) BUG("unexpected extra commit from walk"); - return single_pick(r, cmit, opts); + + res = single_pick(r, cmit, opts); + goto out; } /* @@ -5542,16 +5556,30 @@ int sequencer_pick_revisions(struct repository *r, */ if (walk_revs_populate_todo(&todo_list, opts) || - create_seq_dir(r) < 0) - return -1; - if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) - return error(_("can't revert as initial commit")); - if (save_head(oid_to_hex(&oid))) - return -1; - if (save_opts(opts)) - return -1; + create_seq_dir(r) < 0) { + res = -1; + goto out; + } + + if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) { + res = error(_("can't revert as initial commit")); + goto out; + } + + if (save_head(oid_to_hex(&oid))) { + res = -1; + goto out; + } + + if (save_opts(opts)) { + res = -1; + goto out; + } + update_abort_safety_file(); res = pick_commits(r, &todo_list, opts); + +out: todo_list_release(&todo_list); return res; } diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 7eb52b12ed..93c725bac3 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -12,6 +12,7 @@ test_description='Test cherry-pick continuation features ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Repeat first match 10 times From patchwork Tue Aug 13 09:31:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761661 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 DB2D4194A59 for ; Tue, 13 Aug 2024 09:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541521; cv=none; b=rl/3LXvzVkD4wTwpROSZX3iZ03hDPGuTVxaMBMV1CASl7eQO1TEKj+BPXxM+89MRptboLZgD5bIoVnvvOnwJ/giNDdzaBKL7bdUcmLWIe4/eCYkMZoTOZFNkxyjpIV0xvgGqqIQL7cT1WyiRjY6KwyWuCFIsLRH4GljdbU/rSqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541521; c=relaxed/simple; bh=ITE4erRc/b8Y/qTNPG/XLEHIMWZjT1sbyXWO5GLDM6E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GA2PTGI8su0IYC2l5ycvSZLMBHI8MsEOMZL+5Cz4ada001nlk0i4ziLzvaIcxeVltUbPuU/JIwG1XbMqKgcSaAnDJl0VL9D4rNfVdxWebtvPWXFOT0IUgvGQ5u2YtavsTYUh66Z6sozllA0+er9ZYmakboQcnTRGLRKIirWPLDQ= 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=DNFo9Pl+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cVTiOcbE; arc=none smtp.client-ip=103.168.172.146 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="DNFo9Pl+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cVTiOcbE" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 060CA138FCF9; Tue, 13 Aug 2024 05:31:59 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 05:31:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723541519; x=1723627919; bh=r5fZSpie5H T8amF2hqjnv7n2KKUlCZFOuB9vonuv/XE=; b=DNFo9Pl+jyZz0/5uY0Q7ukVhKU 9Rn2K07z3x84a9x8zKv3OG5iBn8VcT5hfYTmr+7KYT10JPR/oInKa4O7nv9kJlxU DMyJEPLGOiKDFsWQs61QpdxhlTIic1ZsxfU6bvApzqR/2S6oAU4WsaX5A+V0BTO7 MENFBUaRRiSw4zXybiuYNuNCnFPNzRx75pk0eVYEXYkX1v5uFfIx+TYfXWBJAapt b+rv5ypdFQNSIIBhM4xP2cwF36mizI17LDEJtDfadoGxWC/QhiQNxUDKSQ31JgFo fqMG4YQjri8D3QLX4nHi1AtmOlMP84S3lsvUKEDTXewJ0YpelnGYkyex422w== 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= fm3; t=1723541519; x=1723627919; bh=r5fZSpie5HT8amF2hqjnv7n2KKUl CZFOuB9vonuv/XE=; b=cVTiOcbEmgXL457Jt0UA8B9sx3HnVG9y5gdbtqzIC3rJ 676rvs/0ThtYkRawBguFpwa4ZVjwVeeLi2jToEMUhi+7/K2wq0zZVTlNP8M6daG0 x7V0m9L+ODrFlaa4bR7+gVpF40+bs0lISiWPvm04ya81cCJiBXXOkeqkIRt5FfyL ybSxosFwDUo1OA40v+lU3UQ85vS6Y8cOqh04E9Vp+YlH7MGo8YVIfHdmDuA3SzeM 9Z16TJRLp109/2u17pG3M84IXxzwHYaec7BqNS7prz+PiFXEbB6E+8DXgHSsxcuo 3fnX1x6t6tvpmF86XFJ5mHB6B+VKz4tBAdFy0KEm/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthhtohepkhgrrhht hhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpoh gsohigrdgtohhmpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphht thhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:31:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7ea3bc97 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:41 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 16/22] unpack-trees: clear index when not propagating it Message-ID: <5d4934b1a9cf402cbae2f25ef4e0254d45e31e21.1723540931.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 provided a pointer to a destination index, then `unpack_trees()` will end up copying its `o->internal.result` index into the provided pointer. In those cases it is thus not necessary to free the index, as we have transferred ownership of it. There are cases though where we do not end up transferring ownership of the memory, but `clear_unpack_trees_porcelain()` will never discard the index in that case and thus cause a memory leak. And right now it cannot do so in the first place because we have no indicator of whether we did or didn't transfer ownership of the index. Adapt the code to zero out the index in case we transfer its ownership. Like this, we can now unconditionally discard the index when being asked to clear the `unpack_trees_options`. Signed-off-by: Patrick Steinhardt --- t/t3705-add-sparse-checkout.sh | 1 + unpack-trees.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 2bade9e804..6ae45a788d 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -2,6 +2,7 @@ test_description='git add in sparse checked out working trees' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SPARSE_ENTRY_BLOB="" diff --git a/unpack-trees.c b/unpack-trees.c index 7dc884fafd..9a55cb6204 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -210,6 +210,7 @@ void clear_unpack_trees_porcelain(struct unpack_trees_options *opts) { strvec_clear(&opts->internal.msgs_to_free); memset(opts->internal.msgs, 0, sizeof(opts->internal.msgs)); + discard_index(&opts->internal.result); } static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, @@ -2082,6 +2083,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options o->internal.result.updated_workdir = 1; discard_index(o->dst_index); *o->dst_index = o->internal.result; + memset(&o->internal.result, 0, sizeof(o->internal.result)); } else { discard_index(&o->internal.result); } From patchwork Tue Aug 13 09:31:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761662 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 274C2189B9A for ; Tue, 13 Aug 2024 09:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541524; cv=none; b=APbMDw7Nibjl25OdmEZ3pfRA8fPRF5sNj+YWqRRNe+NBjyJQ2B5bl2wDet/Dbtc+dqc/oelE4i3UvlxWVk77UhtNcM+QJ5w1VjcX5TNnUfAF+Bi1mfoelwnQl7NRyx1vPhtXn1rryAPeHYGTy5AKircdCfFvc4nrwycJnxKkLog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541524; c=relaxed/simple; bh=yrlhgSdKEnDhi1HUwtx7k/dXX5LhZXH9LP34Q/lwjIc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sWtxYSrjIawyNZJwXda5Zw/F5v8yFBHs2cdP5Wbnhzj0Xv3gj78rEpB/NgdRoFI9wCoGQ0hK7oq11OSmvlX4XcXToE4f/vLO8lS6wIAQkOfMuMnnbn7u2w8P9KNmOAicC0sKhnm0LmiOIF+iUjtdW821FVtdRfMOTjqsRiDyYi8= 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=KpgEHABm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ckAoQIPU; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="KpgEHABm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ckAoQIPU" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7EEB11151BB7; Tue, 13 Aug 2024 05:32:02 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 05:32:02 -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=fm3; t=1723541522; x=1723627922; bh=vBXD9cXde1 d+k0rRqwemqouzQf8J3Q5zX7ul7aMo7qM=; b=KpgEHABmD3yVdKQE+CmBBo9GM1 7EBXOw5v89l0eRKfGQVrhljn0FQhMAD/ZVZnluyCiXSCI+kSExWVqZAYNsW89aAt Tz6WH1pEP6D7ks3btATwNoiP94tx7izJYZx7pzG/WldL4UW+ZMMhfBl/m3uOcjMk ujSrCiKcA4H48d9yy5Y/DsP0LbQYoeJYVLUFoGeNZbFq7BKItW4rvDgE0He2u01+ r9jtzGPT1Ko5lHBF8Vq/35cHVdaxXAAnysuIXJzVrxfpE+21YOxHvIw9RoTIi55W bCVePlLejh1iWq9kqNdd4I1nimEBWOcCVBDQBpzrA9v3MmbqMwnP27RgV/Ig== 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= fm3; t=1723541522; x=1723627922; bh=vBXD9cXde1d+k0rRqwemqouzQf8J 3Q5zX7ul7aMo7qM=; b=ckAoQIPU6gI02pzMdvjkHGVUT427vHN+ETnd0TSSs8Wn 5StTV8esP64BAz/kCjfIvPmyMvdBBgEomYBZQpKp9VSqJpYgAa+JIaLc6YcpZ4x5 oqGa9GW8zyHbFiJ4TSdWdAz7j2IqQ1m9PG8UY/PyPWfI8dwiFCxj/j5vDxuQsHHr /qoyXWUE5+2v1gF6lxaMJkd6TXbs6RaKC4cgVA0ass7Ir8eCi4jzzdMUkbLqNmza VyZN3rihJhSBucvNr189cftb/aIFcPFwgfxIsdXFdgh9auPpsCDWCKjbSuOqFUIF 0z5DZ59mLNWIdhme1oUaIGcTZeEWjv3UcHxY3OR1ow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtth hopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepphhhihhllhhiphdr fihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthhopehjrghmvghssehjrghmvg hslhhiuhdrihhopdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e1655c38 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:44 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 17/22] diff: fix leak when parsing invalid ignore regex option 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 parsing invalid ignore regexes passed via the `-I` option we don't free already-allocated memory, leading to a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- diff.c | 6 +++++- t/t4013-diff-various.sh | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index ebb7538e04..9251c47b72 100644 --- a/diff.c +++ b/diff.c @@ -5464,9 +5464,13 @@ static int diff_opt_ignore_regex(const struct option *opt, regex_t *regex; BUG_ON_OPT_NEG(unset); + regex = xmalloc(sizeof(*regex)); - if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) + if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) { + free(regex); return error(_("invalid regex given to -I: '%s'"), arg); + } + ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1, options->ignore_regex_alloc); options->ignore_regex[options->ignore_regex_nr++] = regex; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3855d68dbc..87d248d034 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -8,6 +8,7 @@ test_description='Various diff formatting options' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh From patchwork Tue Aug 13 09:32:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761663 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 EA998189BAD for ; Tue, 13 Aug 2024 09:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541528; cv=none; b=V7dGKMjwNs73bDikAGKJ387LwM3PfBA08nY0RcB9N5o6FcbhnN7pRJIsxS51wVZ77M+Igi4e8mJRtQj+y1HzRLNXYyqaswyZg65rCSZxxoauptJhHP6QUO6LpM6nG4A6VOUdveWohC/X+ao/ZNSy8HoJ5WcTtgYnLu9MOk9oFKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541528; c=relaxed/simple; bh=MTmI9pxDD+BIgfRH0tEiTus53HHC8zaBM+E+NsUt7KY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QKQtOmPSq7bGSBSWVTi3eHTlry1K9mYAUj3m4tv4Km88wYC+plJ3MgMLCprHvQeC0VIid6Y/imG08wVhLQgLzyqbhae0XBuFdJ44Maa9RZxpat8+1RpLYdTTn9FbwshikQf1ui5w8aZAVD5lVtvg2kn1gjxQtXj1RD/hNCMhH+8= 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=EGAttZ3O; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Knj7XG6j; arc=none smtp.client-ip=103.168.172.146 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="EGAttZ3O"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Knj7XG6j" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 29AD4138FCEE; Tue, 13 Aug 2024 05:32:06 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:32:06 -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=fm3; t=1723541526; x=1723627926; bh=pxJ7Lou9Tl vLoYOK/cTN1a+8djtyHLHLa3xQtvwLL8M=; b=EGAttZ3OW9gUYcVCdBon3WHyrc p4UzyidH5UJK+xzmhyeML9vizdL5Hub3ehYsBgVeKK6w+/BxjMXk0Az8quZ0QIjW DoyxiZyxzvJdtSVVTeOjZ/8AVVDPpQRzGans/dLTbwXfthAdK8VOtDITIdwqKNsE rJZWCc82Hs5Auaa3WJvDmE7+R83O+HbU5C1Zh2YWAbSDGILkAAs8687aVpcp0URR f/TOoCg9hByYrtK9BKwueQbPvxsS4Jb04JqW1ZucGU+xUbLDBxcngbQfVNnVqgET 5gv71i/lA5ctfO5XAi4azCXWMe8j6xqbbk4x7kE7SOOz2uNwxmnXKGTZO2Tg== 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= fm3; t=1723541526; x=1723627926; bh=pxJ7Lou9TlvLoYOK/cTN1a+8djty HLHLa3xQtvwLL8M=; b=Knj7XG6jpQ4kdDkCvY8HBd4aAPkcQSNY0XQnS9pEe968 tnQCvFzInzDNAa/XDmthTqF6Zqms2ABV6Zdtja8u2W+A2Kuuc99uCcD8IJgOXNRX gzaREn3hEBh5K0crSvjlNzD5LpK9nmSF/bj81cz0XyIUDc5oVtLBA2+oO//Eudn/ jA3GpZScWj9Fuh9dlbTbGsK3FGm4XrvbJCntChz85NgWPOLwfiopYafVBp956kiN 6/a0laWTYh8nuVy6KOMiJuDwgMAf7BC+cCkj+6dN8Ei0lB8iiKN9Es881ALTmOCZ hdRU4q22Y3yghAl1Pp2w4oQq8KSUqGd+4+AiQ1KK5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepgfefueeltdfhfefgteehfffhffegieeukeevteefvefg udelgeegueevudfhveeknecuffhomhgrihhnpeguihhffhhophhtrdhnohenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm pdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgih htsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgrrhhthhhikhdrudek keesghhmrghilhdrtghomhdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefse hgmhgrihhlrdgtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdp rhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepghhithhsth gvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 47fca038 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:47 +0000 (UTC) Date: Tue, 13 Aug 2024 11:32:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 18/22] builtin/format-patch: fix various trivial memory leaks Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are various memory leaks hit by git-format-patch(1). Basically all of them are trivial, except that un-setting `diffopt.no_free` requires us to unset the `diffopt.file` because we manually close it already. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 12 +++++++++--- t/t4014-format-patch.sh | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index a73a767606..ff997a0d0e 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1833,6 +1833,7 @@ static struct commit *get_base_commit(const struct format_config *cfg, } rev[i] = merge_base->item; + free_commit_list(merge_base); } if (rev_nr % 2) @@ -2023,6 +2024,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) const char *rfc = NULL; int creation_factor = -1; const char *signature = git_version_string; + char *signature_to_free = NULL; char *signature_file_arg = NULL; struct keep_callback_data keep_callback_data = { .cfg = &cfg, @@ -2443,7 +2445,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (strbuf_read_file(&buf, signature_file, 128) < 0) die_errno(_("unable to read signature file '%s'"), signature_file); - signature = strbuf_detach(&buf, NULL); + signature = signature_to_free = strbuf_detach(&buf, NULL); } else if (cfg.signature) { signature = cfg.signature; } @@ -2548,12 +2550,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) else print_signature(signature, rev.diffopt.file); } - if (output_directory) + if (output_directory) { fclose(rev.diffopt.file); + rev.diffopt.file = NULL; + } } stop_progress(&progress); free(list); - free(branch_name); if (ignore_if_in_upstream) free_patch_ids(&ids); @@ -2565,11 +2568,14 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) strbuf_release(&rdiff_title); free(description_file); free(signature_file_arg); + free(signature_to_free); + free(branch_name); free(to_free); free(rev.message_id); if (rev.ref_message_ids) string_list_clear(rev.ref_message_ids, 0); free(rev.ref_message_ids); + rev.diffopt.no_free = 0; release_revisions(&rev); format_config_release(&cfg); return 0; diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 884f83fb8a..1c46e963e4 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -8,6 +8,7 @@ test_description='various format-patch tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh From patchwork Tue Aug 13 09:32:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761664 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 5E6F9196DA1 for ; Tue, 13 Aug 2024 09:32:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541531; cv=none; b=tB8Jyb8y/RldbC2SIXvdN5IOyMuLT6V3KEa6DfD2CxN07NCp/HtivxWB3XxgSYpqNVO2IBRISgQnjMvHxgi5cdn//YI9XamTNF2d4lnpPBd0fOMUEjzQVBWVLwCSAhdkivi+Gqlu/py5uNFjd65sC49pE+iOhFnva/HDUSBOgu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541531; c=relaxed/simple; bh=zkdr69ZWVgse8a8Aa0KV+OS9xu+UFHizWG8N0HufK7c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y9JhIcyTdrOVRA28v3QZ3MaagZseSAPFGGBnFaXccuYqgVCR903ko5AaHDHrH9NEyAxgnlt8a0TUoT+FKG52YuTFaLlBR2dKC3YNvVpb+S1N4vMj6rFbWxfoeCdVE8Hdw6ClpkY+tbzfmZxB4AriOBxHklAT1G9Bv8XYwuub7sI= 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=kREm6PgN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ifV4p47B; arc=none smtp.client-ip=103.168.172.146 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="kREm6PgN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ifV4p47B" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id B84A4138FCF1; Tue, 13 Aug 2024 05:32:08 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:32: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=fm3; t=1723541528; x=1723627928; bh=XAUeetf7P2 4rfZv6N44Ib1z4mOQLc5e3yrk7AJcS3Bs=; b=kREm6PgNJ7Vlg2BrGdE1AcYoH3 Yz2YqmUn38Njc6acC6x6PlPTZmtzPSiqPs0f0dIWl3KCY2/BZjgUhiWa9UKkUKv2 VI2OyGbIoB5KSiLGNl9B+5BAbjAdKbQ9iupkFb4m+gZ/BoJRgR8BPVKX7czvFiPI ONsPxGpZLXa0uLQ1+LCZ0ZoX8lvJo+87bI9FUCQ+Mk+/9JYf7kBtIhCdnLdBAKsm mJ1EXurEVOHmtw/KghT7wCHSVhhYoir8TXBtNv7IMLhPuAbSi0LlFgTq1U59n0/e PjFWyXRg0ikszByZqXDdSCd5t8ll/vjwCVEnnYaYnvqK+Xm5yizhlL7m0efw== 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= fm3; t=1723541528; x=1723627928; bh=XAUeetf7P24rfZv6N44Ib1z4mOQL c5e3yrk7AJcS3Bs=; b=ifV4p47BbgmKMZye9b/PK82pcGmOlDYHaXxXI5UUYdvb qRN0lqezwq7rs4rBG0wAPE6GbeaG4DvdzfNAxsYTB2VCeiNyPf4wUjvTIU3VIrMN HTBKA6P21o8/sTxPeV1GkxahLvn523Lf6G/AJiUldXpyDcT0wXHuprThQz+wQmVL h1hAxP0+Jc3TOZbCHAAEkdoC2wwvYezj6fMn9y/KjgenKU99dX2rY62nAxepKRcV roE3pDlaHzMsmhafTQNtcL8llOOhR5PWK+PBiOCPa+Y09vf9lJ8pKvFgbmV/JzOu W17OSL0U7HKG7i54A60j/NqtKmIaDE4N5LnbvtQbpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepieenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrdgtohhmpdhr tghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtsehvgh gvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogidr tghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:07 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f684c4a8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:50 +0000 (UTC) Date: Tue, 13 Aug 2024 11:32:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 19/22] userdiff: fix leaking memory for configured diff drivers Message-ID: <39b2921e3e6aeb7bc5d6d08ed9861d26b738a42c.1723540931.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 userdiff structures may be initialized either statically on the stack or dynamically via configuration keys. In the latter case we end up leaking memory because we didn't have any infrastructure to discern those strings which have been allocated statically and those which have been allocated dynamically. Refactor the code such that we have two pointers for each of these strings: one that holds the value as accessed by other subsystems, and one that points to the same string in case it has been allocated. Like this, we can safely free the second pointer and thus plug those memory leaks. Signed-off-by: Patrick Steinhardt --- range-diff.c | 6 +++-- t/t4018-diff-funcname.sh | 1 + t/t4042-diff-textconv-caching.sh | 2 ++ t/t4048-diff-combined-binary.sh | 1 + t/t4209-log-pickaxe.sh | 2 ++ userdiff.c | 38 ++++++++++++++++++++++++-------- userdiff.h | 4 ++++ 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/range-diff.c b/range-diff.c index 5f01605550..bbb0952264 100644 --- a/range-diff.c +++ b/range-diff.c @@ -450,8 +450,10 @@ static void output_pair_header(struct diff_options *diffopt, } static struct userdiff_driver section_headers = { - .funcname = { "^ ## (.*) ##$\n" - "^.?@@ (.*)$", REG_EXTENDED } + .funcname = { + .pattern = "^ ## (.*) ##$\n^.?@@ (.*)$", + .cflags = REG_EXTENDED, + }, }; static struct diff_filespec *get_filespec(const char *name, const char *p) diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index e026fac1f4..8128c30e7f 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -5,6 +5,7 @@ test_description='Test custom diff function name patterns' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4042-diff-textconv-caching.sh b/t/t4042-diff-textconv-caching.sh index 8ebfa3c1be..a179205394 100755 --- a/t/t4042-diff-textconv-caching.sh +++ b/t/t4042-diff-textconv-caching.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test textconv caching' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >helper <<'EOF' diff --git a/t/t4048-diff-combined-binary.sh b/t/t4048-diff-combined-binary.sh index 0260cf64f5..f399484bce 100755 --- a/t/t4048-diff-combined-binary.sh +++ b/t/t4048-diff-combined-binary.sh @@ -4,6 +4,7 @@ test_description='combined and merge diff handle binary files and textconv' 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 binary merge conflict' ' diff --git a/t/t4209-log-pickaxe.sh b/t/t4209-log-pickaxe.sh index 64e1623733..b42fdc54fc 100755 --- a/t/t4209-log-pickaxe.sh +++ b/t/t4209-log-pickaxe.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='log --grep/--author/--regexp-ignore-case/-S/-G' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_log () { diff --git a/userdiff.c b/userdiff.c index c4ebb9ff73..989629149f 100644 --- a/userdiff.c +++ b/userdiff.c @@ -399,8 +399,11 @@ static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t static int parse_funcname(struct userdiff_funcname *f, const char *k, const char *v, int cflags) { - if (git_config_string((char **) &f->pattern, k, v) < 0) + f->pattern = NULL; + FREE_AND_NULL(f->pattern_owned); + if (git_config_string(&f->pattern_owned, k, v) < 0) return -1; + f->pattern = f->pattern_owned; f->cflags = cflags; return 0; } @@ -444,20 +447,37 @@ int userdiff_config(const char *k, const char *v) return parse_funcname(&drv->funcname, k, v, REG_EXTENDED); if (!strcmp(type, "binary")) return parse_tristate(&drv->binary, k, v); - if (!strcmp(type, "command")) - return git_config_string((char **) &drv->external.cmd, k, v); + if (!strcmp(type, "command")) { + FREE_AND_NULL(drv->external.cmd); + return git_config_string(&drv->external.cmd, k, v); + } if (!strcmp(type, "trustexitcode")) { drv->external.trust_exit_code = git_config_bool(k, v); return 0; } - if (!strcmp(type, "textconv")) - return git_config_string((char **) &drv->textconv, k, v); + if (!strcmp(type, "textconv")) { + int ret; + FREE_AND_NULL(drv->textconv_owned); + ret = git_config_string(&drv->textconv_owned, k, v); + drv->textconv = drv->textconv_owned; + return ret; + } if (!strcmp(type, "cachetextconv")) return parse_bool(&drv->textconv_want_cache, k, v); - if (!strcmp(type, "wordregex")) - return git_config_string((char **) &drv->word_regex, k, v); - if (!strcmp(type, "algorithm")) - return git_config_string((char **) &drv->algorithm, k, v); + if (!strcmp(type, "wordregex")) { + int ret; + FREE_AND_NULL(drv->word_regex_owned); + ret = git_config_string(&drv->word_regex_owned, k, v); + drv->word_regex = drv->word_regex_owned; + return ret; + } + if (!strcmp(type, "algorithm")) { + int ret; + FREE_AND_NULL(drv->algorithm_owned); + ret = git_config_string(&drv->algorithm_owned, k, v); + drv->algorithm = drv->algorithm_owned; + return ret; + } return 0; } diff --git a/userdiff.h b/userdiff.h index 7565930337..827361b0bc 100644 --- a/userdiff.h +++ b/userdiff.h @@ -8,6 +8,7 @@ struct repository; struct userdiff_funcname { const char *pattern; + char *pattern_owned; int cflags; }; @@ -20,11 +21,14 @@ struct userdiff_driver { const char *name; struct external_diff external; const char *algorithm; + char *algorithm_owned; int binary; struct userdiff_funcname funcname; const char *word_regex; + char *word_regex_owned; const char *word_regex_multi_byte; const char *textconv; + char *textconv_owned; struct notes_cache *textconv_cache; int textconv_want_cache; }; From patchwork Tue Aug 13 09:32: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: 13761665 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33032189BB5 for ; Tue, 13 Aug 2024 09:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541535; cv=none; b=uHx1UWg7lG8upVvwn/rcOuYAgJuGJb4AuBCxfKbLYHuyWS+w1Tg7S+L4peFEBSXtoymbZQCBCPhveg5T1pKGcJ+P00MFvcq4aeTrFAskoZRBniaB2aWUv5Dt+D9pdtDWPURU9tw+2Z4/GyTkxFHAjgNAu2hBtGJC/0Hr731VS8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541535; c=relaxed/simple; bh=1M5HVRtyZz4evMWV31VObitmbOnwVwTNwgWt+z1nXjU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fspGd42iv1qr2GNiVO1R+9N1UNjbk16puHdNVl56AWkGECvq96CRhiarJf91N4L1BhMnrHCZXYqC69YOnKVUDaJyXHy4nij++CFC0XmzFovyO7y4+ZgQPxuCczCmGgCJ13aZfkCTiD+JL+4LibkpYK2IFjqQNjdXkOrMpSUvVLM= 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=Znttx6ds; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZvPDw0hb; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Znttx6ds"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZvPDw0hb" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3DC6F11518F9; Tue, 13 Aug 2024 05:32:13 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 05:32: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=fm3; t=1723541533; x=1723627933; bh=mmi0yNNyJb C2zwSx5aG2d1QP9oODEFYukuC7p6GJDJ8=; b=Znttx6dstAJF/eG/jCHsS7jJLK JsTc6ixUwSFe1kl9KLT4nAUwlPmLRxkdf4q8+NcnAz0Hi8n8mTRPcxJUCeDbIvNQ bumFfjZwxV/YoDvlmoiCCrcYZOWgJlRqSe8bolTfTbzSIBbDsme8EcrEflJwqTbq c1TM3DBEzlauqkKTliuaw3xBz/MaOSCWZB5iMTZ+mq1enJsK+oHKH5S46QjQMi9b nYPf+RD6sqEr8Z8DPMby7iUYW9T142mF2hG4kz/PLbDMHaGrkgx+AGMYcMFCGjcH 01JyAPx8Urkv06xoEwM3qckmOXkAs/AXeoIeCJ3gNJKq1nOY++kQKCzjLwyQ== 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= fm3; t=1723541533; x=1723627933; bh=mmi0yNNyJbC2zwSx5aG2d1QP9oOD EFYukuC7p6GJDJ8=; b=ZvPDw0hbUv4CY9kpHHLPjc7G319Ysk1AAHreoq0FS17L wnfKCh6Q1mETCtW/mwOgQ5703XMECW2K+8qvc6UWz5BZQtgF8L7V8+OOs7vJVPA3 ZHJJep0+PXuMT+HrpYBd1qjsb6VRMj2pgSTaeOgwq76ZlA0Nk/YQ29vY6WD7qgfh DQ6TgZe9MjOHj72aS2qVIiz29UQBP8Tp62RqfiOw1Gz6yO9vZPG06ll2t4B4NgIf R0zLv3yqoGXPE8Hr90JvLa57ZvKcdMm9ASLLAv5aAOB49+SuZx93dblhymOXMg3j S1M7c+lbTTOSnsvCvftbk63EoEthpseSI/rPipT4nA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthht ohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpoh gsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdp rhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f0ba96e9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:55 +0000 (UTC) Date: Tue, 13 Aug 2024 11:32:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 20/22] builtin/log: fix leak when showing converted blob contents Message-ID: <50dea1c98a207498c5c48e1fb9eb63ad15960e6c.1723540931.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 `show_blob_object()`, we proactively call `textconv_object()`. In case we have a textconv driver for this blob we will end up showing the converted contents, otherwise we'll show the un-converted contents of it instead. When the object has been converted we never free the buffer containing the converted contents. Fix this to plug this memory leak. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 1 + t/t4030-diff-textconv.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index ff997a0d0e..1a684b68f2 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -707,6 +707,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c write_or_die(1, buf, size); object_context_release(&obj_context); + free(buf); return 0; } diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index a39a626664..29f6d610c2 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='diff.*.textconv tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh find_diff() { From patchwork Tue Aug 13 09:32: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: 13761666 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 89FC0189533 for ; Tue, 13 Aug 2024 09:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541538; cv=none; b=olFSR/TsfucfMAZn1D8bvIGq1MpA4wpDChUBqpFDL7yV7CIMs2BMdqC01YwG4jLU0lMEskGCnUHIP0TPRa8wnjg5X7XbKbZWAFJSzBC7zyZ6/DzPx7fPy6br1/fLdZjWJ70cC5N3mC//73uQqZZNG1p6kk9B2VNpDzBDKAJdIRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541538; c=relaxed/simple; bh=bvWcGfcSixWsFSNcgd9tHk8PRZAxdnx8ad846E7MxrQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xg4vFqwKZt9peL/9d6dKpK5QP577ZKpL3o2KJV0HSKgv6xQVjWi/9ZcRR6/hTD8mlkPZBMqj9mOkP++fzbBAejUva1eLnjJLCUKrca/BA8qgSMqTvVD3JumU+geUCQZ2RL6EOYexvkKUoxJzreQWJeTSFTxEBLY3paePgsnJGFs= 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=lAkAS1lX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Go5y9JHS; arc=none smtp.client-ip=103.168.172.146 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="lAkAS1lX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Go5y9JHS" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id DA56D138FD93; Tue, 13 Aug 2024 05:32:16 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:32: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=fm3; t=1723541536; x=1723627936; bh=1wPwXeOjBn 5/xJdtr8fUs0WTFnPMLFaLxNRBCAIJRNk=; b=lAkAS1lXYI8hJEovYMQXEvg3Ti uPOlD/iLaoz26t+PahA3QFtndIb/9Tl0PUjuM+RpXQanBwicB/cY3AGG14jv0B74 xbYdmBPel3Gx3YczY3dXid6a/Z+ejkWJHmTDBSvl91rgBvXetJBucbxjFQD/xW7+ lWMf03BroXihu4YVntySlpcYMOmaKoCHwXCDE6xz14EiXISkPAH40raUCmvewScD Zyj9IOh9ButmHmRxtlwtD77B/Vxu3yoaZsGsUEjTE/nFJt5FG9v+FqmNQfdTdPJa cwHAR/elXU1GXrpdnaqyJWQoUY+LRbEOhCaVMpcYTBEoXsr3f/7tKlsEolfg== 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= fm3; t=1723541536; x=1723627936; bh=1wPwXeOjBn5/xJdtr8fUs0WTFnPM LFaLxNRBCAIJRNk=; b=Go5y9JHSE2f7oQJ/op0lw96eqM1LDRhqgsAewppn65em JD79IAM2CqIMeM3UT4UUlHuaoVnpEQCVA7td0EVGSJECFb8v/O9Gh5mr3iRiBzl7 7bc9rNqXNtcWRK6LxeUn+6p6AHQFzUyMSze8iF8by/0vsgFUHU6DEbVfZ9z/h0g3 vAEMDatFqqa8L7zCB1RKOz90WC9jdQoiDbYVtgWSK77bUX1HJozpAVcUE/N/fO51 +NbrtAB7Ki8UpDgQJOqVLGutURRszvrPdqoSuErBczubME8Xiu91AZFf1eHSBHcO Fc1o3jTaeBsIqEujF327U8knnInhMrtokC+o8iVQXA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthht ohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehmvgesthhtrgihlh horhhrrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:15 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 15321e83 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:58 +0000 (UTC) Date: Tue, 13 Aug 2024 11:32:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 21/22] diff: free state populated via 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 `objfind` and `anchors` members of `struct diff_options` are populated via option parsing, but are never freed in `diff_free()`. Fix this to plug those memory leaks. Signed-off-by: Patrick Steinhardt --- diff.c | 10 ++++++++++ t/t4064-diff-oidfind.sh | 2 ++ t/t4065-diff-anchored.sh | 1 + t/t4069-remerge-diff.sh | 1 + 4 files changed, 14 insertions(+) diff --git a/diff.c b/diff.c index 9251c47b72..4035a9374d 100644 --- a/diff.c +++ b/diff.c @@ -6717,6 +6717,16 @@ void diff_free(struct diff_options *options) if (options->no_free) return; + if (options->objfind) { + oidset_clear(options->objfind); + FREE_AND_NULL(options->objfind); + } + + for (size_t i = 0; i < options->anchors_nr; i++) + free(options->anchors[i]); + FREE_AND_NULL(options->anchors); + options->anchors_nr = options->anchors_alloc = 0; + diff_free_file(options); diff_free_ignore_regex(options); clear_pathspec(&options->pathspec); diff --git a/t/t4064-diff-oidfind.sh b/t/t4064-diff-oidfind.sh index 6d8c8986fc..846f285f77 100755 --- a/t/t4064-diff-oidfind.sh +++ b/t/t4064-diff-oidfind.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test finding specific blobs in the revision walking' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup ' ' diff --git a/t/t4065-diff-anchored.sh b/t/t4065-diff-anchored.sh index b3f510f040..647537c12e 100755 --- a/t/t4065-diff-anchored.sh +++ b/t/t4065-diff-anchored.sh @@ -2,6 +2,7 @@ test_description='anchored diff algorithm' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success '--anchored' ' diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh index 07323ebafe..888714bbd3 100755 --- a/t/t4069-remerge-diff.sh +++ b/t/t4069-remerge-diff.sh @@ -2,6 +2,7 @@ test_description='remerge-diff handling' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This test is ort-specific From patchwork Tue Aug 13 09:32: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: 13761667 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 1D17B19A29A for ; Tue, 13 Aug 2024 09:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541541; cv=none; b=ZC4lupMz+whiNrvQPfmgFgh3nEzAjpzDnl1nQY1PeXTL9lodIi/jwBO1Ty3HTbIgNrOwhNOTUb1mhIJggz71pn/LHJnDLhETeShsAUiov1mRvt5SjeCuFiHqJNnx4oIypjUsWLqzEtQ6UHLIxOy53VZnSPpjYO4ZaKY+74DvYZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541541; c=relaxed/simple; bh=vcoJvbJM1pGRGVHJToDh9JKl51Pz1EXZDsOFlVlTcQA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qRJvuUCkKFPExxrEdoEmp+mtsd3mD+Qn7azaEEQjtBmz/Ieg29orf7bkDTfT/sGVQD7/JDaiGSd76XzO7TRsA9ukrTy0iVC9V5AK6l25umatix1zejdIFbrMIOcqwNvkmKkmmQ/5Cb4TTXZ0/hqUpPklrI8ue2GkS+kbG3RBVBA= 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=UWNMAgGI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qBsybQl6; arc=none smtp.client-ip=103.168.172.146 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="UWNMAgGI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qBsybQl6" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 79850138FD97; Tue, 13 Aug 2024 05:32:19 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:32: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=fm3; t=1723541539; x=1723627939; bh=CEcQoDcK3Q QoKfLk5yqIfvuZmFRzqrzQkFnFX+Ly45s=; b=UWNMAgGImq98aGA48NSuAZaprj UmM2h5gVCiL9dcEvsH3WjDZRFI3vDjQjfxNOLd247Cqzaxpwaq+FZobMQ6rO8C2r T23Jj5WpgF7y98qEnYANNqJKniDo6RYLN20sUZQcxA/XG7Kp0R1QVeAw+TF7tdOq qLexxzmxr8FfDEDXk7dYEIM9UfqQL/BQ5T8jX4Lf1Wv1QacKUL0B5YUTRiwVa/B+ /sgXK3OkREMorvmoViHfV90AQiFfVGWZWEfsx1ar1fvDsYwgYW1keXcpNMhiFVv9 b/D5eWReUCwhAu3AEZjmlP4dq2+Q9oSOzNc54qCoTYu/jLMVmJFiAIKgNLCQ== 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= fm3; t=1723541539; x=1723627939; bh=CEcQoDcK3QQoKfLk5yqIfvuZmFRz qrzQkFnFX+Ly45s=; b=qBsybQl6TvFtPZA/iasYZZ0xDDl4oiqwAhCiIeCvnBkl wo3obQ8cx5MMk641Sw4dwnHSmsQ5McLmxZahhKopEOQ52UpK4FHLUeJyj5kJeRHV SglseWrW43k0jlHVtcEcx7u2Bhq96Xzd0XEmShw5MI7MkvlhsOrx2ei7BzWiSJAw CYBVYkeOo1jyXACYqiVrqi+P4RPAO4geMMIzDnn6Re2OR1mPmfSRC1MlMJM7ntGu VbyZeOwIwVbWb5bJSdEmqxrcclExA90qerMJbODcYwPyUOfL9bLGMFG8ipfgYMeG WLF2PQBLyx2xTgsjM5TzOp0k02RP+PzTOeRpZEKMaQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepjeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohep phhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthhopehjrg hmvghssehjrghmvghslhhiuhdrihhopdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdr tghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ae28efd4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:32:01 +0000 (UTC) Date: Tue, 13 Aug 2024 11:32:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 22/22] builtin/diff: free symmetric diff members Message-ID: <31e38ba4e150c9bc9e3aa1073869881ccba9035e.1723540931.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 a `struct symdiff` in case the user has requested a symmetric diff. Part of this is to populate a `skip` bitmap that indicates which commits shall be ignored in the diff. But while this bitmap is dynamically allocated, we never free it. Fix this by introducing and calling a new `symdiff_release()` function that does this for us. Signed-off-by: Patrick Steinhardt --- builtin/diff.c | 10 +++++++++- t/t4068-diff-symmetric-merge-base.sh | 1 + t/t4108-apply-threeway.sh | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/diff.c b/builtin/diff.c index 9b6cdabe15..f87f68a5bc 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -388,6 +388,13 @@ static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym) sym->skip = map; } +static void symdiff_release(struct symdiff *sdiff) +{ + if (!sdiff) + return; + bitmap_free(sdiff->skip); +} + int cmd_diff(int argc, const char **argv, const char *prefix) { int i; @@ -398,7 +405,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) struct object_array_entry *blob[2]; int nongit = 0, no_index = 0; int result; - struct symdiff sdiff; + struct symdiff sdiff = {0}; /* * We could get N tree-ish in the rev.pending_objects list. @@ -619,6 +626,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) refresh_index_quietly(); release_revisions(&rev); object_array_clear(&ent); + symdiff_release(&sdiff); UNLEAK(blob); return result; } diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh index eff63c16b0..4d6565e728 100755 --- a/t/t4068-diff-symmetric-merge-base.sh +++ b/t/t4068-diff-symmetric-merge-base.sh @@ -5,6 +5,7 @@ test_description='behavior of diff with symmetric-diff setups and --merge-base' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # build these situations: diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index c558282bc0..3211e1e65f 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -5,6 +5,7 @@ test_description='git apply --3way' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh print_sanitized_conflicted_diff () {