From patchwork Mon Oct 21 09:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13843755 Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (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 C01B01E32D6 for ; Mon, 21 Oct 2024 09:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729502904; cv=none; b=QNdJLtm4o8eYKg+N11fkrQ9f4kPEs07eEN8aGd7Xs7GEYm+IbV6WIY6YPmchR+zC/LM583lcXEp+qbhfuobXIZVOTV9kHDC2CiDOS2fosgewXE3plEBIO1fjCY4iqhIr48YCK7iGpl0oss6cr39fRbeeA7nBQy/3Ek63XNbuGtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729502904; c=relaxed/simple; bh=r+s9b7ltUxVwbMsWnkg5xwXA8v3ggAoRifCuLqZ7Ju8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JWbXCOlIY/RCgmvuj/pXrhoEjapGPc4BgLnAAgOPFo/6dUmu8dYx1gdPlnogDjQWsc0d7Bnx1S3YrW0M7sXc+8R/4zDU59NCaWqkud0iS4Rb71jl1McHBrRznxYH/+2//2z238B5OErDjujqBkIfZRUuJwAM5tfin0KPwc3lK1M= 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=dodc0BeR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lOO5nrXa; arc=none smtp.client-ip=103.168.172.157 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="dodc0BeR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lOO5nrXa" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id D9A61114022D; Mon, 21 Oct 2024 05:28:21 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Mon, 21 Oct 2024 05:28:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1729502901; x=1729589301; bh=VvzSOmwyow gBCDSs6/DGkUvJZCffkolLEO2myq3vzMI=; b=dodc0BeR0aszJrhNMF4oPAAMfr 71lHEhX9WjNb0w6uMJdfFDP5quYDCtAd34Sm7jrVk5+XCJvCe6nreBoP8nX965Gh j474/CFl8Q14MIOWF/aQE5FkpSQfTcg07VYGDr5jitJEpvubCnVq+yNlOTjPAIxR tFRURpjKJ43RcX8MEGZrlPgDvk2KH1bd4WJxE6PSUFtaVUtiUmWIBsVPS4W5gRML TAewzAREAuGEVzbDaoZhmM23bgVfNfgXdUYfhmqSfEzZB7qOg63jMsed5/8amDBI iqR6clE8EzojwH+w0jO2mnsYD3LFtx6UJGLiCDZ8ExoDN5VIm3isbFTxVZBw== 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=1729502901; x=1729589301; bh=VvzSOmwyowgBCDSs6/DGkUvJZCff kolLEO2myq3vzMI=; b=lOO5nrXad2fUsiZ8ZwKZ0EIckOj7YwFT0Wgl/yf8fYSf Db1sKRbtHZAOwyoRon5+qszy3epMxuJ7DbQ7a8/9syuhfRDdMLsBhDyNe8vqNnov UTE0BWiPYxGtHRY4lIAahOrDLzJMHmFwxsDWzWELuYsj45FC14Qu+FU5DO730/dE We4bKCQZzPrKnpWGPTEDbv+TI4aNu7YZmj1q/8lp0bOnMNT3CSeNiDTzOM72pRpZ TfkgkUaACGUvLuT7J2Lpd5xarMqA/1uDH0wGm4h+xh7DgGL1Ig1bKBa/G8eZi7aq opW0SaCt4Jhq6r6RP1Gp1DtOnKOBQBmvCkES2+NMcQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehledgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepgfefueeltdfhfefgteehfffhffegieeukeevteefvefg udelgeegueevudfhveeknecuffhomhgrihhnpeguihhffhhophhtrdhnohenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm pdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehtoh honhesihhothgtlhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhm pdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Oct 2024 05:28:20 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6b97451f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Oct 2024 09:26:53 +0000 (UTC) Date: Mon, 21 Oct 2024 11:28:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes Subject: [PATCH v2 06/22] diff-lib: fix leaking diffopts in `do_diff_cache()` Message-ID: <60af98cb2c7752edc7cd5c5fe8173dc5b2522a7b.1729502824.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 `do_diff_cache()` we initialize a new `rev_info` and then overwrite its `diffopt` with a user-provided set of options. This can leak memory because `repo_init_revisions()` may end up allocating memory for the `diffopt` itself depending on the configuration. And as that field is overwritten we won't ever free that. Plug the memory leak by releasing the diffopts before we overwrite them. Signed-off-by: Patrick Steinhardt --- diff-lib.c | 1 + t/t7610-mergetool.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index 6b14b959629..3cf353946f5 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -661,6 +661,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt) repo_init_revisions(opt->repo, &revs, NULL); copy_pathspec(&revs.prune_data, &opt->pathspec); + diff_free(&revs.diffopt); revs.diffopt = *opt; revs.diffopt.no_free = 1; diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 22b3a85b3e9..5c5e79e9905 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -10,6 +10,7 @@ Testing basic merge tool invocation' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # All the mergetool test work by checking out a temporary branch based