From patchwork Thu Aug 8 13:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757427 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 B30D1EEA9 for ; Thu, 8 Aug 2024 13:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122279; cv=none; b=qcE8P5sUk8dW1QX8SXKhL0heIlPKLU2QUf84Y3wrE6CUwOlMb+0pldPaGqo9Rukxk6b/o9U5yHtTZIPEkmOy31TI0CiSveNbvBQIcYxgbStUhqBN1NS0+MIp9DqaM7P+T35T9eod26ZYNzcxlEqarTXliIFvhWP9PNlpc3gIhrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122279; c=relaxed/simple; bh=nZ2k70qk7pL/dOxkjCWxDY0lQ/YI5VrngLidMgr5/rk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ELOumSUPlFLPoq9k5ml+18Xs4bYb+imhYSH7v7LGrPfjKgdIlHeC7Ve1SDGj3qMFU67Bj2SwjAQZtIagoVAnqlCNR44ynnz6VTZ83P97vegKvXHM7xZ+IVjvQeAulzH/KD3yw88alxoVkMoOMWvOPFO3/2OcrJn+D/E4GrbvMxw= 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=W9SmGmBN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fS+HXjHK; arc=none smtp.client-ip=103.168.172.155 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="W9SmGmBN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fS+HXjHK" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C8CFF1147006; Thu, 8 Aug 2024 09:04:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:04:36 -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=1723122276; x=1723208676; bh=dAdaJLyQwG cv3dUF/xqfs36/jGKXp/uRyU3BYiwSMjk=; b=W9SmGmBNpkEagFwIrzkVhGynJ6 7Y9D+6IjYU/AeOVawWN0KgRifn9RslogSUj3vy7Ly4XHhP4ZjxwlM6kFbYUVLgYw iOFY9TUeI4alvumewItJuHiE/Ndd8ROyWUHyp9Zz/38j6Brbrl7Y4TffAw9WCSDO wUpjyJzLNs6XEy8z2whgWESP4z7q1iCOh3Ib0Uf1lN0hWuj+tg5hWPPRbSwXUS4b vgs8V775pWzjRA95KtzhLzd4bj5D4hbVtvaNc8CJHTmQJxF5qS+QnggdaO2PqYXp xiGGhzmnvrxxw4q2yejaaf1AfIlO0TjrSUpvYo2JBEQh09YwQXzwrXPtKXyA== 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=1723122276; x=1723208676; bh=dAdaJLyQwGcv3dUF/xqfs36/jGKX p/uRyU3BYiwSMjk=; b=fS+HXjHKVipDDTKNykcLeC2s9scsUIvtkNoZg7NW7pbj /I6Y8dEeC6w4nTs4/nVeeQ7Mlkwy+MMGAJFu157gqft1RNJdecfORa4ibxyc9DzA X0uTFgV8LR6YflUu0Nee9SYdKibzogPNs1QjDkMTkliO0X/HifaiAWH5EGmQTQ9i LO2FM7Bf71WeG8Cf70ZqOeRh5LZ6QhwQJSB2Vuh4i1v3eq94sxqm+Z/tq9c1LpGK atLTgPnL6lOwvOxM3P6ymDLz7WT/LploaXMTQaVOnlDKUj73kw1PeAdyp5KxL8kl JWT4MBpkSmkhh1WxXuiyYx9FkENh8T3a0w1/Zvqkeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtphhtthho pehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:04:35 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id da99e260 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:28 +0000 (UTC) Date: Thu, 8 Aug 2024 15:04:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 01/22] remote: plug memory leak when aliasing URLs Message-ID: <2afa51f9ffedfa6dab51c9515f695ddfe0a9a4f9.1723121979.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 contanis 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 Thu Aug 8 13:04: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: 13757428 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 F02B1EEA9 for ; Thu, 8 Aug 2024 13:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122286; cv=none; b=YgxBbcIxD3+5zjt2eW+S0tS4ypNCDa3j6RrpHA74inF3+pZjZVfFrbK6251h7vAmM4YKWPWU7r4xuvRrscxy0VwsvXTRT8yTpaskBIawaLnL8CCRxHs4rZTDBcJJY95LKqqjI8Q2QLm2G66JjYm1S2z2Tu3NhToB5tsAw5qKbYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122286; c=relaxed/simple; bh=UFXWmf7TKxG06+KQI2gYlfJ0XeT51V20jk7beLuZYV8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CU3w/EzQEIFzQlykMahmNSoaxNT0gWSRV9BUf8tcgqPzwPBw37R+GFchuvKJ9cw59uY5XvNB+Z+Zj1VrF8Q9oXVUjSArkzi9o2nJRLsnAgGRAlUQtEpGIJBXXASlfwCLUXieyw8cNz5pRoFasYaYHZ6mlHA1AxXmKnfqbZUGAgk= 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=VEViwi79; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MP9DRIIP; arc=none smtp.client-ip=103.168.172.155 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="VEViwi79"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MP9DRIIP" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0F78B1151AB7; Thu, 8 Aug 2024 09:04:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute8.internal (MEProxy); Thu, 08 Aug 2024 09:04:43 -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=1723122283; x=1723208683; bh=xXMagUTGKL qwsUb02dzoSHqwmtvSzM8vLAcLUVJuR4k=; b=VEViwi79TWI7ayRINa9M8skeWY qjTXMc3xMSKS8MGtkmFlnHgqwYuiMhuTEidi/rw52Ey8sI8HaefDdNcfcqt+qTa3 MJrohFdKggtOpv8Wuf1fLwXXe5Y9YdOd0N23N6p2Gihb1aKsTsTzXqctAZYm4aJN decJNWRRinTSMQZ44qVbhHBUjYFbhQAlk1lXwU4/kvNrXnrByTGWPiMZJaimNqC7 6CJQkmvRz/hsd46z6ZwTPFYEvRmw3u6zAZiPsmw+XR0hlV3HEn6o2F6Tcf3MBims GZzmmuOmjdzNPkemFz3+3QKYd3JOyFOMQ8dIBetU4kxZpw77ONsygBW3rG1g== 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=1723122283; x=1723208683; bh=xXMagUTGKLqwsUb02dzoSHqwmtvS zM8vLAcLUVJuR4k=; b=MP9DRIIPaI4a2/VtfqQATayeqIcFaj1zuHBNFF3tBO5+ fbqwexMyMb533trNevtUjcLBiT0MVEpSNu/Q5be7oC/5PP3uOHlJPSBTSmfpM3wY zDBVEDBqCYfEb/Qf32soju3SKiaxZkze4V715sClv9z2/RKaD8rkTuZTU63wS1J0 FQ+Qg3Dz9EDzs6OuOMWKwg1+r/W1g672Z4snqZZypX5v81OZ3LohiucMuCyfV465 /6QYD507cBT5zvbp/i0Qy6tWpyWuxY28TymCPuPMBClIOQQfkRnhbWebmNX3t/RW dhm+6cK4gYKKPQH8JOr+z2KI6SqqYBARcIg7S48DCg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:04:41 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 59c91c27 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:34 +0000 (UTC) Date: Thu, 8 Aug 2024 15:04:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 02/22] git: fix leaking system paths Message-ID: <324140e4fdee54fbf0054e76abb287b7212fd21e.1723121979.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: 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. Signed-off-by: Patrick Steinhardt --- git.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/git.c b/git.c index e35af9b0e5..5eab88b472 100644 --- a/git.c +++ b/git.c @@ -173,15 +173,21 @@ 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)); + char *path = system_path(GIT_HTML_PATH); + puts(path); + free(path); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "--man-path")) { - puts(system_path(GIT_MAN_PATH)); + char *path = system_path(GIT_MAN_PATH); + puts(path); + free(path); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "--info-path")) { - puts(system_path(GIT_INFO_PATH)); + char *path = system_path(GIT_INFO_PATH); + puts(path); + free(path); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { From patchwork Thu Aug 8 13:04:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757429 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 F21BF18CBFF for ; Thu, 8 Aug 2024 13:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122289; cv=none; b=mku/JdcX4jHj0Mx3YucIu98ewkLkOZCd5Saa8nESrqtWzOe0ubdtfZYlvIJSbvoFz90WdE8tcbWqib8ZIAPmgmU7qkMSZ296VvN/C6PNxF107Y1dLDhz+MoFsRHzSo/7iToTf7j0rRcPPRhxw+fTRIHCLwC3o27WNLab/CV9ako= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122289; c=relaxed/simple; bh=kCOwud3vZYBKCSj8hYKu8nqzdcA8pxNOqf5RiCPDfNs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fGg6T3pOHBaWu63tu93cMNNVC85957ELLvOPQndynp9PHufvecxvmra7WhyAg2Gewfg8ptI+PiecVOvPAqdDEcfZ/IHiOpw8aTGy1B004XF3rY0DfnV9Uau8TIgUVORo4+Ke1QHvidnMws3FWV0yA0WxTHi+1/7NEhNvbUCT9nw= 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=Jo7F2syz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fe4ShwCd; arc=none smtp.client-ip=103.168.172.155 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="Jo7F2syz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fe4ShwCd" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 323DD11482E3; Thu, 8 Aug 2024 09:04:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 08 Aug 2024 09:04:47 -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=1723122287; x=1723208687; bh=XhxKlvhqCq 2sYK04Hde/fqk1esfFejyLG8fRPHLOAl8=; b=Jo7F2syzswHmb/UY0MuEm8GFTR 0h5TY21cyqmLL3t9fj0VQPzXCjjdpmtwdSNN6SbZ0pJL1uflTN5bc2O8BoL32F+b BQqleNY7mG37ZB4/B2ubyam1m1rkT84o/HIVeAB9PvGGMFz5UiKNBGEbtfd1b5VU 49nHHmNKu8HNflZAzZ0hg3DwOhB9fRjuuf/eelOqisZDmVhAWygjg7CgPZie4qgs 1E1xqqrH0y+8elcrIJk8frxhci7sXN9vv8N/4UruJfUJ3Wcp4aMF0XFUQcJLG3rG Vi949QPXWi9YwGq0KgH28uWU84Hg+5l2veorvERXMZWAyJZqt9OdkJJ5Weng== 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=1723122287; x=1723208687; bh=XhxKlvhqCq2sYK04Hde/fqk1esfF ejyLG8fRPHLOAl8=; b=fe4ShwCd1ZQaBD8Bx1QCY1TjWMFxX859YfdA8yl9ywif UvAa8ngx7c7Xql2isiZifPevIiPuDKCboJbBd/7fMbz+PBNWMx0B6bETTVVUCMH2 t+JevoOyvJuzVl8AtUyOP4ditH5VTMYQGnUAEH5vqWZolxtlnjgMSXxq/h9SqPDu 8ySMEwvy4Tl4XgaPtctOf0DR88HSrKEy2r8JfWkxl4UDLwK8EJnQCbadpViu+S/S FFNRvaFB17i74HxgvH+zjRX1m9P0ffRTlNHVcqiXjDq37g/ibDtp91+lN+ByC4lF TxqBGjTxMoqczF2xDNf0521thRfZ2wh1K/gAHDQW3A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:04:46 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 21239cad (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:39 +0000 (UTC) Date: Thu, 8 Aug 2024 15:04:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 03/22] object-file: fix memory leak when reading corrupted headers Message-ID: <43a38a2281f25db837dc9b5a59ecbe12214ac7bf.1723121979.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()`, then 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 Thu Aug 8 13:04: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: 13757430 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 3129818A6B3 for ; Thu, 8 Aug 2024 13:04:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122294; cv=none; b=ESssQZ4KZ8A+PgRoWC8PQlnRvOBEZw0vTgi+hc2baqf40hPRcxBxz7EpGYHEoDYJhkX11Y9hVAOgDhC8whXoLEn4/p2ZG4x7hzWFYEH9YXqiW5cv5CGUc/iylgj5TcTvdMqvtWSHi5BCEGhz57aeYscjyd7J/MXF46HpR90HUuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122294; c=relaxed/simple; bh=8I5e9Cxunt4osoT31+NxYD9EerZfoq/8ig6SWR4QFLA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uZjEmBGzrIQRo0rQT2cE9fCNuYvdoOE6H/WZQm+RYU8pY87E/dsJj8fU2CTEqwzcxAYOlS3aAcXN6JqImRNiMfw4Xl/XxOkQNQpMpit2YhOH8foSso4TotraeKReSLIZytLCpiifT6r1adq6BY4dIArQ/ftsb9DxGzoOFECeXc4= 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=SLMl1hgJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cS8x4jZC; arc=none smtp.client-ip=103.168.172.155 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="SLMl1hgJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cS8x4jZC" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 58EDE1151A9F; Thu, 8 Aug 2024 09:04:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 08 Aug 2024 09:04:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122292; x=1723208692; bh=ah8PAqvoEe 7xJ4BzJ9iftcfmGMWF5Y90yWAq+6wx1PA=; b=SLMl1hgJiKTW+pkY2ojW8Wp+M8 kl1kXsVjicxmNFYadM4FoG/7xC+h8QGRkv8MpTqmMQZRlFDAegUT2Tm66h/04PSi G10d3vUR7S3hc8TfxHx4XiXxryTKwE7cdvZhJfRZStLPqmhMU2LiaaKQIK64OoHd mLFtrAGT7wdESQRmN/xmM89VbBHbgXSThDswPRYgX881d80DmLKDreMGJrop6hkv tC8wRm0RD7IrB++EiykwQcexXVv0/+/5U/TukDDqKY22BC6A4WpQBijDQm3lxN+1 YSg+yGWaWfHlbkGi2kCihDkZFoQ6GXl4AYE4T0k+myIsyYtyZxzjthO1z1yQ== 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=1723122292; x=1723208692; bh=ah8PAqvoEe7xJ4BzJ9iftcfmGMWF 5Y90yWAq+6wx1PA=; b=cS8x4jZCQlfoptOelJ7VwS7zA13Z5B1RqjhG3OpWftEw XRpi6v8U5RFq9kM2+9/AAwmBCtM8mA2Wx7dZtI6+WoFPkA8xm0cgM3nI8lglTZw2 4xKSDYIgTYsTvOqTflhGAGyjXA0U8B0Vc6QwlsADWaiVQK72cx8orqJjyekh+/7j WuMrI64qXdlPI5oQt0C31bJcX0iekJLrIPla3AiTysPfvBTrZ10JBRwz7xq4pobY 5+cQbc1QYGf7lhfgvWsRgMFt2Ut0qOliCn1FNkSK+HPqmk9holKfVeJM1wMVBDFu s8VcWzhq4+1JxKDiEHmIHYO4vWmt4cf5v2QnX/ebZw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:04:51 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9ecf1900 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:44 +0000 (UTC) Date: Thu, 8 Aug 2024 15:04:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 04/22] object-name: fix leaking symlink paths in object context Message-ID: <9d3dc145e8a60ae446b890ae5b97f81bfd762f79.1723121979.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 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 Thu Aug 8 13:04:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757431 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 5264B18A6B3 for ; Thu, 8 Aug 2024 13:04:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122298; cv=none; b=uZ/t2lABVNaEBiT67Y7vGrshLdkEjzNw4ZFog8zfr8mSjP6t07zHzk/m5GfamQQX9/WYtCc9t6HwA4UWLjCei+KSjrTXJdvgR6M/9jkcNeBCLd4EqPXT26YKMHXM67eCJo4hFxwLsMnlx8BW4+qarCMKk+xwL2hAclEYITagmeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122298; c=relaxed/simple; bh=yp1ZPpMPF1yeULBu/xlmGHp6Va6lHWm6BK29k8JtWw4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HfzLa/MUVbq+AziYTz2y+BGAujEmEFpwhFlopteYUviRKWGa7vfGrXbRZxZqOfrreUCgJwkRiRmnMABKY8oLlZZ+KNAwwxzKnuC7qbQ8iUTIoNXr0JtKrIMD7eOA9uK7fUFOTG+3bPbwijeScQ366qQ6oifebbf6/GYGIjm93ho= 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=k+uqrOaI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TWz70G2U; arc=none smtp.client-ip=103.168.172.150 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="k+uqrOaI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TWz70G2U" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 6E3DC138FC65; Thu, 8 Aug 2024 09:04:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:04: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=1723122296; x=1723208696; bh=ihvA0cZgu/ ZmG9F3up+dU6Ozg2T/EtM1clmJPbKKljc=; b=k+uqrOaIwqg9tLRXdGidnbcz6i K9pJKiJ++coxWhpgfH26fCcIc4weTKAEgzzs6yS1rpBJ6pP+zorkEYDTX2UsU1AI U/kONjooqGRM5SglVTG2tmkuF+/AeIzxO1/rEkL0bTPhj7q6sTDILUuQRYJtUO8L UbyQ0jc/mDfAK0mFgJWsWZWYvZkOSFbjsxjuWnI4pvDAHNVsucLelEQ6uR5zcptc 5W9El6tX3syf9oBnAI3vRpvX/RSvC8pEOKww88CePcsTwo5kK0GGs1KKxpxJQP6J YDmYys62slc1epW3YvuOCGJMKIC2NLtl7SIQE/Xi62Xa6uVHjeQImrTNwmpQ== 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=1723122296; x=1723208696; bh=ihvA0cZgu/ZmG9F3up+dU6Ozg2T/ EtM1clmJPbKKljc=; b=TWz70G2ULDbA5kaQnAET4ZFRHIjcJsoTXzpNNh/jQTQE Qex9KLCYIzamco5pdETb68OazURtlM6fm0+U+4CIOGAwmaSzwYig9RjmT4W8X8Cy jVR4TJ2xCly0SDP/y4XF8Zkx4Qa9OyNI7kvvaWUv6dLWmNwrj/WMlMcXDwM46V1g 3ccDWI2EiV3wuzbTkZt10QUB5rZYTAWTHY/LwRmcmvqM4EsAYR6vNw9O9vSRWhxa DHCkYGHec8P/PNykpYm5H95VRMtllarNCSc2UCYZm611MhBhm/dPdUZ1w7r9akrc JfiUna7hNlKMKLwHNwOb54iUUsIt6WQw/hRMBdomzA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:04:55 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2d4e96db (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:48 +0000 (UTC) Date: Thu, 8 Aug 2024 15:04:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 05/22] bulk-checkin: fix leaking state TODO Message-ID: <454139e7a4b0272ec8c304bc2a84dad35187de78.1723121979.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 Thu Aug 8 13:04:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757432 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 7F86A18A6B3 for ; Thu, 8 Aug 2024 13:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122304; cv=none; b=kB5jKCvwDtOAHtZqPm5SnVSG7lZRp9TRQPADPAbANJBZ6X7zmMyvRRYIqxsg8sUT4nvRcLPaROLZSJWTqrvOy2WR56blArfgmo2YiNVjLJryNpdneWZFeQq9MieQKGDwSMMp7YlZ5Sk66cHcVevIlZOXfUjSkaiq+1oz+cjXaDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122304; c=relaxed/simple; bh=iXqj58fsFC1ve3ODz1PaJg6QS4Ws+Hq1mTRfn2sxL6U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bzRQuVdMk3zwZVVS2cSYmmlq0AXBTpNp7d2+Fbdru6Ck/AsHy381QEFt4XuGd6rEK0GOeSENX2X37iJrd1rdj92jHcCLdRUij2lGaZodLpFw3XLjnCHNCCYELn2+uAkexF0qtGKHhqvJ9q7b02d+qE054KgIii3t6YM866FHhdY= 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=of9raoDy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ibc6x7xL; arc=none smtp.client-ip=103.168.172.150 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="of9raoDy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ibc6x7xL" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 93CED138FC71; Thu, 8 Aug 2024 09:05:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 08 Aug 2024 09:05:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122301; x=1723208701; bh=4FvdSQWPjY IemZ0Du2zyCYBl60k8zWgwI/IrCQXUi6s=; b=of9raoDyyk/O1wdsqFeLKV299w JH+qxu9gkDIhPnTJBQoiX3nY7trh5ACcuaQwzhuMcaLMDPAchnd/QoHYOXFv4dm6 eSRbSWMmRp1lsF4/g7JvMBpcqR/Hiyvj3jwZnt23YhoG+HWgTU64fC+mdP1GfWYp l9vCcjYusYEsxcyCVRld1lKStlYqmsKNNyY3HkViqAOJNHflsO2GUns6WxiEMpEY it7iVUadE/gKgfj9ZO5fCTpR5+f/iHeg2tx0cQUfTFTQrAwLKP6uAonJAOJf2SSV gPY2xjdocqp9cvMbkyx3QtXeSZyzjsAK1B5hzEOnG2oZwHPOA5vbHrcwce/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723122301; x=1723208701; bh=4FvdSQWPjYIemZ0Du2zyCYBl60k8 zWgwI/IrCQXUi6s=; b=ibc6x7xLeG5eiPlH9fmqjZZCzFEND1JtOPxKAbpETv0R hCqwVKjgaCHkEVk0/bGue54q7SkX2KY6eYcy2bhvQKmbAhccgJ38I+m3W1rHb3P4 VmroMtuioDRMxeDADCqDdINZCyn/dR7YPX/c3yHql1EaGj8x/4+tRjuA6RK5C0UR AuCYwTGntGUVFELneUh5/WRDwsAoQhaBxo6E7fHv9Jt4UIOhItcO92jzH92MRBhA WC+1VvTGFcvzPjiyKk56QwV4F3CctNdw5PPRlm6c5uaiKJbc3ockHa3PuAPksVVQ 6R7+kVIfy7ulGLlObGzrooFUFrKQrl1Dxx/RRr1aVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:00 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c0e91a42 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:53 +0000 (UTC) Date: Thu, 8 Aug 2024 15:04:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 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 Thu Aug 8 13:05: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: 13757433 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 5DCAB18A6B3 for ; Thu, 8 Aug 2024 13:05:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122307; cv=none; b=HwJjoParzlUTvAltCoBO+uCYnI1MzDGLkUod6ilXKuDxNSfGPzw/fs6IjugCZnU7ZdgM9zAQakv+n6dN0Xg/s/fdIKulkTRwX5QWaoprMKfRAxn18VOpbZkO8j8q25se9q27CocTEHNx2eewXb5HTG41ZotMwP+dJ7e87tPLBes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122307; c=relaxed/simple; bh=nC6TpkPJwmq473N1Bj2Wjb1MBxRxxFpWUJ4F+ywF50s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dUPT2WOoLGpEfXzFsGV19ayPfHq7skk7dGaX1GRD8ChgQ+XAnQ5TCSewx+LiUiCOZmkQa8+lbUpz3x7pRshx9R+JSizIHRyrs/h+YDnb4RsdKjHxH/gGylBWHt6WNE2X3VJy7uhJZCUbzMrO6XJI87UY9HBRWefSLNZvLCBfFY8= 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=gmKaQrWk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Nd7YVTvC; arc=none smtp.client-ip=103.168.172.150 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="gmKaQrWk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Nd7YVTvC" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id AF4B7138FC78; Thu, 8 Aug 2024 09:05:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122305; x=1723208705; bh=DGQBoweVC5 9gm0Ezuyk6sI+AGLXmhsdKVfrzF8iu7V0=; b=gmKaQrWk8njXWRyOYaJh4k6KS0 gehhaJ1RBa5Ds/xokgJeMYJFiw8s4GUe13mmBinDTvlL706b5TkRWn7BtehSpUf5 ygwCnAqZEjdY0dvMHd51vicw1Npyzv4ms4DH94u5uuFqpErigDIGbmbfEceqxnw7 1+rfnvXQMDYNWsLxmlwz2Yakgtvxp/TcUViGas2jCdorkyKZ+UpHjTMJkOcK+HMa IaEmCneMNh0DOkuE4ecfyrZW56OBhEgQB9mafzzWHpudb53ht1CM46zM2F+sxBdf Vdgjr0GhStAP9fC6vRGpwwewa+tuYSGL2mw2s51N7M7aXdAlgTmFKfmY7kWA== 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=1723122305; x=1723208705; bh=DGQBoweVC59gm0Ezuyk6sI+AGLXm hsdKVfrzF8iu7V0=; b=Nd7YVTvCcSOj/dKho58hmMjoHPWtOHAZA5GICEarnPWY jFodakRkitMN9kXORa+aIEQfrTliI3DgfkQTR+GtP8W0KJb6LVasYb6DfigVW6kS 1IEmlJ8wD+7qJij1K1CkuTJYqFlwEMeZqMthFmu2VxGMlIDzo037xU7LQdOxpBHV jK/Kxv0wn6X2sylCrNiQw6gi45MRFS7/u7Py6oZlTZMF2V+9kFaJYdUFL/9iYBEx YlOTdrPf00o3VVVBJlmPyfEFrKggU1/PkM0bCUSDGoBc4NWByVQ1MaWvJRcspqiI zeeFLWjo1Rs2X7jMuM+IPIDjNIYTfQY6Eir2lhGd4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehphhhilhhl ihhprdifohhougduvdefsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a36e229b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:04:57 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 07/22] submodule-config: fix leaking name enrty when traversing submodules Message-ID: <762fb5aa730fd2c0af21f8f4a4632cd9ca6ae35b.1723121979.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 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 Thu Aug 8 13:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757434 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 9CC56EEA9 for ; Thu, 8 Aug 2024 13:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122313; cv=none; b=n3RjvEDA0EUMumV9hCd14ntYWd1H+KgnVBQ31wrS+ROJSg4/2TUNgMlqLnkrepoI+fKIlZkUOzUBoI1UIz1mqiLfydJXcUC6fLuRLk+v4qfNpk4DBTraN06cByfqFpVugmNsDXMKhUpvUeuoufntfrdYMqX6dVvDpW2qV6FIUao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122313; c=relaxed/simple; bh=oDLchzGe7Ee4MU7C6VSnikCZtYxYgD+7hYI1cRC7Xlg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=md9Yb78oU6JFfITMSf325DMb8BPh1Bwl5YfVeNVOsO+mLW0eh52sGRre8vdUFDpjMsWYg1n/zf27kRi4TP9bwBFnde8+olBXtKyKACWCy0fr8yFTlNpBVNT0lbiobwCESdLjTac6pkBIagtFB/OlqtpzfVWpByqMWjvrx6eM1DQ= 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=LF5imQVY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QzSNHVYh; arc=none smtp.client-ip=103.168.172.150 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="LF5imQVY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QzSNHVYh" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id C814F138FC70; Thu, 8 Aug 2024 09:05:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 08 Aug 2024 09:05:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122310; x=1723208710; bh=8+nj5Y/mx9 6wWp0Ob8myx6K1tynKti+ImBJhz0/x9Ag=; b=LF5imQVYFr04KXmUwtKOv6bLCO xaJSJ6J4SUbAuENZ+c+xOZ7ODSO5/N8+TAWdaqrJNlq3m0lj/cEoG3T/c9uIBjsw cVfE9l3bmNwjT3XLOTRpduvrh3VQImYCfKJMqz8vJVOW0GlO8WZ+N/8Ox15QFcGr n0tkwNTEZzdqTp56O4j+GkhT8eF3LXTbijXmPBOaQMRWqDHONmuJqXFmTgvGh/rF 2+VbKUb+msyijpC/hWIGorO46NVkiuaHanqHkq8sSTp1WWLx1Osr+RRQ0uqCPyM/ UgjraXqMACi0MjIiWgcxlzUUDc33/a8bp5INlhytbmh54MQPm5FEQ/DaIQNQ== 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=1723122310; x=1723208710; bh=8+nj5Y/mx96wWp0Ob8myx6K1tynK ti+ImBJhz0/x9Ag=; b=QzSNHVYh2Fqfprv0/YBtvJjaA+dXuqFlq8AYniNwzZF5 AfHFX0EGi2V9mXgeEfusKzwEXPB0rjpkr5KFlWySR98xw2zhMkfSJbGTguYQF5tC vRtXai4jxqcQ9jzIW6mJ9fwczDjqRfUCyM0mvhLf2Y4RZZFrj5RuSyRkOVgOD9Mb aYz45M/eq3I2DX2ebYA6nJrLe2zv6YI/MyGHUIEv71f1yOrax/dzp5CdZKTKCr3W zcH/JHeyB2efErtt1LByOj0E/jHNYT864+QOXIfyjb1Lbs0vWNHBeB8oZueXh/VK yPapWC2wmEXQXRrlUfIkYF4poJcmJ+diQ0srjaLQhw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehphhhilhhl ihhprdifohhougduvdefsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a16f6a9b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:02 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 08/22] config: fix leaking comment character config Message-ID: <8fbd72a1002d1a285847c62b5524041927a7b4d4.1723121979.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_allocated`. Adapt sites that set `comment_line_str` to set both and free the old value that was stored in `comment_line_str_allocated`. 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 | 4 +++- environment.c | 1 + environment.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 66427ba82d..025b1c4686 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_allocated); + comment_line_str = comment_line_str_allocated = + 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_allocated); + comment_line_str = comment_line_str_allocated = xstrfmt("%c", *p); } static void prepare_amend_commit(struct commit *commit, struct strbuf *sb, diff --git a/config.c b/config.c index 6421894614..cb78b652ee 100644 --- a/config.c +++ b/config.c @@ -1596,7 +1596,9 @@ 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); + free(comment_line_str_allocated); + comment_line_str = comment_line_str_allocated = + xstrdup(value); 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..1a95798d5f 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_allocated; int auto_comment_line_char; /* Parallel index stat data preload? */ diff --git a/environment.h b/environment.h index e9f01d4d11..0e0906f125 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_allocated; extern int auto_comment_line_char; /* From patchwork Thu Aug 8 13:05: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: 13757435 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 CDCD1EEA9 for ; Thu, 8 Aug 2024 13:05:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122317; cv=none; b=CmAL/HlCGpnlgINorSI2ul00ydw+9dd2jihmf04M+kyhVJjy67o6YUPzGzgvlUWF729CayMSO94mSLJkoinx103pv/meunbHiRf1RATpxxjplQs3vXwzmcJehc0dUUkfqmPrRmWwqbz9lrYEaxV2wwEk8J3WT3DEV1c4Ilmsdcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122317; c=relaxed/simple; bh=szKMLuTQWNgtjsbJASdSyjj6BZcyNqyGAyLxorIM8mg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HJyKYfihatKsQAMdeV3LzZdQIhbQVpQ92OiQUgXLlgp5xmtM33Trx5dUArYdgjd92MEGqu+5jVTd3GInmS5nU5q18MgN9gmJWgX/JA8OBfO4gxK+k6+zMa+QtrWiwAHe6J9WDNv6eHd1YDFq2NzgIq4Qlg1StmgHZU1hDRv3Cek= 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=NZRakOLS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=rwfn9S6o; arc=none smtp.client-ip=103.168.172.155 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="NZRakOLS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rwfn9S6o" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 17D691151ABB; Thu, 8 Aug 2024 09:05:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122315; x=1723208715; bh=7D/VnnsTlS SRNaUReBh7hQcfXifxue1fHQFwmd5FeW4=; b=NZRakOLSNvPr4Okb5lFQgIkb9n KuBBTnXDbA1l+UIk6TLgZxqjuiBJP7s0d1+mvQf8OChLswA50io/C5oXJ/Iphdzo tPAc03ZOLqXlJBVRQLkgrNg3xHr5jeZZUB1ZeJ2VzUASU4zohYZ5EnWN0jFMRGcY Wbcag2GlhUJZh6SPoZaFzLwng5uIvam2i+5envaBUxXHYx1kzgFt6y6W2i0VlZpJ w/pJtimUfJFkOtUXw5k7OJAd/LBnKhjQ7pO8pAEChmaOxhN6E2Oq6ghLQFtirLX8 6Z0wT+9ztb7oqyhWsJ0L2ZVQwBcTB2ozHB8+wmfVpRfC03zu6IK9LC68EkEQ== 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=1723122315; x=1723208715; bh=7D/VnnsTlSSRNaUReBh7hQcfXifx ue1fHQFwmd5FeW4=; b=rwfn9S6oPR0sCdqMwxrssJvKxCAIq+Qxmaun/dm5WC4F BjbcmgFLHLxw7lG3HR5eqD5/h/LwqWEWStvo9Wc0dpQ7ASYlX/Axh+k1gJyI/xOs 78lbD1PYytQm4Hd1yXbSRg+L1CwljEQYuvQIfAbTResXoTGVjR8tyxjhPLHGEuix sF/SyQcC7H+PvVf0yiJ0nx8tm8kegQ+31hi/NDM7opr5ns0U0Hfs3nBvi04KcWkn PdryFqKy/KKK8HJIc+aCRSO7z0BdGx8hZGSyM7NBC5Rpy8Npxf79iklxdrhcTM9x 0lHHdMaObb23Xpr5f6Y1Il+QyhuDmzlE8QDtR1soNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtphhtthho pehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9035d9fe (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:07 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 09/22] builtin/rebase: fix leaking `commit.gpgsign` value 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 `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 Thu Aug 8 13:05: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: 13757436 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 D7EC1EEA9 for ; Thu, 8 Aug 2024 13:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122322; cv=none; b=Gdzt/D6FlfUpTOKQfOqUHVnRlGJyDtBQgD+unv5wbyvouJ2SSAfJtXlQRcOfqsid/7qHmsfNfhtYSzOVsilhFzMt8OeIJVrfF3eJ9qH6WFM0t+bI36feZ7LBd2/jo4JuFVjVNP82wXPE6KfhrY5kxUFXZ8uJiABEPuyNsRdi0eQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122322; c=relaxed/simple; bh=YkNUPnukO+LAwYE3miTCQlN5SqlGB1MUUlG+dOzSSEQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SM3Z8GpricU+4jE1o8Cil3GOrW8F9Ekrf6ZdGEsPgmIKrgcoCFbIEMt7N22gi/JASOv1in8CATIMAVhNxILt9IcPwKpqL0QGQuCIBtnZY3osb1IA8WQNmfRFy1E/Xr0CYygOC8fTD6Yr1FW/gVRBgGC2jXeKu4zpRFOlQ2dZNP0= 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=oOTILM/E; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HPisMOM9; arc=none smtp.client-ip=103.168.172.150 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="oOTILM/E"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HPisMOM9" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 4AC6D138FC3A; Thu, 8 Aug 2024 09:05:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:20 -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=1723122320; x=1723208720; bh=y7T9YAxF68 Rx/lcy5gU0XHzWcJspUY4UkFg+NAkFM6c=; b=oOTILM/EfBAJgPcmAuCP9ctNHO WoHmn85SXtdF4TV839+z3UFUp/9nq/bYMX8CvVFHKOXVMx6nBSnsbu0CLtz+8TtU xGzYAtzbb9+ImvdlMtfHTyiDQWKHtKeUzBfRoTqIEe6kQWfepS3QHHcWLEru+i7A zRLW+L472DIOqBGLaRHOvX1I4VCduw55UMApCkqZ91UFA/7I1ByATPm47MA92mAp xtPxKC0RkX/EkSbnOBLfFN4Mwntv2iK92pABKEPhFYzvjcnViGZFK0QR4S/Flk1+ lWH1R+xi5G6hd4nozlyX3lZKGJEFx1OsA5pK2Ou9HXQAqK+pucjGohI+rEhg== 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=1723122320; x=1723208720; bh=y7T9YAxF68Rx/lcy5gU0XHzWcJsp UY4UkFg+NAkFM6c=; b=HPisMOM9dzK+H2ewgApMqi4XGcSf7BJUV3m+1WcVi3Gv Hpar9ps7gvuA3/OJxGGjW35m02f7DswauFYxqJyAqPJMSCt+EYApqefYMbt+67sP jk0A0GDDefDpHdqwC7M637zjEYZqW2VIGbLdftCGMQUsild6bE5mYEELzj3fiD5k byKd4aVrQg3oPuicoz4ijioDTHjSQtGgd7l4RRF5IwTDdGX2H/txIKLa2fYfc6/4 LYnqkdUcv1wPq2/zj5qq2Yuabsvt6HtdUuYSx5lS0x4TBDcOQOG5GAcEsmBA1nS6 8/OpzpQYMrzfiPrr7Y944sJCN3IEZzhzUg9XPJ0fsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:19 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b62b6b85 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:11 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 10/22] builtin/notes: fix leaking `struct notes_tree` when merging notes 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 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 Thu Aug 8 13:05:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757437 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 2ACA618CBF3 for ; Thu, 8 Aug 2024 13:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122326; cv=none; b=CCCgPFQKakkcxDeFb84cJHPWYiGvt7C+xbETeqm+wXQtC6+65/vBVwPP5XO9feZI47Y/zkeJG6EikCFWZHhXtlaz3aMnYLeMD42jdIk15z+DQSu1/YFxoKISOe/yC4AJFn7ZJr+XaLaE98zuarc1/TD18SwFOEWh2C1rdi242ew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122326; c=relaxed/simple; bh=xcIZBYzHtkb5xO9oiQTWKci5z+vcwhMIzGuQxjjcjCE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jYQU944U9HMzrDHYVfkSDtj8Mrs//MHxrLMcv/9+4TA1Ym6KRMZi7JInnOt/2qiyUYkeDiiH1Tj1LJZkDDpGvoLWF5wRxaVBoTXEov/9gHw3TDx+Jz4vJkyi6juEMdPqq89oYYX09f1eYO7zB/sMMJjQ03eU0rm+zJD+vMzc/7U= 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=Q2+xOGIn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CuO5RP9q; arc=none smtp.client-ip=103.168.172.155 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="Q2+xOGIn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CuO5RP9q" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 71D7F1151ABE; Thu, 8 Aug 2024 09:05:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:24 -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=1723122324; x=1723208724; bh=xV2qufCYHt qM0Ny/e0o9FDvYdFCfpMhCbMGttLDJk48=; b=Q2+xOGInX/RmoXwjXQ6MFG55ro fRAkYL2K7aHOAlWr2haM6GoR2cAe7GO5QGLh6kteewXfBoWrsivVr7XPE60niiiw x2f1R9AWwQPQfjGHgiGyOow5DcZIMU6vgz7voCR7ridltkyBqnTkSaJVegYFojEn N8H54claWx37QBRhX6gzFvuqmXuOLmPj/xw5nAqFvTQg3acr4egU+86KQCgyL2VK KOq1BvvwKpKkBEExZbYHpM2SJ/9Gd1fjXEXb9/tjrY1JZYqlP2HoZWFAVukMsJ6+ vMRP7Ck7AXeifb2LEe5ek57sKrdUPZMF+2y9UdGi75Kw7UMB7bscHGJaTt+Q== 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=1723122324; x=1723208724; bh=xV2qufCYHtqM0Ny/e0o9FDvYdFCf pMhCbMGttLDJk48=; b=CuO5RP9qQBQnbfxTTR3MTJRgJedqi8y5TavJ/WwjwtsL GndH8JDaG/WM+InJi57dYSrC0HxsltsZAifpAB7d3M/x1/R34WA/4MWwNLV/f8u5 Y2qTeslYdGTpqqwOBz7Gd0EkZibtqxYeN9B8IPQ007OSfoSU9cflZxm/gLv6XPiG Zh3P/RmCZc95GmlA82ivbLFvOO+lq0SyY0FbczBCvkpLq6zG6RA1oypxL4eWouxa cBuQRNO8K1rNBZIlkK3X7wC8OkVckgF2XsNNHomspuGFshQFOf575K54uq+WnUhw 5vu/RrfnSfWSnXiC7tGvg2zI+f+OOmEwIv82N3nTxw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeeinecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:23 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4c5e9b5c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:16 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 11/22] builtin/fast-import: plug 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: 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 Thu Aug 8 13:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757438 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 4CA2518CBF3 for ; Thu, 8 Aug 2024 13:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122331; cv=none; b=buo03Uv3x2z4KH1yN1/FcrGXtR+snJDqXaJ8Tt1gYue2ag0TxV10Si2cY06EeQPhMhdGCWyAM14JuvdpsBzo6XGFgmzMBi1SaLy+0Lvp56in218lwdIqn1acmdNW0TNWT2Z6fr2b2m5MKJZ5MzA8C7PwfUGT3quJOS1prA4qwGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122331; c=relaxed/simple; bh=cCknkQ8cHC0BKnLO+GyFMAEBzfkKukdmjxl2sHXBlso=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qCOqPwLSEsyVNcX2rkQq1e4hdI5yUYgPZ1rBZXXnzFnkIGdtkGeDtq+Xj8N8lnYJIXdv45+4V4BUAwvlumPmxekJkRiDGR+Iikh95Okko34HwK1Ig9xod4RsjZZUGSplGMhXpk6mn1yiituDQmYO7U2pmW//t7rmitf5kVhMHG4= 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=A8J1KAeA; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RH1lNHOq; arc=none smtp.client-ip=103.168.172.150 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="A8J1KAeA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RH1lNHOq" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id A6C1B138FC76; Thu, 8 Aug 2024 09:05:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 08 Aug 2024 09:05:29 -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=1723122329; x=1723208729; bh=xNKkWx7spq eIMsc2GxyV4YNLE+UzI9aCWagrMeyvfBE=; b=A8J1KAeAoj5w4hMaLO7u+dKkix wYgQcCcUNWRm4Lf1p/YCeUK0kAetHc9qEpTH4AExv5WopHME8A7Up8b0uxN8XWZ9 rHAC8yD9KmbF8qs1+UrxvK9bXQwd982yDNvJE5LEW9KFPE4ra74RB/+FlddHmpz6 MKERjTIqgvzVgpmenvWvWxTfnEcW6Oagsh0usVQ5S37WJpwCRHwZBYyGVpgmgKhR St1SpWsTZ60UuGTNvgnqe9e+y4CHDR6koSpEPQQcpqlpq1CXPCgaUfOK37FW+8Du nJqf1eo7F9Y5Hiu1oglXaJAom22jgwfy64I02d0Xsi+Dtb2Rzt9WLdTII51Q== 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=1723122329; x=1723208729; bh=xNKkWx7spqeIMsc2GxyV4YNLE+Uz I9aCWagrMeyvfBE=; b=RH1lNHOqg3qw2TYMMp/CL4hEuoo8mK0Kuuptp2CFRXrq XmajCM16Q4Nz0hx5CUwLArUswVvmrkzBmw2LmSGWManw1viIAewlJgSIft73MJG3 elU+JjJ0Xtod/CFH3/U4aXq7jtkOrPt80mPJKu/fvd/b5DbFvq0FqtdnjeoLzkuS 4zx6pcSu7MMQI0v/tG0GuCyekSkzIfhf4/1pgWyUS7FfRYxP63r6h857UZO20ZSG MfqY9eaWIWxHVJ5q/kb4+rd1OA7mrizl6YpgnrYyUMwV+mf/gWyd+mVjqT4x9wnm WAz2fR+ZBRcQ5VhMptYwpsgp6No+8i6dSODEqM79mQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeegieffjeekteeluefhteetheegueethfetuefgtdeuffdt hfekueekkeeuvdeileenucffohhmrghinhepughifhhfohhpthdrnhhonecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdp nhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhith esvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjrghmvghssehjrghmvghs lhhiuhdrihhopdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:28 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 752174d2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:21 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 12/22] builtin/fast-export: fix leaking diff 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: Before caling `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 Thu Aug 8 13:05:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757439 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 385F218CBF3 for ; Thu, 8 Aug 2024 13:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122337; cv=none; b=dvMa3SH/mgxuibzHuL6GPOjQl9GqEuna/jMkRCZVktTMnqMZnuKmrrgsHpJ2dcLR2p4MZK+uirQM4KkPT7aFWFOU8iAdYCrevFd/6I/RdImpoKer7HEYgTMNCTbE9+q3lNdOroL1T/sUjX58sDv0KAvfFD8uX5ghli5qhnzipKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122337; c=relaxed/simple; bh=dnFkPaJomKdDhg+XEcx3a1eDMytOvx7O+JOswN8lIPU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jroqdre/PUaHgjnwlAKwXjz0Au0HmqtCYayP4TRSFWtz2AsL/zY3FA72uDVCc2DPN0mn5PMR61D2X8KISdX1ywkj584etPoUp6j8HklpU1oGHuMfcHx35Qg28rvbbWCGgOfINV4/RljZFuFJidOjaQzH6Nn/J+WtrU4eiF6RXBg= 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=Y8zCKvib; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JSnhNxxs; arc=none smtp.client-ip=103.168.172.155 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="Y8zCKvib"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JSnhNxxs" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D054A1151ABC; Thu, 8 Aug 2024 09:05:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122333; x=1723208733; bh=I0EuISd35d RqYWFGmkzWeHGp/BdcgfO/FO3foq1Tf5o=; b=Y8zCKvibtX5wGKo2j6h2rWoRCL vLGp1VJx0IrCZXrUnHrcp0p32VoI14KU8DU0h1/r08tVv40IFQFatm/spuuy0iOY NOqgw/D9p0/SavfpJ23+M4ZTV6V6f35fx9ooFix7u328R8KIlYbISb544qsNQ4FE jIw9nQzmeaIsuM/bHxSz9wwCZ9j6Cr+vyrY4aIhIenYUNciPeQq9jtDQFoB+tpyU FL3zwxT7Jl4H1a8cPbbUC0VgL5fSw3JvjwZ4ms5nA8xLvxbAXTsHyZfBe/nZDqNh TxEz6DoKex1NCthQ8tWU2/k35Bibxsot1sRZ2e3qVR2WnfGSurR0A4haaIRQ== 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=1723122333; x=1723208733; bh=I0EuISd35dRqYWFGmkzWeHGp/Bdc gfO/FO3foq1Tf5o=; b=JSnhNxxsOjZbzOGBHXbKMSWSpYPMn5rhsUmsYwzJ5H5F AcByEIRxn6hh3HMJf6JwzeOSIlwBdaiLGgd8E+HszWyoBXKzpS6GTG9GaR1eWeDe 7PhVx1etVEOCUIc+DAiGxGX1WtbjOSYQd2Fe3z3kgk6n1tKpkBvOyVE+lVeD+71k e/T2v0+JCn+dxdzmrSv28TpkNC5+Tv7lZ5VNBvVQpRTPFeCfr3eh+FpEhS+gHYdo nuAvRM9qLmFyGD/4o/VRR2ZU+f2pGftU7/ao0umPprnhOx1yTWpkTZMSS0uKHCd2 F3fkW9J3DaqL42aKz5tNR8jzHaUX34kYIPgid0Qu5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeejnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 951d5408 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:26 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 13/22] builtin/fast-export: plug leaking tag names 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 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 Thu Aug 8 13:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757440 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 A8F1C18CBF3 for ; Thu, 8 Aug 2024 13:05:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122341; cv=none; b=m8cPWlByQ/8o8ZN331nNg65wBFmfl5kxpWp3/VYpqvJUzDkmLx0pDcbHiluZ0/GKq8BLmsEelpli7r+dXXb2GEkm5uBBXiE3F6/5+bPRE+UUX2ZEhTL7rzOiHwdwmtDjv1FG/vVddKpibMR4iPQE0NFXY5skGL2eHyf2RxeBqvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122341; c=relaxed/simple; bh=1upg5b7TYizz4CP82niP3afnP84tLsj+sGwONfes0OQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NPCszrn69owhB1BH6kSV+AhWWM6g0SxjLAYSyLGWN1JUtp/bG0+SsDRQUKiIRNJwlKYFVNHR8m+4sImO1BWu3d32bi3OgS5LC31efbNrrTUFlIbhzeLTe3uSiH9FnWlAWndQAfrPqHpx2jydgsy5MT1qznsHnyPTuizzubPrjCM= 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=kzyyvYGQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oagQ9Ajj; arc=none smtp.client-ip=103.168.172.155 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="kzyyvYGQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oagQ9Ajj" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EEDEC1151AB8; Thu, 8 Aug 2024 09:05:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122338; x=1723208738; bh=v5Pcsxqp0R aj1P1JX80A+jFJ2jULQksSHp0lT0ll+vQ=; b=kzyyvYGQ/Qc7f4roIrST4RbAWL ZrHf+YOFVwRXWAvDsCwah8kLbBd1JHN2vyBlTSZGINlcWtzMT5qqaa+tdKCUOD4C JUT36NE4ZOcq8mYIo4b9ewxMrGlPy1milQLpD8eMwVvP1tOpyj4QipnI3flBf8GE Dh5Lsfcq8GrVk4h2MWoiGUN6lBuvob+eMFtlrdI04HyHFv5mIW5exMMynfqAxUK0 ERCG+ZorCc1piBfTvSFcXJAiqcEfjVoBKdW73CVEwCaKzRcrAfk4tzRIeXm+1GQh rrdNMYCPd1CTk6YlYUbWo4/2QhYjdqgziOjkoq8aBRFYFBwOQhlprMAaW8vA== 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=1723122338; x=1723208738; bh=v5Pcsxqp0Raj1P1JX80A+jFJ2jUL QksSHp0lT0ll+vQ=; b=oagQ9Ajj3JvbwFB72kbawXYzz5bt4SG+6jOjSQEUvMNa F5gJgvjoA23grFSm7rtaClpDlgWW7dOgS/xXRU+IC9Wy8uxzOFeFJA/gcwW3R5bk ojeV6u3XrmoHMnbSx8jHSC/jKXDEV7su+Lkw9KLn3bw51Y/Fa6icEz9nlbcQbq5w x/3N3KR59PllUI+78KRTGEMzsj6BUB69EsJ7cBwwJh/shLTiO0UsVouqFvnIBR2H 4q4J7wuziFgxm5m/Rd4/AaR+GD/JCoIxsoqtHltrDUhsdUiEmk/akPb2dWRRovWL o44ZxTLG9mBK86Rkk7rapm6mcgJmpSbocpdWo7RI+A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeeknecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9d1bf9db (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:30 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 14/22] merge-ort: unconditionally release attributes index Message-ID: <8f6860485e8f806477964575928d31dba8373f66.1723121979.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 Thu Aug 8 13:05: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: 13757441 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 F246018CBEC for ; Thu, 8 Aug 2024 13:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122346; cv=none; b=sEx6ZIgOdNJhkUslyJYLSTTt6A+JLIhhwJDj1oVH8z8qY74YNxpp50kibiMLDc9aDG29gzxue2/te5mztkZq3z1xvej8bmnMilC7bklN1CqqxPD1PMQTGx1gmwCHz/I6kZKSL7faaxO/Qf+6EcghA+3MLBfMeVlAWAOyNS6tqWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122346; c=relaxed/simple; bh=rhP4cgZ8/2QkgMOPLr2lm+02lIck7bhb1EK+3JXdxbc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ghfrdEbnvksDfB1ZMcZoxHmrPHxfoa9cXfb+yK0j9Ddo6loNlHGoScY0qrJhfi1Wlo0v5OADq4OId5/jOcDbpIRHJ7ZxU1ZOOVVVZCj2qlrwKVf84hELnuHIK+Ros5PcCqNEm5tLZBVau8GOKOWmqSuHHB7gm+J2Awl3otNv9KI= 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=INkyfufU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uDHNTjw3; arc=none smtp.client-ip=103.168.172.150 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="INkyfufU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uDHNTjw3" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 242091380522; Thu, 8 Aug 2024 09:05:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05: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=fm3; t=1723122344; x=1723208744; bh=fGDbC2lrxg mHtTVpLXeAprYMxN9RyFYnJvt/N/UKvm4=; b=INkyfufU3PuFfQQHdzMxpqh8LG nIEMDAa38no94t6tVlICY4JWJ7VRJwXUixB2sZfek2mVeKKMEmmgSYnAnegpmaPL 6OUm4EZewCXrAEXI2fRO+s0Bu42+bDYX2XdAbadtkM51uIIHna8/EpcPsNiisxMs UjtNVqhqvnzzzDpEGjon4G7FsGfPmH45gDMWKU8QhuqU/DglhR1tBBOctIjcpK1q HKMAIx6n+i9l4VesuahCRPB5e471oHPSTntJ0bt5FhYLz6rEqHPEs+1rCM2qS5vF N7f6pIrRAp6TWxJn9CEVunkXl6Hwp6z8tmJmE8R7uyb8Ft5e/XNTaOfSrPGg== 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=1723122344; x=1723208744; bh=fGDbC2lrxgmHtTVpLXeAprYMxN9R yFYnJvt/N/UKvm4=; b=uDHNTjw3CRBMtGhf4pKdgapdA4HtOF0pEdyoy3/GLUQH KaWeVY1PyLMasSoR+q6G65wV640CsDvOQvurGzUrVzDVuHqViDzgsprUync/M7Ro p9QAX4yUEkjeyUkI4k4akKDGyA5YJlyfNr4SEW2JcIQkIUe7XU3YcpSxSjYs+2Oe I5WL0VC0NusXiVj8IZ4uKwHqAG+20ClXGaBOKEOgGu3WraQ0lEF5nyx7HbI57h+L D7SDibTDuzVxdld2S0YEdRCmkUuRerpcD+Mgbura9RkIsrGuAstNiOrMAAi007Rq SGb9NK6bW2tBep4rrWfsMn5brCFxF+bxYiYZoZLjkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeelnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b80517d0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:35 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 15/22] sequencer: release todo list on error 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: 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 Thu Aug 8 13:05: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: 13757442 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 D2C6218CC0C for ; Thu, 8 Aug 2024 13:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122350; cv=none; b=qHCIUKxYPOGFy9bb9xPuIUk8POSV4GTFI9xxafHCdMxZBXEEkBTLBlyb9/m6F4+QCYUsm5Lfvp9NvMKhuclPyQvgRJ3ko6WtYfiUfIAZkw6AzLP6mDmhtTHIIcK2kghI29FRlZEOeGwycFLbMEwsfuEhcdRz+ZkYkED7CM+p2AI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122350; c=relaxed/simple; bh=AGewfgi60MmoZT02SLkTpw8s5FliFb7W/Oad5/iC6hM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mgVdskALJmlQiFvuPIAwH0jELTKiapY0lBbZtkEdsBV48ql6wEFbM5jrbPVicIqla4wKtAMHMhBtQqK6yFsXVrl5+NUpk8Dflq1yRaEsIACL+kYUFAaatr4lvYq+jBexfizAiC29H0QscpA7mAfrw8oCoh8r3RzA9ClSXVZIotA= 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=JUaz8wWW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cW7vr108; arc=none smtp.client-ip=103.168.172.150 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="JUaz8wWW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cW7vr108" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 38F1F138FC7C; Thu, 8 Aug 2024 09:05:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 08 Aug 2024 09:05: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=1723122348; x=1723208748; bh=vAvDZLuY5B O1FtNiA+PmUiAn64uI7BlvdmRdVCfVJEs=; b=JUaz8wWWu+PxDhE50XYSi2I2d2 H624TCwoTkEonVy9bwickVX0/HgEaWfT2TNnj5zodAYNcgYGIj0EoYiQLq6grx3k 2xT5uxtNgxuK5E31dT9GL6pNUpLlfnxdxsLATaekAUxrH5kdAOzinFPw7rBbr0rH j7rPDIK1Vl7d2Mpt5BBFAy+1UWJMIP5U7pqjzL/bRARm79SpD6gzbC9oIBW3amTQ xnp+aTZ2ig6CtKghGeux/zSRTOL+lI9u8fMl87mrer2NQcZFN/6UcZFOWogSZIDs 7r7DPNr+KShCF/7DpjuSez+4pNqz2XY6S23+dP2RfhxWkTs3e6wQKySXeLrg== 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=1723122348; x=1723208748; bh=vAvDZLuY5BO1FtNiA+PmUiAn64uI 7BlvdmRdVCfVJEs=; b=cW7vr108dXmHXRjgXOqB+eWsM571z9A+b4LuqdyK4fl/ t7Xz7x1Fh6iw0LbL8uFMuzQ/UzWUrqVeq9cGmPeM9lGZWGy2cxt3gHLzsaSozwSw rzRbV51FFKljgLkdLie9W8krEd/rueprmPopS0tFc7yY+2x4Zl+K/Rgx28hTNfBo EUuEvIRcFTeCFdL22z/CGp6xwR5ZXi51QWxaMyULvvV2AsWxmKyqb1IE4nYa0cvw aBZSis2jLR7vDDKGXpjk6a7urFfIBZM01U/QzKmpmI4i3PPB+2rYQj/SGdJgs3R8 X6R61cOR+zyoWv5NcWztgwpJkpwPAOPercqRWA8bLQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpth htohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthho pehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:47 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 234510b5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:40 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 16/22] unpack-trees: clear index when not propagating it Message-ID: <2755023742e33da6e420638ea1bc90cd31150407.1723121979.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 Thu Aug 8 13:05:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757443 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 4B02718C333 for ; Thu, 8 Aug 2024 13:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122355; cv=none; b=dW9/iujzscTSoui6vBe3exZ/HUY+7DifoBt+vWSrDgT3UTyUpjUW8RZCfTaYOtnozMKGQzErMawVkLfucYd+QyX6Rc30AfJPmhK7EO7pe3As7MdWfH7joVn/ekzRpo96cEoGQiT0k0EtLs+awIe9dNTr299aYLq41zfXqxwNWn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122355; c=relaxed/simple; bh=h66vPxNJLDUjULagXIM2P6YAg244y+cFx47hZ/bYtQ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ohRsf9Q8jtPadIoQRJK036AIAFYiqZYsZgbqZSXu51e+za08IK0R9u73DES+njjHHn4lqHEAOWoUK8O7pQ62nPbN+IyXeyNwcd+QfenSWdO+Qpar0wYxsj0a7BeHBJtzaWFdHc5wKM6szeGZZNDpcrhGRc3cgOjaBtogTdJFQiI= 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=hMwZxXH0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eR2adLTm; arc=none smtp.client-ip=103.168.172.155 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="hMwZxXH0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eR2adLTm" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5A6741151AC9; Thu, 8 Aug 2024 09:05:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute8.internal (MEProxy); Thu, 08 Aug 2024 09:05:53 -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=1723122353; x=1723208753; bh=5bU/hHktVI D3YUUZBxWmZSC1cDj7jCtG/YGcVhnvzms=; b=hMwZxXH0mA3vVBKZrCUb1sZt6x S1FFxaxy2SPa1hIWkvidh+yh/XgQ0ae/QDTNlu7ND5fEV2Rw1hMDt2Ctsg4gd5Zr ffKnyxVGlZpB93n0mkjDR04EcFvGV/Ib7erCWjGxQ21WsxnIe2otoMVI0cLO8wTp 0DYnlKLLzQ3h5O9Dzi5wpwL32aoN6q6r+yzzrg0Ngm1GQU/rPivoxeDd7HQKDiFT baYDCUuLVcUV90eapU9ku5B1qru76W10sh9400rhdFEpoXANtsyBovISXT7sHN5k Td3RXLk2owta3/zpmugI27Qr8HLCBuZVZL52S1iN+glsjr3Uwm+VnoYQ1V5w== 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=1723122353; x=1723208753; bh=5bU/hHktVID3YUUZBxWmZSC1cDj7 jCtG/YGcVhnvzms=; b=eR2adLTmI+VfWoZGiCR97RHSbE+8ZfORzeVnHFzlsXBh 84DlagIRmO7g06BpsX+2VOL4GQcCTwTcOg8LhYfnAaZEfuqeatWBUg2LumVzn/am b3ecQUz5PXJI//ObLl6LUfcKA0dvz5uzf5AZ/hkrhcMatUhKeOyIwilhVNwkHx71 6pCVhTzxnKx3sKRqPLapgkX5ghUuBPsibv+EBANMinY+929WHry1I94ouaFc/Ln4 qhGf+xM4+45iB7g0r3WT88PYnBDGdadZ6bSN/mO6K5tk6KZCU2gx8oABtwjHS7Yt kIfF1SVn7V5lGe4rBOjvZxrUpuZNAYxGU2OWM6RRxw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtphhtthho pehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3b0283d5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:45 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 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 Thu Aug 8 13:05:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757444 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 2743B18C333 for ; Thu, 8 Aug 2024 13:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122360; cv=none; b=a5wRKZPON98nw+vSIhsb/huZxna2s3O4/sY2kvhgsBKc+bbAfh96TJKr3djExEPqBEJeKNj0NGrtRfY+kkzxKZ2yVfoeM41sHXnYq5/92Ze8E13GmDXzz8g5t3swRJGpQI96UR5MJxhwSQURhsni0juA2MacWFkY9uDEHGALA6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122360; c=relaxed/simple; bh=C8HQKjGu/Wwze7Lp+IrkWZz2KZ1pzkYDi8CTT0Y8tmI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WGMaS5ci5NHVlBmJZYT0WvYZxhchdA7YYovaAY+soSP99ZRZB8KL87pH3Wu8noQUwvRxz+rqhB67KApQFGChZACFWZoGX2d88rVPN4RVIL/A3+bqvu6kx47jwqr4nq2Z1tnJZ4XTNz5UuwzPW9+7n46RHiR+4Ak/P7uNsiyW7gU= 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=Bt4/JGO5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=up0aWjDi; arc=none smtp.client-ip=103.168.172.155 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="Bt4/JGO5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="up0aWjDi" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7BBF11151AD8; Thu, 8 Aug 2024 09:05:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:58 -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=1723122358; x=1723208758; bh=FXlAYSkoXQ 1x0B8hXh3SeaBGA+U1CdVN5noNTlVxTuQ=; b=Bt4/JGO5yflnfIk95tOniy0fTu DRqO5D/ok3GceA+zCpptV11ftBf4Oa0Nb/QDjT0Zg40FuQTSq0JJCLbcwQ7CoFH4 i1QpvkG/U8sdEHM7hI1Sb+MuYGkLFEw159w1Yk/u7Q9PVT+p1yt1TqOsxYhVdDIQ woBGJh2VtyjYtqRErcCuMA0nqJyd+O/yUAK7YSAyLGO03ib5pzDIsZkJCbtq0i2a 6SkeBe7iFpbcWy1P8rEvl2tizZiBYVz4qcFpglnzgQ9l13p/r1chjZnrHIH9+6M2 W1njI9MKAVHijU4NlobQCyyYSH/v42TPCI9D0uHka+xzTr0xckXUA1gmNH5g== 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=1723122358; x=1723208758; bh=FXlAYSkoXQ1x0B8hXh3SeaBGA+U1 CdVN5noNTlVxTuQ=; b=up0aWjDi7H1bI1/mwbuGwb29SnaApSI/sZTOT5iBd7u/ gA8uSw1efrHZhokO2Xg9oT5+i4EHEKufenYSrxH23zm1R1kTKQfybY8nxAA+62hL iMpCPSKzzfr7quyft3a4YfDTyZ3Z40o/gOisXkUynMQKY4honi8wUzLPKaeP1oUe 5yRAxli+C8R58j0SXWFcR06/03BwMHzsJeKCTG+7D09GLUfI7tJWU5E118j0mFKb A1untAIDsFVbsZc8CzFiUNrWZLlTnYXEFGyJ6kStmgd8qQ1ZFicHhLi1l1mogBNt P8yQKcGYa8rlzPGYA5T1GEH+04YENu8T9JBl1/LnRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeegieffjeekteeluefhteetheegueethfetuefgtdeuffdt hfekueekkeeuvdeileenucffohhmrghinhepughifhhfohhpthdrnhhonecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdp nhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhgrmh gvshesjhgrmhgvshhlihhurdhiohdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ab90a3e9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:50 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 18/22] builtin/format-patch: fix various trivial memory leaks Message-ID: <343e3bd4dffcde04d42ef005c715cada724bba91.1723121979.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: 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 Thu Aug 8 13:05: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: 13757445 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 604DE18C333 for ; Thu, 8 Aug 2024 13:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122365; cv=none; b=DBM6oDO9/gaNrSdvCWJPp4z3fcOiwdslbF+BHPs2AhzmHh5naEtO14lWGxIzzXu2Tg/pU+riB5Yd+bPTQuV+JDIE/gjWSfoeOLvto7qUYo2aRNcPagwXsqFQYYPznyV8CQ99YppIA1xx8JoIb2nFf+xYqBsLq+xn0Y4Q8aDvcEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122365; c=relaxed/simple; bh=GO9yTjtwcrgkCGyc+0gix6+c3rFc0bEUWH9wMwPE3q4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NiInXAedXM6iVzj6zVaEyCebx/90glmSVa8zqzrxCj6Hp0rcksPNZ5Fsx7m6hNxUgkvo4h4VGTnjt57aARDYA3b3gTpOU2c+Y6CDiMIQZaxGkViLWdfn767m4+hLqD6QRQMquwjNFUO2WsS7FnHoPAxyv3eOfX0GwH6YpBOroJg= 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=N5D3M1Wt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CG5trl+0; arc=none smtp.client-ip=103.168.172.150 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="N5D3M1Wt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CG5trl+0" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id B1EB3138FC80; Thu, 8 Aug 2024 09:06:02 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:06: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=1723122362; x=1723208762; bh=Jfc+x53P5+ QhSACYg7gBpdGLgiyobdi/f5x1BSdY63I=; b=N5D3M1WtYaGkMUm874unNnOmdj OP2UwNl/2y93hXa8iYzsGp7jincnoJk3hEFLRfvplwUfdXzW31izIHhJOb0wSo/H 4Dl+cYdrLtrYKBkeb7h4SlIsKoLWh7eHLvjOZ36uZuXaZ6uiQ2K/7q9gRpPQMYYz pTVHxGEaDoY4yi3Ay0rBZUpgPWCIiK1jEzYE7p0AxXVD3wc4Ve8lhz5PMIwDh4g/ ZZzYO5n4Rlv1d9PmgWHx2/Gqo0jwgKK/vqRaSyRgaLGeExAZDzIcYP2ruiICQ4Ns DnsYZVPjknuJRuixBuo47+eh4X1YIfA40lUVFhFyj0ng3iniCAiNJa970yUQ== 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=1723122362; x=1723208762; bh=Jfc+x53P5+QhSACYg7gBpdGLgiyo bdi/f5x1BSdY63I=; b=CG5trl+0LE8uZiy+8hdpalljzozFPWVLsuwq/XL7pm13 NUQfAQuHlsEkw8gMctvzSVSlzeymD8UkSOVpvqXnXaNnphL5850kDK23ybmvksqy QsUQnXoj1X49F+6NQ74i86qWNwpuXUBsNpzuPHO/Y0bO5PBNdoASxSgCE2hmq/IP nMzrq3gsvJ5OXHEkKmEc20bWZDNA0s7PXyDszxKYA6HV+c1JNxJr4uF7HV+uA8Xs xfMK1K4Evjrhg+17nqKFAliUk1yEhqvbiEHXfwzqoduk4TzCoqSBO3SvhrVyeWqR 6utZ/kSrFcgroC2V/iZKJ38WfkQMOxOIoIlVTbwQQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedutdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthht ohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:06:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8775d4c8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:54 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 19/22] userdiff: fix leaking memory for configured diff drivers 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 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 Thu Aug 8 13:06:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757446 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 9E79718C331 for ; Thu, 8 Aug 2024 13:06:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122373; cv=none; b=iCISLOAIKSa4g+OuJ/dA27bPyxcIyRYEtsBmpIk080yD5Btt+PvGHRUJpdDdjH9PcfImyHp9CNAJxON3KwtHSHKuV7LPuDX2xocRtZSoOqwugeA27OU2rJPYkhqYTygWwvPVdGFDcXXeCVN8WxT1fmaIbfSQ+WPwdm/8RyIoHaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122373; c=relaxed/simple; bh=6vBxEwUX/+0maFk629E1LSZcl/IJf10cwgdI51wNqBc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kAOI4TrN6+jZxRpGgLN+ykVSiCSB+cwqyva+eZ5EFp2y/ebOBO0AFv5RZxXRS7ftIxMrNdQeLtbelG+LCfpclnBrpqaVRiznyJE4AEPsCljGeA9+FTsqRoTBl8CEHCui1/QIpvy9YY85zOh7k1lpYa1B5XGXSJVqW1BQj0pJyU4= 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=HsMJdQHE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CApEIVTz; arc=none smtp.client-ip=103.168.172.150 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="HsMJdQHE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CApEIVTz" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id D39E8138FC75; Thu, 8 Aug 2024 09:06:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 08 Aug 2024 09:06:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122370; x=1723208770; bh=kszWkZkhJS fCknC0FruFFyvOVDXw2o7g2mlXIWQ22DY=; b=HsMJdQHEyCJFfOAR7vCHzoicXn eOv23oDXq8Lvnl0EfwOrzjP0X57bg0Gtmp633oot677gJydXdQJOQq6MBWkzJUpj 2vq9GWXkJop0+FryYfv/ekMBerZR71RwJUEmjE4pKVtcvNcJxDxnOLHqQS9yivAP B90EV6OioKNpdDlxOaS5pZ77X5fmffeBAe0/cbj+JmfTffZH1L3vugCfwVWtEmRy l4S9gi9Tm2essP+tsZYDvYmuWdsHb6pKxOpKR69nHyqa1BVYkSx7NRX7Kn0IVA2O yCgZHl6sv+Q2fIgRuAk7dg6ml/N7mAtPditF5ksQD4Wr3LnLyrTQnfXLjU3Q== 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=1723122370; x=1723208770; bh=kszWkZkhJSfCknC0FruFFyvOVDXw 2o7g2mlXIWQ22DY=; b=CApEIVTzhCaJYA59xMPEIxxFQDyyu3cz+kpFcXSfUY2g uZF36dKR2X2m3OMgNjlnSHkCH+DMUieED7YzR+9fIcBWS/f6xV7gduDVm3rJ14RP 0vFw9ZR3FWN7nFzF/FTINhOIl6LTAzqRhzTMtzP/gz6dJygegOSoM4fBN66poAsI Y88KDylZD5+uB82AmRwNl/y4Km9STxwqlmQCuKXrqAIoRe2hBzaNxIEd8kSxr2q6 VTefWemlqLsDUURV+sD+qlXl7KXaec0AIUslARmbvKFMavhfHoX8KnLc47ab84hY 3qif+IDi2aTw56+dIqQzkNfwYsSIz3M0bwOaScmxcQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:06:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ae3e4e96 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:06:02 +0000 (UTC) Date: Thu, 8 Aug 2024 15:06:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 20/22] builtin/log: fix leak when showing converted blob contents Message-ID: <78882038333ae40bc4520d60e42b590c68a5dd8d.1723121979.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 Thu Aug 8 13:06:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757447 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 9300018DF84 for ; Thu, 8 Aug 2024 13:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122377; cv=none; b=P6Y9GqUDeCpMCUQO+LDoMfNxGnoLkDJuOdNSXNCrw7XQVn0zoIzqAOJgryZqYGh1UDPWvaRzZ1iZdPvkM4/e8781/7ZUm2JgzDRPE69RDDMibGD8+Z310JFZRiV3FMFiVYGMbF4AoeY1LCGipDvRMb+tcabMofb+YwXPrtXQv+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122377; c=relaxed/simple; bh=GIlxa1HODxkm3hV8nIa7Dtqbo7cbrCwwnRK+XbQETh4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rQgQZjLH6QwBMAvrm3oBq7Q5fo9bjHKbmcJ5J4nYJgA+jHsbSvvgLxHM4r36vtgq9g2BONpagoLDKBEWkepaId6ytdgONYhAVW5ZNWouwe4symZxHlydT9fDLQGoqq272RI0EkKdb4+eFF1fs4gYwgP3qrWF3aRxOz0LUe0PaNI= 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=iaTJsETU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=r2VXH4ZP; arc=none smtp.client-ip=103.168.172.150 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="iaTJsETU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="r2VXH4ZP" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id EDD26138FC83; Thu, 8 Aug 2024 09:06:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 08 Aug 2024 09:06: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=1723122374; x=1723208774; bh=bj+vfxISpE cIZwT0dec/TuA4lSrpWQ3tkTj/ADbEMlA=; b=iaTJsETU+K9Iz6ERjhI8gi+sTz FEzOeuACNpfEvSrwb4NTM4kG2g0C5kuZi0gIGnvOs59tlWrH12cndAfd7DpWuj9i NORIf/0vQZw4pDp2sv0WKXbHf6acfTAJO0MNcyfMNhT/XvE9gCtGQy9y3ngt6wWs M1ZhSDA8VbIqmTQnQC8UEgt8rSQqoUGimrs/MqrjS+ej3oPy5eXqJ/wATj1PEosw mr2hBHOp/asiNsExa/HMh9cuHP9F9RfYG7UdKPihvOVzGoOamR5GZ0qL25+EszTp ZJytrl7LJlj44InvczgoBuh7uIPA9Pmhx+t0wS0ROvrnLodgCy2hX0n1WtZQ== 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=1723122374; x=1723208774; bh=bj+vfxISpEcIZwT0dec/TuA4lSrp WQ3tkTj/ADbEMlA=; b=r2VXH4ZPRX0+FoUNC9844ZeRaolR//KTi07SDKuzUBcc 5BfOj70v15mjxEvljZQ4M2AXOKxZtBoUGD/EEbMAFGY4GSDyUy7t5JrrhWPK1g9C PFmYGFAAC3G8IR+j8IZ053ZZGd5UMdQ0BF3+/iF/2rncNj1dVWe+pV79jR4iQJjA hrIxh07OC6Lf8wuZlwKUC2+Snn1oTVI2hHgdC44Dxvq/qAV8rp0oK9UrtHYp2mAL g9p+T9BHilbYboqoQkoX1P0B8dHXIU3GVi9wO9BOy3u4YSgqYL3SJNzaUJ1AmdHv GObl/v+R6pCYEIQEiUYIcKDKYXe54uvVFNkEWX46tQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehphhhilhhlihhprdifohhougduvdefsehgmhgrihhlrd gtohhmpdhrtghpthhtohepjhgrmhgvshesjhgrmhgvshhlihhurdhiohdprhgtphhtthho pehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:06:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b0291d78 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:06:07 +0000 (UTC) Date: Thu, 8 Aug 2024 15:06:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 21/22] diff: free state populated via options Message-ID: <245fc30afb4d9993381ecf53f8c081b17dde3539.1723121979.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 `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 Thu Aug 8 13:06: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: 13757448 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 F0EBE18CBF9 for ; Thu, 8 Aug 2024 13:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122382; cv=none; b=JALvNimGrOr5vpd0vD1xO6q1S90oK2vRmQ5/rNEsJDwJq20VEqMcEOpOEdaM6orbrHbhsVlmUvPpEHja9J9XlW3Vu4U2sPnr4R5X2oyGSaS87FSlFEQsmBBPgnnVQHbXvAgTRoQc8QOwDz1wzZIeHldTuuUOsJ9OBGLaO1MPzAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122382; c=relaxed/simple; bh=sByQKiqMXwbOhLp5TBIp6n09fxJvHvchZOtBqqmHxLc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aECPlXBUOqa5Xu6ZOUg28Edq/rGeAtM1vZS8CQ+8VM5vEIxFhQppyycC4BZQro6cjt0gKg1S8zYAA8CyCLs8gKtfw6fOr5ajkk0eVL+LYkS21Q8IbeJMgNRUmXwYbIHoLGcBo/MJBrlJ8dZbeuknLtfBZSEDxmE0164NPL70wZc= 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=DiEYx6b8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TemR8VXN; arc=none smtp.client-ip=103.168.172.155 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="DiEYx6b8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TemR8VXN" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1F2151151AB9; Thu, 8 Aug 2024 09:06:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:06:20 -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=1723122380; x=1723208780; bh=U9wiXEcjQY UnPW3Dk3F3BRl+Z38bS3RBcyTVb4cWE10=; b=DiEYx6b8Opam/72hDGy6yH917W pB9fRbk2ilrAaFhRxodUV4/VsqLer0Yro+S79VMEMooHEMJgOk58zta5B1UtpjDy tT5VCJcrNnURWBw3CJP/8L/+Tv3UZXli7eFq4bZBjVxn6n307+4OXJ514QydUkN3 p2xbyV4E2/7734MGOm6OKCXnrShQRIHicAI3fLmR/odF+jMeLTGnTsgfGyGhrr8E OwlyjADRq+Af++Su20cJnsjY0Q2kiVnoyWBXpZM+3tmGjr2lriuqxzzXedefe8yl PUuQ+og2lZH8lhUtnZqz/NsL8W/vJAvJ3cmXwPBlyzURu1tKtHs1tmM5NmnA== 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=1723122380; x=1723208780; bh=U9wiXEcjQYUnPW3Dk3F3BRl+Z38b S3RBcyTVb4cWE10=; b=TemR8VXNHfpOb4QfD2CJI6tif5xn0GY5hduwj/atqHyk cXKdV0mEpynBglsq1gFQmaELJbS7MavtRQPkFpjKkHRKVvvE2sZ2uWSahgmtoztl FqvQuSVl4VNHwZdSeAnhx+1u2eiTb+pbwNM4nNfVllnnt2A2LjMHb7zS98sxzOC8 +CX/G1tBKhCp7X2ezXtq62AAgZJ/v0ZOiR5x9BF4M8HW9TptGh6K3MNF+ZYmqvpn Q1Kl2uZnApmrwSrpuVxtWzeWxMW7VJKFG/VFSRHOzjCvI82i+gxSeBS+dHg3WdFR s8K6yVczQPZ1L8Hj2MAhNjdyOGzPkkrQvjlwa7XxFQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeduudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilh drtghomhdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpthht ohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:06:19 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eaa67808 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:06:11 +0000 (UTC) Date: Thu, 8 Aug 2024 15:06:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 22/22] builtin/diff: free symmetric diff members Message-ID: <343ddcd17b3e13dc7b8ab89f9c9c427bb2ed101c.1723121979.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 whihc 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 () {