From patchwork Tue Jun 11 09:19:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13693327 Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.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 6125117624A for ; Tue, 11 Jun 2024 09:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718097586; cv=none; b=kQAwXnwVJ54O9FAkK+vEVvL2DU6nANYjZVgH2LylDjxBI7eZ0yAyU68KBYRtnGFrdsFUr/cYo9/fWAsj95iN0rLCvXu5fWrDUwb+/ez4UOrNh2ftMX2oDWkq095CryO4l2b1QcvVMlkPqttkLv5ptnM6R2qd1VAVmWtmhfdqSoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718097586; c=relaxed/simple; bh=jOvXoRXEGdlonBSSGbp7rASokQ6nzTp/jmpOgYeY+Ao=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qx3LzpCHJyC8nrsXejCaJn/I4yDHDV5a6jAIa3Rz1Xk3IpTP52sKF/TEHgcfd0SUp9eyP40VziptWWnfkt5s6H8cZ7SCk7Ksj8ifftOSjuQGO1cPA5abfFshnDFZojdVKtsGNAej2mj+dPefkGw/NZHCHNNx+zQh8WJlI3l7DW0= 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=h82/PKVs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=K+/0gUne; arc=none smtp.client-ip=64.147.123.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="h82/PKVs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K+/0gUne" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 8118D1C0010B; Tue, 11 Jun 2024 05:19:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 11 Jun 2024 05:19:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718097584; x=1718183984; bh=kVwsnpp01v /hyIU9WBdvtsCGLMmn0N2f+aHPsfhKe8Y=; b=h82/PKVsILLyg1ted0v6q6NrwV TlPHIJduGL7Gw9e7Zdk0xipXsTSQ7dnab9+8DRwUmRejK/q+j6jwcvOE4FrANWi2 Dqo/N83OHw+rMLbOV3+Y4G8GDbPIWRzvZB9JYoCPRX5CsytvtjcBs9kGvyxZcxwr QAN5BlVjMemmpkbyAEp+uSx1SFtLdsY3L97/on7cgWjEiNabcNlhLAUS2f02FrNd xWSTxW7V0NAfzBeXVUEv1wGhab3qrKMN2kkJNyCvna7e7PuSbP4qJ5nBT9wCgf12 y7DPqaJkRdtUI4sTQOhTGUpHdgXseWSUe23HR+dMXDJSKvwGyFnDMDtgjbrA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718097584; x=1718183984; bh=kVwsnpp01v/hyIU9WBdvtsCGLMmn 0N2f+aHPsfhKe8Y=; b=K+/0gUne06iTcGLePrv/3EQpBwpRh8xmE71IuQ/mvwKx izRieX/z8kz63Ko7XrNn0GND0xGB5BHdncCWqdfpvs1E+My7VBVu0zl/MaCLDV6n RMjAuaFP5Kb/J1Mo/HOAnEvq1nDGzhIhpo5kEGy/Te2oUc2/rW7wm77ubu6srevz Megmmwrc+aAS4UvFnfS+yjep4zgtCGaqDQ17gi/j0h0z7x2beeyu4dJapbGT7L/w W82oRhBiOmKipRuJxQ4Dva7psBNheQMNadt38L8qSZs2oa3f82F0jY8B2qlFZuRu TpapddPrWTu/yL9MDN5+NCf69pLaKonXBqTctGwb5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeduvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Jun 2024 05:19:43 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 32c72a1e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 11 Jun 2024 09:19:34 +0000 (UTC) Date: Tue, 11 Jun 2024 11:19:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Phillip Wood , Karthik Nayak Subject: [PATCH v2 06/29] merge-recursive: fix leaking rename conflict info Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When computing rename conflicts in our recursive merge algorithm we set up `struct rename_conflict_info`s to track that information. We never free those data structures though and thus leak memory. We need to be a bit more careful here though because the same rename conflict info can be assigned to multiple structures. Accommodate for this by introducing a `rename_conflict_info_owned` bit that we can use to steer whether or not the rename conflict info shall be free'd. Signed-off-by: Patrick Steinhardt --- merge-recursive.c | 8 +++++++- t/t3401-rebase-and-am-rename.sh | 1 + t/t4153-am-resume-override-opts.sh | 1 + t/t7201-co.sh | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/merge-recursive.c b/merge-recursive.c index 8ff29ed09e..8c8e8b4868 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -239,7 +239,8 @@ enum rename_type { struct stage_data { struct diff_filespec stages[4]; /* mostly for oid & mode; maybe path */ struct rename_conflict_info *rename_conflict_info; - unsigned processed:1; + unsigned processed:1, + rename_conflict_info_owned:1; }; struct rename { @@ -308,6 +309,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type, ci->ren1->dst_entry->processed = 0; ci->ren1->dst_entry->rename_conflict_info = ci; + ci->ren1->dst_entry->rename_conflict_info_owned = 1; if (ren2) { ci->ren2->dst_entry->rename_conflict_info = ci; } @@ -3055,6 +3057,10 @@ static void final_cleanup_rename(struct string_list *rename) for (i = 0; i < rename->nr; i++) { re = rename->items[i].util; diff_free_filepair(re->pair); + if (re->src_entry->rename_conflict_info_owned) + FREE_AND_NULL(re->src_entry->rename_conflict_info); + if (re->dst_entry->rename_conflict_info_owned) + FREE_AND_NULL(re->dst_entry->rename_conflict_info); } string_list_clear(rename, 1); free(rename); diff --git a/t/t3401-rebase-and-am-rename.sh b/t/t3401-rebase-and-am-rename.sh index f18bae9450..328c1d3a3f 100755 --- a/t/t3401-rebase-and-am-rename.sh +++ b/t/t3401-rebase-and-am-rename.sh @@ -2,6 +2,7 @@ test_description='git rebase + directory rename tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t4153-am-resume-override-opts.sh b/t/t4153-am-resume-override-opts.sh index 4add7c7757..6bc377b917 100755 --- a/t/t4153-am-resume-override-opts.sh +++ b/t/t4153-am-resume-override-opts.sh @@ -2,6 +2,7 @@ test_description='git-am command-line options override saved options' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 42352dc0db..189d8e341b 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -23,6 +23,7 @@ Test switching across them. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_tick