From patchwork Mon Sep 16 11:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805329 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 BAD1015531A for ; Mon, 16 Sep 2024 11:45:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487128; cv=none; b=FeCwQDSYHV5XIBnfMq/kGu4BT4VA3PCUO0r9ppoGvxLqGnlgkSvPTCyUIzexEhmii9XKmoxGiF31cPZmfjlSO6rdEvgWllbjV1gjC5MzAub1mVFCMrj70Ib26cC6m+7d7l6UcpV2cxZeyWzgiHbhwvxML9mzeEAtbfKprhgee90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487128; c=relaxed/simple; bh=MhEp8N82CtTYaYucNOduWOUJLLKUOrdkaKiBeogl+7Y=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pknFmikbL0i5OqASESL6g+4BlKSASe3PAonoCVofgkObJtr2WzrmzVx6PN0zciJ+kerwsbk52gM233fTpbfB7V3p3EQjYWtjBMAKixNIib1D8pRt9eQhdioEAxs02YESd89Ncpz9xQI8qVEJZp1AjbE2YpE9krmJGIjzqfOd5mc= 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=X+jLHkyH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SWTcIaFm; arc=none smtp.client-ip=103.168.172.153 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="X+jLHkyH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SWTcIaFm" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4B7F81140125 for ; Mon, 16 Sep 2024 07:45:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 16 Sep 2024 07:45:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487125; x=1726573525; bh=KvAVlW2joO Lw1w0vsTKGfRpz9NM0Xadr6jGYuKOhiW0=; b=X+jLHkyHZOZW48MJ3orUi/N72a OMRrAz0B3ozcRnlR9fiOBiGCkl8tFa78EhuCAjC5sCJz2Bzd0TW79EI/gdz1tXX7 ufphgNQbzs6Mk1UWuXsZIODAixIFjtoIAfHeefaS+Yqx6ruG21TfUtQ/TmfGaGGo jsaTkMRY3X1uNjEEbjYh/yECj5x59LRyRVIOqaKYGj8gsQ6QlwcCC7JA0hvDaIPR Bx6j8H5Zbh7Z0EN1kMlNppIk1E9sDkozVTWucjRStc5kHAsaUluPoNSvsabztx24 InfdFAFcqbbhv+fHrKyFCnpOIIP52+Nq3dqusSzqWSJ5hDtH4n3m/9Ibhl4Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487125; x=1726573525; bh=KvAVlW2joOLw1w0vsTKGfRpz9NM0 Xadr6jGYuKOhiW0=; b=SWTcIaFmUIjvV1/3wZ+sTUr9qrWDVNZrssRBsyxa7W48 Dmtx5+xjbpTGGZLAZYI3OmeM7dKVZc91tX61hJYPz6NX3wC/6DlKSbZYk0YhzmLC FLo/8QiCs5Jb/4PilYtBRRIoXI0s5uh1aIWkI2xmUbOMxUVfGM0zRkNz4YEZU5RJ lOw6pUHPLVV0GBSw6uLMsqq+/L5UeientwkwyS2mY7HEnfDFLXa035bAM9UKYDjU gOON+V3mUA8cSMuqd1i3ltoMFfrDu4LFvTik7JT65n1NdiZfvCHmfSqHvOmoYPvA 0xZHgpxyB+qFKQYvbAWF/dujoPacshqXdw8m3Mi5eQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e4750f47 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:08 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/23] builtin/help: fix dangling reference to `html_path` 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_html_page_path()` we may end up assigning the return value of `system_path()` to the global `html_path` variable. But as we also assign the returned value to `to_free`, we will deallocate its memory upon returning from the function. Consequently, `html_path` will now point to deallocated memory. Fix this issue by instead assigning the value to a separate local variable. Signed-off-by: Patrick Steinhardt --- builtin/help.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/builtin/help.c b/builtin/help.c index dc1fbe2b986..282ea5721fa 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -513,23 +513,24 @@ static void show_info_page(const char *page) static void get_html_page_path(struct strbuf *page_path, const char *page) { struct stat st; + const char *path = html_path; char *to_free = NULL; - if (!html_path) - html_path = to_free = system_path(GIT_HTML_PATH); + if (!path) + path = to_free = system_path(GIT_HTML_PATH); /* * Check that the page we're looking for exists. */ - if (!strstr(html_path, "://")) { - if (stat(mkpath("%s/%s.html", html_path, page), &st) + if (!strstr(path, "://")) { + if (stat(mkpath("%s/%s.html", path, page), &st) || !S_ISREG(st.st_mode)) die("'%s/%s.html': documentation file not found.", - html_path, page); + path, page); } strbuf_init(page_path, 0); - strbuf_addf(page_path, "%s/%s.html", html_path, page); + strbuf_addf(page_path, "%s/%s.html", path, page); free(to_free); } From patchwork Mon Sep 16 11:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805330 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 181691514FB for ; Mon, 16 Sep 2024 11:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487130; cv=none; b=En/+uOqj0HFvtIM24Rsxnir+fDT7Zgb93TkykI3qw8J7UYuBrscmRRKaRmpKMBb00jDodvUsHPNp9enei9sZV1uOCcBS+CsfgxGmdbcRolPD73ZUCZdQSgGYYeTHQ6QJKxk/LJ4GUZQP1uMC0HxUx9Gqn6im+35KW/FT9V7MPNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487130; c=relaxed/simple; bh=2RBC8Iykf1IoJkTRZDG+rgIeqcRdsgjg9sOJjXet92U=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HYuHjrJpfDeiTf+KzZtqgVPC1ChZyL4OQMJKis5FK65KZKagNWAy0swz/JUv4UOzcaYPz4e5Ecx6L+H8MI4BP3OsrESDnD5Hztt5kmZ0q1sl+McYsQ2HgDy2bdf1abzsIMM/61ku5FGe3F6PfiBgvWe/KdDTL1oGPR14kKSv2U4= 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=LFMrUNQu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=l2fMIWEx; arc=none smtp.client-ip=103.168.172.148 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="LFMrUNQu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="l2fMIWEx" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 21212138026D for ; Mon, 16 Sep 2024 07:45:28 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 16 Sep 2024 07:45:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487128; x=1726573528; bh=0+9kmgD6j9 ChrCCAvbIKMo5Hh99sdTE/YYvNfhu0M6g=; b=LFMrUNQu7iXZt52zO1i0+rTMZZ DBhA0Hd/exXiOnTvffBN1aso9GRzzdTnIMHSPQEjlfYyPLebfxbXyKV35E3EVq2K K/zwLpadbXAh1eZ+/V8DCXv1UttCW/fgVadKyw10samvK+RRZgTljOW4vYIvJve8 q66ImsgaYTHpIWa6mUycDumL0EUvRrLqvEML5yU/zaN8xTn37WLHRhRX4WAx4ScH 4IyTWC2sQjcsR1uFpPZqSYLlTZefBwBeflJ8aTptNDHWDVfoWM3X6iTCCos8s+xb XjeABpEz2As8mdUwo+Bcmps9xUyJ7GJrv8dvqy5XGOd2O6w8BJbum7jkQ5pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487128; x=1726573528; bh=0+9kmgD6j9ChrCCAvbIKMo5Hh99s dTE/YYvNfhu0M6g=; b=l2fMIWExzwbCYXg0MJCEUhKjQusnipHi3qNsGrVUNiGf UmPK8Hs7flHijK7VnE28GD3R8ETyWEU7Y9WXpbM9cFr+5kBJHMIiQnN+S1Z4y3Un ifQwt+D7jG+M3IgD9OeQFsG1PPi/MrqbAEX4ZmbjRBA6MuDBrC9WdDEeArwAjLTA sWOUf1H/ulESWhZp9e51QagMfNY09bQ3bUK1mmK3M/wbSz7q9QDHkHdMr56MyAup W08Lq1/HgCM3iEM2XhnjuzBVsyvkJBepfYQEZcZB2+/Wqz4cFzVHaxFg8Nd0ZqAx U9g+Aw1236/0C3yTUnDPGal9evJdUb3/RZRoGspiQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a0ce2a71 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:10 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:27 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Message-ID: <4a59fe15ae30548164d1433d1d96fb2726512cb2.1726484308.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 `html_path` variable gets populated via `git_help_config()`, which puts an allocated string into it if its value has been configured. We do not clear the old value though, which causes a memory leak in case the config exists multiple times. Plug this leak. The leak is exposed by t0012, but plugging it alone is not sufficient to make the test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/help.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/help.c b/builtin/help.c index 282ea5721fa..2c249cbca4a 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -52,7 +52,7 @@ static enum help_action { HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION, } cmd_mode; -static const char *html_path; +static char *html_path; static int verbose = 1; static enum help_format help_format = HELP_FORMAT_NONE; static int exclude_guides; @@ -409,6 +409,7 @@ static int git_help_config(const char *var, const char *value, if (!strcmp(var, "help.htmlpath")) { if (!value) return config_error_nonbool(var); + free(html_path); html_path = xstrdup(value); return 0; } From patchwork Mon Sep 16 11:45:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805331 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 E012515575B for ; Mon, 16 Sep 2024 11:45:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487133; cv=none; b=ab5c9Vqw+qZLCviB0/IxdUMcY+mk40wUKsaZu1QUw4++rKND8aUx03C5BJGesCJQGew6ehrP0hHeeGnC8alKWu9iTJ8RWbtpJfNciPb+pUa+tRpCKinUKQ8TpdNT0RL8SJRUsCF1bdylSsYKlmCQQE3DOqgK2cV/R2YWOPkSZK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487133; c=relaxed/simple; bh=/Mkj4LhspWe9G/jHPGzpraKAibeOo+VefIElPFTFQPo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r+3u9YbFW/h2Rfj4TIFO1Ybe9RjnhgiRJHp6UEnXsVti8sZ/7BAdbn4uhdmNL2ruGqZA2R80xk2LZSUUGFnMKajMc5nP29NDSJgR+JsoQKTWVlbkbyY5KGj3tUwXPPPH8/7YVCROl7ECERjN09XmDti+dhM1WAqmWG2gbM2V2vg= 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=WK6AQXuh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JS/e6M+n; arc=none smtp.client-ip=103.168.172.153 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="WK6AQXuh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JS/e6M+n" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0D3991140125 for ; Mon, 16 Sep 2024 07:45:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 16 Sep 2024 07:45:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487131; x=1726573531; bh=Gy9dRi/RIr FcIF9V2ABkUu47w1+Eyo2IO+2FM5Eh8cE=; b=WK6AQXuhUnNdDbb59ly2QPC+rr 9NaWZUIsxX0xmWhImotHzSb7GtREomTVMHcT09zEV2qA8J4LbMuTF3Uc/GVqY8GU RpK3eWTS9QciizQQKy6dwynrr609U+lElA8F7yv5Z4TUrmIljeDocQvMEOryoq0S 091A1pGNgPnHkNSfM3kjwApvUMrMM1SbUkU0opliQeNFJ2G+UoLWj/cxQMbj+Att g1Gp0b1g4iHIWyjv5NB1X0zob+g8uYkvZaNV4ou1DJCWHdGie5wI9jL8LoMvlG3e FRcLolIhvzmPKTew50NEV+U4HipEHa6nJhmksIRrExjVapGppKJoXnB8RIAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487131; x=1726573531; bh=Gy9dRi/RIrFcIF9V2ABkUu47w1+E yo2IO+2FM5Eh8cE=; b=JS/e6M+n/Y0aMsRz5a6VHg9LEaHLHTSEOhfKv94lkINA msyQnlXN23xhZsyCtT4/GyxMb0J5K/KOFmETKlO94XDeVmDXYpAqB2rh9vhl6zhn KcGfPwq3hHr3h3xpHOIn1g8eLHx8OB7cegyRUiEJnhjL12ziEUzrnt2dCsw1hw/o bzxIEsAq6RtyYIfSHp2/aE/bZusj3wNrPJsYk2GPIvELiQEDf2q/GMypd7hQFY5G Om41nukaJ3iG0uTBYllUJzDSPkMj8cKUkSjFQqtb/Rf+qHmUSE+LAxDoYazPcfJh sNpfj719wWwAH45kT6LT7Vfe2EshP13YxmSouuUBVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 31bec77c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:13 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/23] git: fix leaking argv when handling builtins 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 `handle_builtin()` we may end up creating an ad-hoc argv array in case we see that the command line contains the "--help" parameter. In this case we observe two memory leaks though: - We leak the `struct strvec` itself because we directly exit after calling `run_builtin()`, without bothering about any cleanups. - Even if we free'd that vector we'd end up leaking some of its strings because `run_builtin()` will modify the array. Plug both of these leaks. Signed-off-by: Patrick Steinhardt --- git.c | 22 +++++++++++++++++++--- t/t0012-help.sh | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/git.c b/git.c index 9a618a2740f..3c7fabfda26 100644 --- a/git.c +++ b/git.c @@ -711,6 +711,7 @@ static void strip_extension(const char **argv) static void handle_builtin(int argc, const char **argv) { struct strvec args = STRVEC_INIT; + const char **argv_copy = NULL; const char *cmd; struct cmd_struct *builtin; @@ -731,13 +732,28 @@ static void handle_builtin(int argc, const char **argv) } argc++; - argv = args.v; + + /* + * `run_builtin()` will modify the argv array, so we need to + * create a shallow copy such that we can free all of its + * strings. + */ + CALLOC_ARRAY(argv_copy, argc + 1); + COPY_ARRAY(argv_copy, args.v, argc); + + argv = argv_copy; } builtin = get_builtin(cmd); - if (builtin) - exit(run_builtin(builtin, argc, argv)); + if (builtin) { + int ret = run_builtin(builtin, argc, argv); + strvec_clear(&args); + free(argv_copy); + exit(ret); + } + strvec_clear(&args); + free(argv_copy); } static void execv_dashed_external(const char **argv) diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 1d273d91c21..9eae0d83563 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -2,6 +2,7 @@ test_description='help' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh configure_help () { From patchwork Mon Sep 16 11:45:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805332 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 CA5A61514FB for ; Mon, 16 Sep 2024 11:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487136; cv=none; b=GQ67OEiFn2eC6yU0iBwxNYcI/S9t5pQqZ/LnJbBwvj0QswhmsFB7NFabIIcpD505rVEzA2HZr9yYfDyZI6s7CD8pWyPCahvOEujqd67mkFf90Ovd5dZ/X6LGo7cz/8gr7JYfvSp9IpzN/cYf9z9F/muN1ZYVx42A3C9S2naZJ8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487136; c=relaxed/simple; bh=LLbz5IQ2Hpng9oCBhfL3oytcF3UIzuFiu7/vsHpy8yo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Fyj3nJwuxCyJ2E0YrXH1bowUvvvAygVD2i7OqX+o1xKx2eQyzlcfXlpDp/ROyJuRHVQ3jI74kCoCckOS5wvV+SiLJjGVKE2bpj2iKFTqv4CIaYm34OZz9P0hV2ew7qW9df0GEw7jgJv9AlN3aRSgQRjy+7EXfEdD9YDaVNXviPI= 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=CtNqBX/h; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=X/JIZWX/; arc=none smtp.client-ip=103.168.172.148 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="CtNqBX/h"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X/JIZWX/" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id D884113802DB for ; Mon, 16 Sep 2024 07:45:33 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 16 Sep 2024 07:45:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487133; x=1726573533; bh=4UlVmbcIU6 hlCZV36ZST1c4eY/CY3uuz7TalS6uIvLM=; b=CtNqBX/hoWmHRnBy4qzXu60310 AYazb/Us4YSI936HUTQ3+IUZBf4xIKUbZjTLSAUcKhmOPZ2q0zt6f9gXj3WYdRGz jHkRRM3GwZPAXMg+gTrcNepLS6TBiuS2zm9oUJnQo7SAe1LHmqAL5p/tvF2Wxdt7 D/MBkkW/JPsoQyamj7v9jzkiBo8ViNxyp5z0Co6k9GUSZ63HEy1akKp9Rt9h/PpB vrw9zAfWQkO9b5SgDedZsJfVXf9iVirLNcb2ko9ph685g76ML0qkGhEMIZfrgVil Mh16RldorHrsuqNKf02MUZ8EdMwNV0px10pV7aPbKGmJhXA3w+/MxqaI+jBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487133; x=1726573533; bh=4UlVmbcIU6hlCZV36ZST1c4eY/CY 3uuz7TalS6uIvLM=; b=X/JIZWX/CzmRakJtmZ8emScuz243oEDQDZeD81MvvvnK 9CY3nzxudvLnXSv85azjYBdpgqAcQaG5MEy87Fh8jvGRo6PsOd1iDBoSY3xstDOu fWN9ui9tE0EbKqXVq44mOf1JQUxFXVxm5tYTBxbRtwVaayG0M+vYVqeGiJ3EGkpR QvSxc6QfiLXAF5SlFrgO7kQPeWmN2tSGEtgWNDmdTJut7J/llj1cl5SIpQIKr/zO zSB0xxlksq+7UI/05lqwtvGXKnROQqOo+3YchnXDCX1VE9nWVa3Z/n+4EUKeL31k ZZB/Tm0pCfj9JqLlaOc+LYQPSLud9ZuYD0AU9yVqLw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:33 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d93791c6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:16 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/23] submodule: fix leaking update strategy Message-ID: <7cdd2691b77d328447855f898540f7efb2a415c3.1726484308.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're not freeing the submodule update strategy command. Provide a helper function that does this for us and call it in `update_data_release()`. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 1 + submodule-config.c | 2 +- submodule.c | 5 +++++ submodule.h | 6 ++++-- t/t7406-submodule-update.sh | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index bf8f9a40128..ed05dc51347 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2021,6 +2021,7 @@ struct update_data { static void update_data_release(struct update_data *ud) { free(ud->displaypath); + submodule_update_strategy_release(&ud->update_strategy); module_list_release(&ud->list); } diff --git a/submodule-config.c b/submodule-config.c index c8f2bb2bdd3..471637a725a 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -95,7 +95,7 @@ static void free_one_config(struct submodule_entry *entry) free((void *) entry->config->branch); free((void *) entry->config->url); free((void *) entry->config->ignore); - free((void *) entry->config->update_strategy.command); + submodule_update_strategy_release(&entry->config->update_strategy); free(entry->config); } diff --git a/submodule.c b/submodule.c index 97d0d47b561..0e67984d770 100644 --- a/submodule.c +++ b/submodule.c @@ -424,6 +424,11 @@ int parse_submodule_update_strategy(const char *value, return 0; } +void submodule_update_strategy_release(struct submodule_update_strategy *strategy) +{ + free((char *) strategy->command); +} + const char *submodule_update_type_to_string(enum submodule_update_type type) { switch (type) { diff --git a/submodule.h b/submodule.h index b50d29eba4f..4deb1b5f84e 100644 --- a/submodule.h +++ b/submodule.h @@ -41,6 +41,10 @@ struct submodule_update_strategy { .type = SM_UPDATE_UNSPECIFIED, \ } +int parse_submodule_update_strategy(const char *value, + struct submodule_update_strategy *dst); +void submodule_update_strategy_release(struct submodule_update_strategy *strategy); + int is_gitmodules_unmerged(struct index_state *istate); int is_writing_gitmodules_ok(void); int is_staging_gitmodules_ok(struct index_state *istate); @@ -70,8 +74,6 @@ void die_in_unpopulated_submodule(struct index_state *istate, void die_path_inside_submodule(struct index_state *istate, const struct pathspec *ps); enum submodule_update_type parse_submodule_update_type(const char *value); -int parse_submodule_update_strategy(const char *value, - struct submodule_update_strategy *dst); const char *submodule_update_type_to_string(enum submodule_update_type type); void handle_ignore_submodules_arg(struct diff_options *, const char *); void show_submodule_diff_summary(struct diff_options *o, const char *path, diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 297c6c3b5cc..0f0c86f9cb2 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -12,6 +12,7 @@ submodule and "git submodule update --rebase/--merge" does not detach the HEAD. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh From patchwork Mon Sep 16 11:45: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: 13805333 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 8FC112D047 for ; Mon, 16 Sep 2024 11:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487142; cv=none; b=pSTTAQ1K+5PxAR58xQXqw/XmNVpirm8Xu26i/TgcB4w9cHo9TzyLZ/GqvcVwLyKSmgNFM2geUs5RfCdEOzUFX3KoEJZJgf8HYEr3yR52fpZqq773+qSjPSEtUjCTFeZXHuetPoKfcsKU24BzmPwbk+sfL32B2QjM8T51+u5gzuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487142; c=relaxed/simple; bh=97W48CGMDgv2a9GS5XZ3bLlo9b8bpnNmuIxxtvoGxZU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dJPJfVd4bEM2stSoOvVDA2pTMpVF+4zzRa2ov5Akle+kIlx0AQpuBm+NZ478i5/rb5XEccrqseIA+hXHBVjiaoES0fxJ4I2fsc2JGz9xAwto2KCtWwtrVi3heEU/z+2sPiHnWSIfKNg8MMqSqShSBahSQv1rYz6UqdqKR+E8MZk= 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=CoIQS0en; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a81RIOb6; arc=none smtp.client-ip=103.168.172.153 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="CoIQS0en"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a81RIOb6" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id B3A9311401BA for ; Mon, 16 Sep 2024 07:45:39 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Mon, 16 Sep 2024 07:45:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487139; x=1726573539; bh=wCmmLvJQvb z2DUfOhHa3djTS8HsjYObJ6IHXjCm8jRI=; b=CoIQS0enV4//9QO+96k1+je79R o2m1ftDqPCN9iDHifGpBbZogYNZ3arub8IdBn3FHWZ3fFoXMUsPhIMIKApjW8+pZ WvZGjC+/NaNWaq0djT+G0lFLQq3g/HtnTMScGxK0NnKVmVLXBZjkUf44B79e/9rw dlwoIiPIk4ubqZgeGPF/8UWNuRRiR46dwksbCf+kJmw3Y4DPwXCkCYafuQ2JctrY DwA+R+w30XTc2q/B7KDOvO+9UojnUGVIQY3NSDHxrWREheII2Pflqgpxpoz6+Fkq bcw/FCeyiv/S8WLn9dP9m+oAN4koy1NARQr6T/HzlKv0ZdSvmPx7YlDmyl6w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487139; x=1726573539; bh=wCmmLvJQvbz2DUfOhHa3djTS8Hsj YObJ6IHXjCm8jRI=; b=a81RIOb6BIUO+FHyq6/pVgiOllBHldKQz8+HGKz7MlvK 7VzoSD9uEmLBxY9iwbyv/gESUomf1JxwUnf11Em/J2JCkwVWDp948yW98zItvq+k mYjdfS800u6i2KRphOikalWaVlLQ7o96spMzXdfyduoaB6RLgEX1hVxgqm30mQZg cz1OME/O+8kiiUUscdjILM7xWrzIb7JWIacf6v7YuKbvLyF10gxuV0QCD7NN6V4D GBJYcDF7q4N3uFJNW/dRCF4UdAtMwKpyuf8bfm+h7n1kT3425qd+VTdFlM/6idoB YiZiNayaIYbHuXi00p0YHQJf1WK2PCTiaHLSK/eymQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:39 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 59a1fab8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:22 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/23] builtin/submodule--helper: clear child process when not running it Message-ID: <0d0964a2bec7c6e6375a65a5ea9dc79a18ad325c.1726484308.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 `runcommand_in_submodule_cb()` we may end up not executing the child command when `argv` is empty. But we still populate the command with environment variables and other things, which needs cleanup. This leads to a memory leak because we do not call `finish_command()`. Fix this by clearing the child process when we don't execute it. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 10 +++++++--- t/t7407-submodule-foreach.sh | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ed05dc51347..fd1b6794083 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -363,9 +363,13 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, if (!info->quiet) printf(_("Entering '%s'\n"), displaypath); - if (info->argv[0] && run_command(&cp)) - die(_("run_command returned non-zero status for %s\n."), - displaypath); + if (info->argv[0]) { + if (run_command(&cp)) + die(_("run_command returned non-zero status for %s\n."), + displaypath); + } else { + child_process_clear(&cp); + } if (info->recursive) { struct child_process cpr = CHILD_PROCESS_INIT; diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh index 8d7b234beb8..9f688932613 100755 --- a/t/t7407-submodule-foreach.sh +++ b/t/t7407-submodule-foreach.sh @@ -12,6 +12,7 @@ that are currently checked out. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh From patchwork Mon Sep 16 11:45:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805334 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 8FE8F1553BC for ; Mon, 16 Sep 2024 11:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487145; cv=none; b=Ufjmfii0mPpeoWw0P0AuizSWYDHZOSgEPLoQ8VwRLzGdxDuTISjgGa82Jt13UvOOFgtu7uhBWAf0EOnbVbtL2TwmC2PYzWW2aI71wCd8DLu959herVsNJR4IJFBsdfN1oOpOgM5yK4cuNbay4kKrBt94XmYsUVRkUMnikokY4mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487145; c=relaxed/simple; bh=V3xCsOtXq0apgNpjQhNXAUfeqxLCAdHQmKpJ9fPAOPc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h/biAxAthJ6rwSvLohVrhYyggxaUm+O86zX2FyFSxyUJEBggFvIH09/Ivhesj6w/3QHao1g1VGc3H2K8XWCdQfeY6fw9ZBDC/wSMJGBSU5oWP7JJCHTBt7lRjqh+xGE8KEdCmUa5wulp2Lb3eyqP3ROzCnnQ5+FVoZs3cTXsmpY= 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=ptFjLQGl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fAnDfRZp; arc=none smtp.client-ip=103.168.172.153 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="ptFjLQGl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fAnDfRZp" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 95A971140125 for ; Mon, 16 Sep 2024 07:45:42 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 16 Sep 2024 07:45:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487142; x=1726573542; bh=EhH25wvAll yDxFvVFSgHZz9YLNgvS1jrUK44mwAFCks=; b=ptFjLQGlhVQvzbIbBIrwg+/L6w CFDil86Kk4Qst6PoHWZ99GpJR70f/sp610iodpfGa7dl5n2Wwswnuxo/m8ULrept NzPAl0p3SQEgXjhFWHTf0sCIXbKviomfxpuk9sYfbcl/ldlDUP4DyoIGc3n3IZ8n dCasnCu/9sqjQ0lwRNRyLjKQORLt2VuP1fBB4F/wGwFrhslv4UtA811wrzssH6/F Qwf8eulEStWQNpYNXVba1F3UeiiYWYZZxtDmEMoCD9o2EAtH2w7Ka4Ij7iu/38RF 3mtfPd92asYVjwQs91/HbyUb7pSI4jmOEXaX18l8fXD7s3gtpu3cs2DtVSmQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487142; x=1726573542; bh=EhH25wvAllyDxFvVFSgHZz9YLNgv S1jrUK44mwAFCks=; b=fAnDfRZpcDUp1igpkYTgrrpTF8vh+VPU03v2COZXM9k+ xijk2jRODSeCjMImkVa5VpRXLxCw9WvulaBTBzTKC2L//DJKqfLAkWFSZ+PEVI2P of9ZCHKjvgQ8nSPn1U/gRLwY0nLtURIWWCJfBGo4cz2FNigq49U9k0h7gJM/K12c Zj07w2iHh4jpZjd2ezvGNo3nA/p1qDg/jlnfEGdDmXGwxxxJ35rJSYsU/I/wbEUJ Pfzv0Z7+oIsmI0xcHIkGN19zc09BwUbsQPXgZVKXWo2oiqHaKUaHh++/IJm8Cuw2 WTM85x+bTgMbUb5vPEm2wxICacFMKICCRxUR8jvy7A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:41 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4da6ea18 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:24 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/23] builtin/submodule--helper: fix leaking error buffer Message-ID: <52d12e034b8104a0283958ada013b028322ce421.1726484308.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: Fix leaking error buffer when `compute_alternate_path()` fails. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 2 ++ t/t7408-submodule-reference.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fd1b6794083..ff1376f69fc 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1621,6 +1621,8 @@ static int add_possible_reference_from_superproject( ; /* nothing */ } } + + strbuf_release(&err); strbuf_release(&sb); } diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh index d6040e0a337..7e1afa9ce47 100755 --- a/t/t7408-submodule-reference.sh +++ b/t/t7408-submodule-reference.sh @@ -4,6 +4,8 @@ # test_description='test clone --reference' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh base_dir=$(pwd) From patchwork Mon Sep 16 11:45:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805335 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 6A59815665C for ; Mon, 16 Sep 2024 11:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487147; cv=none; b=U7UX6rZ1hh5WaILKEv7fHso4gybUe0bNgmiJtSg9hzmIiG4daFg3AfWed6jUnfrZIn7e51GK4W6e+LuOkDUqmXxQ7CuWjMNQd0bRwbnmzsEEnRS2PqrJUtuc+G2nXnj40QdfMGY4ZS4ARJb7ANip9gzfOVtOnZmjsj4sraKxSvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487147; c=relaxed/simple; bh=0OurXaQMJ31rwUl5M2EHfVQuEy32asu/nKouKXTGlGk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DD4ZUzXBWOq86W9hD7T+7hJFfq3T2JZ4biIuMh7+Fh+x4pEgJqd5R+p3zVrOzAvdYeaGMwYmbSZ9Ye79cwVU9/VaYpthc4QjL7OED2kkYkmC9E1Xp+MRakd/q44CfQQg34w+maciVE84urf+fVVZBsDou2dMGgRGdq6Fnmb2hlc= 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=ks0l/BTR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jJkbsz/D; arc=none smtp.client-ip=103.168.172.153 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="ks0l/BTR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jJkbsz/D" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7F5FB11401BA for ; Mon, 16 Sep 2024 07:45:45 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 16 Sep 2024 07:45:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487145; x=1726573545; bh=yXszzEAzbz Lh5WqgfJG7Gm3FqzZybYjKBbQaFH6Uo8A=; b=ks0l/BTRAlpuuZC0RrMowJItJO bc6uRP82HGRALKC5dnNjT4i03kX3ygdIKMp1u15xh6aJyZCNcFX5e0wyB/DuDH8o UeYJpEXe0LxooRtnMCeb+gs3+RUzv+ZCYcdsMYxuYxI0kIOSbPVGIO+VvRwomz6q 0dMAKqelNWCY/SgAlzFfpovwLsLZWKFjtrRruyVGV+xjofbruIu6skeXj2rqJl+J YiCcwaErM3G2OEhCHcxDE1R2BVQi614HCSyJ8jyTfO0kjrn5/RoyZdDOmLhNq/kS i9Ap/B3Zd4Py2jdSf4iE5Uc/udQshhQ7pDGjbWq4TATrA7+duoqMlBZ1s7ng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487145; x=1726573545; bh=yXszzEAzbzLh5WqgfJG7Gm3FqzZy bYjKBbQaFH6Uo8A=; b=jJkbsz/DNXhjj4kZ7KhrJheDsK9Zs21uqnPf7p+gvEfP d5cwXltS49tSk0IZ7oLYN1RB4o8Qpvg5KoTOWJWqzGK48ZjR1CckbG9YH2yVomrt vFVDB/ON/XKTUkxDgJqwnj/52z+KqkWlODavECsHOUiOCeyGhUrlukhgq38+Aamc APZZpyCqFNzbNEtsD38sfSCCkT+9u0paJk6e3MPjNWKQAfMhJWKQHUx4EMFjm1yB NvKdivSZ+AJDPm9qxBN+lTfhaiVUkYe7q2VbAGaY7OdbW7+vEHV5K048zEcbK9Vq Ba89UO+cU38tLoNJ4aHV/EkLmebqnxOKDHl9oylCxQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:44 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a3b1debc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:27 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/23] t/helper: fix leaking subrepo in nested submodule config helper Message-ID: <96bd7f01d5d1800a0d0520c0d790cc524e8b4c8c.1726484308.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 the "submodule-nested-repo-config" helper we create a submodule repository and print its configuration. We do not clear the repo, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- t/helper/test-submodule-nested-repo-config.c | 2 +- t/t7411-submodule-config.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c index 6ca069ce633..6dce9571531 100644 --- a/t/helper/test-submodule-nested-repo-config.c +++ b/t/helper/test-submodule-nested-repo-config.c @@ -29,6 +29,6 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv) print_config_from_gitmodules(&subrepo, argv[2]); submodule_free(the_repository); - + repo_clear(&subrepo); return 0; } diff --git a/t/t7411-submodule-config.sh b/t/t7411-submodule-config.sh index 31271f8e0a6..af0de496e07 100755 --- a/t/t7411-submodule-config.sh +++ b/t/t7411-submodule-config.sh @@ -10,6 +10,7 @@ from the database and from the worktree works. ' TEST_NO_CREATE_REPO=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Mon Sep 16 11:45:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805336 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 65CF0156669 for ; Mon, 16 Sep 2024 11:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487150; cv=none; b=fw5pcYvQJhACx2bgs2Ync8g4pI380MUzJYaik4hVw2NAQVMtJBVbA9EP6RM7uXyLPwML7MX5nMvxDUKr+kV/VcvEy2IpizKeaupHMp4sQDkXywzMgWy55V39w6L9qGbheGnPRhLm/GDCjXFwSEM1fC+RybWUBfeZJhI0ifKA7SI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487150; c=relaxed/simple; bh=e3g4VidDMiObT3hWMTmpg80MitqmqhQKOWyLj05S7z8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c94N4aTnDFxWf7Bz7K68An1I3dwdhi6IPL6rlWva8hCEZrzsbBc392CVSeGrGNLmGPWAdYAK29g8V0zIHGSeCnWQYz9IoFIgg0smUE9PvnXWIHwkNyiWgWApNFf4fahtADs5fRUkeyAylzwU57ibh+f+LsYhuT/w0vrqy/yA83k= 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=FTXunrRl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qxMRgsAU; arc=none smtp.client-ip=103.168.172.153 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="FTXunrRl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qxMRgsAU" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 73CBB114007D for ; Mon, 16 Sep 2024 07:45:48 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 16 Sep 2024 07:45:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487148; x=1726573548; bh=2R/0b3T8lc oKGTWVu1h3DXnqFc/k86Op4PNIQHs6LD0=; b=FTXunrRlnkOGIkfnbfeHFmJSZZ M7KklhrtskrP7Vs4YlU+Bph4VpVJ34Mhormepe9y+fXU+/C40lzp+GVgNsdxj0hy J0cDzHEghTvQOg/MOjdMNKTmbW3mQUTw/F3VPGS8EgHgkQlqTF0ud8flV5DeeL1D ZQcYQ184tshwQiCykWNdWBtIOJYEDGRXQt4ur2beTixFsueJx5SMEvcUUsCTqHub wABYcHA41R7jQ5A8ULsoQWXYXu/oDuDQXt3ODSdfFPdkHiZJwNBFEMTDs7+ftvGr gMHMUHxJgK0kL5hj3um4LBonGRB+ffvx10bEhh+qrXEY6DhpSU0CxZq3RIOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487148; x=1726573548; bh=2R/0b3T8lcoKGTWVu1h3DXnqFc/k 86Op4PNIQHs6LD0=; b=qxMRgsAUneyTuiwZDc4xay4bRjy8PUqzdmDlwIZpglgB X6jia8IqSVSNaxS1WCaK+O5JWNnH1pTCYdnFAb2+87u/NgcZjl96BubxxLxnsH7S vm4BOPhQdYyDCOHG5jFQT+3o6vr8ryAoOaHQf3CMQTjIB2Cf1j0yG1DGURO5tWat D35bRPS3a6kvElQF2VMSe13OUTQN3CAXzosQumyAWt9+MKJQo3tnZvCD/LTDa98y g+rGRO2ijRNmbULRb6x0ei3wL3KeBRYJEdH4BsM6bEKM5ggAAE+qNuvijYaT/Id2 lsloKVIklmb8+wCmcHZr2O3mRc2skldlay7N7EGQBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:47 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3ac1ffbc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:30 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:46 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/23] builtin/submodule--helper: fix leaking remote ref on errors 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 `update_submodule()` fails we return with `die_message()`. Curiously enough, this causes a memory leak because we use the `run_process_parallel()` interfaces here, which swap out the die routine. Fix the leak by freeing the remote ref. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 13 +++++++++---- t/t7420-submodule-set-url.sh | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ff1376f69fc..a9bd93a7856 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2648,15 +2648,20 @@ static int update_submodule(struct update_data *update_data) if (!update_data->nofetch) { if (fetch_in_submodule(update_data->sm_path, update_data->depth, - 0, NULL)) + 0, NULL)) { + free(remote_ref); return die_message(_("Unable to fetch in submodule path '%s'"), update_data->sm_path); + } } if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path, - remote_ref, &update_data->oid)) - return die_message(_("Unable to find %s revision in submodule path '%s'"), - remote_ref, update_data->sm_path); + remote_ref, &update_data->oid)) { + ret = die_message(_("Unable to find %s revision in submodule path '%s'"), + remote_ref, update_data->sm_path); + free(remote_ref); + return ret; + } free(remote_ref); } diff --git a/t/t7420-submodule-set-url.sh b/t/t7420-submodule-set-url.sh index bf7f15ee797..d7fe910bbe1 100755 --- a/t/t7420-submodule-set-url.sh +++ b/t/t7420-submodule-set-url.sh @@ -10,6 +10,7 @@ as expected. ' TEST_NO_CREATE_REPO=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Mon Sep 16 11:45: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: 13805337 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 527F015697A for ; Mon, 16 Sep 2024 11:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487152; cv=none; b=jfn4u0F4Gv771rHuouFCcPaNwhciTqQwy+45BgJxzCaCfLnazGZ2CRMN0mP8RFf50oUg5RqbTHU3eX02+c1zuyDurSCO5+2kV48agTHiqrNSZUgglx/6BJOfojIKk+PFihb3ZvBabu6MWPg9tIINNr/QhMAgONtSGz9esfMazPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487152; c=relaxed/simple; bh=v7JFcoOx0cYV0QIqK3dSorD0lv5CpaXjBg9RwRSkxlc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r9SKgJHTVvUrmF8mrSLxAktwXkVjOVWx98Vi3BX+QW26qLvtnOYN5x5LwsnM3L26TJgKlT1mrdP2KwGzbx3KxZ96GdTJB0R+7QuZhf3Jq2xUguomgS+odsE7oMlnOvPpapdfyibKrmd0BxaVAiZFEheVdvzbVuZNKG3MWAbhWiI= 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=qMUqJRC4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lQzH9kYo; arc=none smtp.client-ip=103.168.172.148 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="qMUqJRC4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lQzH9kYo" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 5DA5C13802DB for ; Mon, 16 Sep 2024 07:45:50 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 16 Sep 2024 07:45:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487150; x=1726573550; bh=lHFAlHgbhB lHEqBkSK1/tn+JLT1Jv3KU82uUrQkJm/I=; b=qMUqJRC4jpjY20/BtnCHg6qCLM /Ec/fF8NNBCsy6n52ZfO40CdYFDi7YpjDGWRUbNxdvJIf4qZXVml41gAdbcf9MVV xzeHAqqA1V4J3TaYFHDBRP8tOzMXV0k/VPQGmkgNg4Y7yqELjb9W9LO/B8Zt9OeL 7AC44OAIeU9hethrhUiWFRF5w/Oj992tx71SJ9EQiOQw+LxIWXP/D6Zzkos4FOVz IzyZtaWC3ewtiO06JDxdiBLTIPhM5na7ev5j0C8cWl+91gleKXA5ntCUP3P9bpD6 HpimtcCbo0HVZNoC+quvRebQ9FdkP2b4Jhve57NebfTaBQJ12rhsRez5lCYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487150; x=1726573550; bh=lHFAlHgbhBlHEqBkSK1/tn+JLT1J v3KU82uUrQkJm/I=; b=lQzH9kYoj5Ud3T6V+nWQvUWT1Gc0Ry6qrgBjjhjAZkt8 JtcZQoXpo0paQaDJWeY7jMUt2CEd3h6a4togvpq7xCRNXV+4ucDZYQdGUgWYPo/t 2uPPz1vllEfeh0S0Z9ekomoqB+mLf8xZObjSBqa9osqMW1aDhtjLQGcHGafylJIu O0SMWcsd7lqce05NhQMqybdd5o9crhwGA9E52V/W/urOdVq3zQoq/1f2+aV1ZW2g gdkPuJLVhU7u5F/XXQaop/UvHFQTw/r2AK8MQak2Ot+ktoUEkY0IMloVS0RL3E/e 0S44r0dGTck5YpWGdxnlpC8fDyM2oDVBqbIn+6uctA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:49 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b5977512 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:32 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/23] dir: fix off by one errors for ignored and untracked entries 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 `treat_directory()` we perform some logic to handle ignored and untracked entries. When populating a directory with entries we first save the current number of ignored/untracked entries and then populate new entries at the end of our arrays that keep track of those entries. When we figure out that all entries have been ignored/are untracked we then remove this tail of entries from those vectors again. But there is an off by one error in both paths that causes us to not free the first ignored and untracked entries, respectively. Fix these off-by-one errors to plug the resulting leak. While at it, massage the code a bit to match our modern code style. Signed-off-by: Patrick Steinhardt --- dir.c | 6 ++---- t/t3011-common-prefixes-and-directory-traversal.sh | 1 + t/t7061-wtstatus-ignore.sh | 1 + t/t7521-ignored-mode.sh | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dir.c b/dir.c index 5a23376bdae..787bcb7a1a4 100644 --- a/dir.c +++ b/dir.c @@ -2135,8 +2135,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir, */ state = path_none; } else { - int i; - for (i = old_ignored_nr + 1; iignored_nr; ++i) + for (int i = old_ignored_nr; i < dir->ignored_nr; i++) FREE_AND_NULL(dir->ignored[i]); dir->ignored_nr = old_ignored_nr; } @@ -2148,8 +2147,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir, */ if ((dir->flags & DIR_SHOW_IGNORED_TOO) && !(dir->flags & DIR_KEEP_UNTRACKED_CONTENTS)) { - int i; - for (i = old_untracked_nr + 1; inr; ++i) + for (int i = old_untracked_nr; i < dir->nr; i++) FREE_AND_NULL(dir->entries[i]); dir->nr = old_untracked_nr; } diff --git a/t/t3011-common-prefixes-and-directory-traversal.sh b/t/t3011-common-prefixes-and-directory-traversal.sh index 3da5b2b6e79..69e44c387fa 100755 --- a/t/t3011-common-prefixes-and-directory-traversal.sh +++ b/t/t3011-common-prefixes-and-directory-traversal.sh @@ -2,6 +2,7 @@ test_description='directory traversal handling, especially with common prefixes' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh index 2f9bea9793c..64145a05b1f 100755 --- a/t/t7061-wtstatus-ignore.sh +++ b/t/t7061-wtstatus-ignore.sh @@ -2,6 +2,7 @@ test_description='git-status ignored files' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >expected <<\EOF diff --git a/t/t7521-ignored-mode.sh b/t/t7521-ignored-mode.sh index a88b02b06ed..edce10f998e 100755 --- a/t/t7521-ignored-mode.sh +++ b/t/t7521-ignored-mode.sh @@ -2,6 +2,7 @@ test_description='git status ignored modes' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup initial commit and ignore file' ' From patchwork Mon Sep 16 11:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805338 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 27ED2156F3B for ; Mon, 16 Sep 2024 11:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487156; cv=none; b=QNP9tn1FDLDb8GO66LMu7ZpaV6XRP/+OQc7jAP6aRHpgb6f3ja6KdXjZDPnmXJcnr8NwFHE6etw7mQX5+9Xwz+EhVgidZpjkqsRATV0aEbBWg5+s54E7v6Z6cqtOqVGBpIAZSgPxByyaJtI8RM5rRYUEWgMKydjNK8J+EubEs2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487156; c=relaxed/simple; bh=RCVrddIgjR4AOmOSfVM+GFZLZ4PleHp0ku5SMo2pVxQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mcCbr8FcCnTlxFrZudcU6VSCY1JtdJP/xcu+OFzXlWnWMOZ4nMia84s3QgUNCxKZJPnCmLIBXzru1AMGmFuVyiIXZmJ3CBwB/r9BZEqFaqvHwg3FJ6/zl+ceNV36kAUvByrLlw8X5CgIQ4HfTduX1bdluPZL58yHYSSLbDUWhOM= 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=ChDhnD/F; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=npJr1gz8; arc=none smtp.client-ip=103.168.172.153 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="ChDhnD/F"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="npJr1gz8" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 412D211401BA for ; Mon, 16 Sep 2024 07:45:53 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 16 Sep 2024 07:45:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487153; x=1726573553; bh=JyZjmH7Kvm jlchaQDnNyypinjsHDYhtshZ+A3X8iJOw=; b=ChDhnD/F8sfQXdCKdBsv6XVFyH OT8ma4c7nF3wn14oTh8PLJ+MhrmxAl6Tc4+0RQ9DyHXvl8V9ZueQHAfbpK9fzu9h CIX5AhJ0ps/vPPdsASP+YbKEcwxomgyj7DS5Z0FYjockLUHLaV9lECPd19pS5d8x pqbFoGfmgYq+96tK1SasIvqPFNRcSxAJlgjsXPgitnCTIUzy63eagajemzxnADsb NhMOpypF8GIifRCIFvM+6CiS/uXAOjDYlCaVyrO20UG1A7fYTpmxMhifjB3wzRBo WEp/qqnzbeVQIuXTymLEaF2F/SiNouFmytktgkUfoqEJWqmYltSkwtFcBr6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487153; x=1726573553; bh=JyZjmH7KvmjlchaQDnNyypinjsHD YhtshZ+A3X8iJOw=; b=npJr1gz8IVW+DQy6FpGHIwObkDGF2j6aULsknUOBgDs+ e7Wmw8NaXiA4D2O8KhyopMYai+CVp1THDTyNVY4achZKC+r0h8I/vE83zu4UoUGu 9ibLZnC83uF3cy7VFM/RHfhqwM7EcVrHLTKX1+HWwL8DI53KLfN5oqHe3YbyVMia 1jMCl+BKaDJo8rv8f5s0jnfeVMTrW9VHXBE1ye6Zxr3iBhmMA/okS1DlQUOljf+H 8zsAJbOT+TNDM7NTtuols066hPjkmluTZn9KbuML8v4i9itJ+orMfYhCp4Rhuz1E tRl5gRlmptPPS76bMgrxYLSpFTMmzmNjyBEDgfwlVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4b16972d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:35 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/23] builtin/pull: fix leaking "ff" option Message-ID: <747c9a76a288d6fbfad85203e0bccaaf4b6db282.1726484308.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 `opt_ff` field gets populated either via `OPT_PASSTHRU` via `config_get_ff()` or when `--rebase` is passed. So we sometimes end up overriding the value in `opt_ff` with another value, but we do not free the old value, causing a memory leak. Adapt the type of the variable to be `char *` and consistently assign allocated strings to it such that we can easily free it when it is being overridden. Signed-off-by: Patrick Steinhardt --- builtin/pull.c | 11 +++++++---- t/t7601-merge-pull-config.sh | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 4c54d8196fa..5d9d9e467e5 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -84,7 +84,7 @@ static const char *opt_squash; static const char *opt_commit; static const char *opt_edit; static const char *cleanup_arg; -static const char *opt_ff; +static char *opt_ff; static const char *opt_verify_signatures; static const char *opt_verify; static int opt_autostash = -1; @@ -1024,8 +1024,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix) * "--rebase" can override a config setting of * pull.ff=only. */ - if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only")) - opt_ff = "--ff"; + if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only")) { + free(opt_ff); + opt_ff = xstrdup("--ff"); + } } if (opt_rebase < 0) @@ -1135,7 +1137,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (can_ff) { /* we can fast-forward this without invoking rebase */ - opt_ff = "--ff-only"; + free(opt_ff); + opt_ff = xstrdup("--ff-only"); ret = run_merge(); } else { ret = run_rebase(&newbase, &upstream); diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index a94387a75f2..7fd8c086af3 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -4,6 +4,7 @@ test_description='git merge Testing pull.* configuration parsing and other things.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Mon Sep 16 11:45:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805339 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 173F6156250 for ; Mon, 16 Sep 2024 11:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487160; cv=none; b=SeA4OGJcFez8UHjvejU7mPYVGjt2DCe9FA+HikeKAqiENWfEYvJobS2vlotidRQzFL7mtT7IqvZe7w5SsA3ZkIKOCOCSx3e5oLYdJo4X8iAwnh/rYeqOH/hgaXUPuKj9TZc+z90NNKQLt/xq+tMtYB3XV2lJze8X+MYjyGCR2yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487160; c=relaxed/simple; bh=GeSU4ZXtpv1wE7aP0bu80NfK5GtkljPO7rmvLXvo6A4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U3vjWEz+tokHHFCEPyf2qFDIQCRnq5Q5RGG8yx/pb78YM37L8mx0et9LG4HQOhVxi0ssnqFPJe+vP4JZkrRsvAwdlyA7nCN2Z3JcGitni67SP2cX5fCV2oaClFaHPjK+eelKScyPGThH2n3GmJxXaU22Gc5GOJXoRBTmxB7XKRs= 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=RjvX76/f; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lM+5ku6f; arc=none smtp.client-ip=103.168.172.148 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="RjvX76/f"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lM+5ku6f" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 276471380258 for ; Mon, 16 Sep 2024 07:45:58 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 16 Sep 2024 07:45:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487158; x=1726573558; bh=pblU4lesaa WgHNcH9w96hXIDioD0VC5WLspgVWRhBOY=; b=RjvX76/fXrERMW29u8F6hB9TXc ptb8GQdHnw3EuA51j8YwMATO5t4ZHfkxl0Q4ih/9oiYxuEzO1+wPV9c1iwK/U/sb mCE7Z0bzcQMr5m6hYgdH2mS7PfX7KdqjHVst9K0be3ynKzS4iDhx5Y5xiXRLlZbM iZGS97fs/Qymml5DZ3pzjc2Ia/5h9RRy4EmlI0mcWsiEnB5epxAmpXpvNOQlLfs2 bgeF8gNTln+/yMBNGaetL7qWSIwaPZTzgnD9wxYjRRzm2s+1bgc4WdcZpYYAx76u FJqqR3XESWqvyN2I6S31jzjmE+7bvMR9l0zYG1p4XDExFd/AbIr5QkKBp4+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487158; x=1726573558; bh=pblU4lesaaWgHNcH9w96hXIDioD0 VC5WLspgVWRhBOY=; b=lM+5ku6fENGLg8hFok5ICCEFhJUCMJnEX3lhryulnjts P06TpmgUu3s6gXpcuMPwRgEoybiIcLatHBxv+KvgohlDfvIiAhOwpXLFt6hWgp6b 63h0xS3yAJFD/N+xieRwpJpIj+HYFicqo+F16Q2hDEj+vUiFRCLb11n7sVQWj/o4 bF40wjSnkX8xEYcqEaZcw5GxFQ2gAwoAP0baYOq3CDlbo5s9JeZa/4YL2mcnSF7o BBcbN5Amawz3EbdWRMd6D/QfjrWXQS9pZ6rJWDGl0uutAolUTjn72rZmx7Icia+P mD37+YlBmhqkaUnPPCnuTE3FD6PzIYA7Nav45qxc7A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:45:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1902229b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:40 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/23] diff: fix leaking orderfile option Message-ID: <85c0f9e5f598cc65d1c03f6622900bb950a31159.1726484308.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 `orderfile` diff option is being assigned via `OPT_FILENAME()`, which assigns an allocated string to the variable. We never free it though, causing a memory leak. Change the type of the string to `char *` and free it to plug the leak. This also requires us to use `xstrdup()` to assign the global config to it in case it is set. This leak is being hit in t7621, but plugging it alone does not make the test suite pass. Signed-off-by: Patrick Steinhardt --- combine-diff.c | 3 +-- diff.c | 7 +++++-- diff.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 829a44e4167..f6b624dc288 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1393,9 +1393,8 @@ static struct combine_diff_path *find_paths_generic(const struct object_id *oid, { struct combine_diff_path *paths = NULL; int i, num_parent = parents->nr; - int output_format = opt->output_format; - const char *orderfile = opt->orderfile; + char *orderfile = opt->orderfile; opt->output_format = DIFF_FORMAT_NO_OUTPUT; /* tell diff_tree to emit paths in sorted (=tree) order */ diff --git a/diff.c b/diff.c index 472479eb101..6555b8a32c1 100644 --- a/diff.c +++ b/diff.c @@ -441,8 +441,10 @@ int git_diff_ui_config(const char *var, const char *value, } if (!strcmp(var, "diff.wordregex")) return git_config_string(&diff_word_regex_cfg, var, value); - if (!strcmp(var, "diff.orderfile")) + if (!strcmp(var, "diff.orderfile")) { + FREE_AND_NULL(diff_order_file_cfg); return git_config_pathname(&diff_order_file_cfg, var, value); + } if (!strcmp(var, "diff.ignoresubmodules")) { if (!value) @@ -4775,7 +4777,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options) if (diff_indent_heuristic) DIFF_XDL_SET(options, INDENT_HEURISTIC); - options->orderfile = diff_order_file_cfg; + options->orderfile = xstrdup_or_null(diff_order_file_cfg); if (!options->flags.ignore_submodule_set) options->flags.ignore_untracked_in_submodules = 1; @@ -6727,6 +6729,7 @@ void diff_free(struct diff_options *options) FREE_AND_NULL(options->objfind); } + FREE_AND_NULL(options->orderfile); for (size_t i = 0; i < options->anchors_nr; i++) free(options->anchors[i]); FREE_AND_NULL(options->anchors); diff --git a/diff.h b/diff.h index 9901c8ca8c8..b95d3c1e830 100644 --- a/diff.h +++ b/diff.h @@ -235,7 +235,7 @@ enum diff_submodule_format { * diffcore library with. */ struct diff_options { - const char *orderfile; + char *orderfile; /* * "--rotate-to=" would start showing at and when From patchwork Mon Sep 16 11:45: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: 13805340 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 072ED157469 for ; Mon, 16 Sep 2024 11:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487163; cv=none; b=broYpvY+vaR7c9AgVn6qg2UuOd/8PFfEPaGeJuLctpQgGwfNNt0v5nnjmpCxPTazVwmmu96YnppnlPsQV4OGWCH+0noxs4H9q/cCN+D0RL590Y46xmJrdSYAD6uZDT0GhJbbJF+4o+dG0IAU99Bu47YhCAWiS4lD3EUEmnu+atU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487163; c=relaxed/simple; bh=nfgtXQhLoByL0Kya3WgGCHW1r8a3zL8Ja8SZ+nXoLN0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WEZEDrEbnYdJqkfkUurCA6l3U0PFt07twcRGGZ0gk0Wqs0Fi5QLlQ6FR+0mOuk0t1Sdn1EcYi2oLpvec0rWdGyikNRH1LJ4Zo/AlH8bqKLnWpfFe5RJyTmUGES89AAMMYDGnblWtkBU1JsGYA9Gs0kA8PNFEUrhMAb2TmUS7U8M= 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=BgiTqZSj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ai2INHjI; arc=none smtp.client-ip=103.168.172.153 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="BgiTqZSj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ai2INHjI" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 12ADE114023E for ; Mon, 16 Sep 2024 07:46:01 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 16 Sep 2024 07:46:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487161; x=1726573561; bh=zp2kMQQ97T frUpfJ5oYHVkDFmvwcTdJD/YWn185ZEpg=; b=BgiTqZSjQ4//wD+gXZNgaYrXXQ F218eVtIzvSYX7GVL+RLCMStHl/Sut6SaZwStQSQiiKbyf2xF4ko+kwvpq+mNj25 NIdgjZfIRLECDLk4ulTHU2AbVjxBYh+nMYhw9bRmSgV5WLHF3l4xi4N8lx6LLv/0 cxm/XSdc5KRLrRTKi5xqnC55fHk0VY2yA/NxcysR8AufEidMqhBNSDtSfUZZBrR2 5OBPbhBIp/mqTxbNw3Yu3uKdKyCd3ANA4fJp747hIlQX1iBcPfEl97jxtAtHZl83 w/RJ9dvdOBLCJMPcXBWbw0UgGlzl9VvBlU/miARSu70zQ6Xnp+D42tjGEZZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487161; x=1726573561; bh=zp2kMQQ97TfrUpfJ5oYHVkDFmvwc TdJD/YWn185ZEpg=; b=Ai2INHjIl7We6N9w0j5V92euGl6tixwtR5xrswWoLRpc vwyAUiQnvZ2TeB9MWP16sVASjoCZLpeP1AtZtEw8rwflffrVTfUnYZc2eIN+bOFH cb2DEH74wOXcaJPXxNkeBrNisUKHbLVbNYa5VHHIM1yrfsqGzo5SYcTyEBl05r40 2PElT5qgznBxAemOnp5PN3OfDd7+WZBbhOs75Edx/swpZCskuoFa4ZJfuXXc8WMK noHfhZuPmpn8sa8AF08WoQIXn8vK/RcCWqFl5By3aFRqf2SgTo2XuJxiYPC81Wcv 2DcrFaqiQOMs/73xFweBemy8F7pxB6H7SJ3c3vI8YA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:00 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8b3dee57 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:43 +0000 (UTC) Date: Mon, 16 Sep 2024 13:45:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/23] parse-options: free previous value of `OPTION_FILENAME` Message-ID: <330b6c52a0a99ba8fa18378310250e5b617d40c2.1726484308.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 `OPTION_FILENAME` option always assigns either an allocated string or `NULL` to the value. In case it is passed multiple times it does not know to free the previous value though, which causes a memory leak. Refactor the function to always free the previous value. None of the sites where this option is used pass a string constant, so this change is safe. While at it, fix the argument of `fix_filename()` to be a string constant. The only reason why it's not is because we use it as an in-out-parameter, where the input is a constant and the output is not. This is weird and unnecessary, as we can just return the result instead of using the parameter for this. This leak is being hit in t7621, but plugging it alone does not make the test suite pass. Signed-off-by: Patrick Steinhardt --- parse-options.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/parse-options.c b/parse-options.c index 30b9e68f8ac..33bfba0ed4a 100644 --- a/parse-options.c +++ b/parse-options.c @@ -60,12 +60,12 @@ static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p, return 0; } -static void fix_filename(const char *prefix, char **file) +static char *fix_filename(const char *prefix, const char *file) { if (!file || !*file) - ; /* leave as NULL */ + return NULL; else - *file = prefix_filename_except_for_dash(prefix, *file); + return prefix_filename_except_for_dash(prefix, file); } static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p, @@ -129,18 +129,24 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p, return 0; case OPTION_FILENAME: + { + const char *value; + + FREE_AND_NULL(*(char **)opt->value); + err = 0; + if (unset) - *(const char **)opt->value = NULL; + value = NULL; else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) - *(const char **)opt->value = (const char *)opt->defval; + value = (const char *) opt->defval; else - err = get_arg(p, opt, flags, (const char **)opt->value); + err = get_arg(p, opt, flags, &value); if (!err) - fix_filename(p->prefix, (char **)opt->value); + *(char **)opt->value = fix_filename(p->prefix, value); return err; - + } case OPTION_CALLBACK: { const char *p_arg = NULL; From patchwork Mon Sep 16 11:46: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: 13805341 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 CF848157476 for ; Mon, 16 Sep 2024 11:46:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487166; cv=none; b=DV+U003/YKWgDpHSodcajGTpYYiJlHoqnKaFm9tpQtyzs96WXcqF/3DCEnC8hi/DZbW9ESF4O7O3yyJyKqsAObCwgTzkz+Fkz2ZJcRKrLWmzPfX1id052yJzDMOXRjNm2UAx+FChBeLAJjOz8GhqkDAj7j42WeCb1W0RXMxbDNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487166; c=relaxed/simple; bh=qBEPRQvlxemZhQvyWNjTgnneRAZSg3GbNnrKOGmRMro=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=swVWUA1IoMRiWRCvbVZDwYaZcQqUx4trOmEUCRyLO/zAEFKozwkttjk2riwlrCjaFs0Os+o/B0TPHe07nqIAv0VSbXKBkT3lg+yEKDV5RALGx68sRarAYjZQ2Z/3GH9fx5Js0EuXKql+s03kGJZ96bHu8f+kZ2AL0CHYOCGHLo0= 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=kM+CmYAN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jhI/Ri7i; arc=none smtp.client-ip=103.168.172.148 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="kM+CmYAN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jhI/Ri7i" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id E28FD13802D9 for ; Mon, 16 Sep 2024 07:46:03 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 16 Sep 2024 07:46:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487163; x=1726573563; bh=iZCyIkM3+c DWiX1gyqpos3rXPi080AUguuyvKb/GWQA=; b=kM+CmYANaFoMiC/twG/9cCS0Nr naUTethv8TN6z1bErHXMYR5Bin6sosfD3P1+ny6piKOSNoDubiERAr8k9mwVRY+j wXKBrwKZMs5brgJut53DnUgvjUUBbhouXAydJXCJT2cxbxSVY36vXmrswQkodkZu kFChZIs9J/iuaJXo0mCOYeHDHutouoi0qnCmz0nRciESTtPra4p8Y51OqEZh5UDg Fd0LKuD+rLKfrRCeyPHGXlDQ+JL1F+NjkaFzvD79gQJPk5SHuHzt1KtAm6Q0WsT1 hSVDkwltDxccbSZiVHxgIebLxoomrVeDGatvvckEOivimveMlL45/nYDbHaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487163; x=1726573563; bh=iZCyIkM3+cDWiX1gyqpos3rXPi08 0AUguuyvKb/GWQA=; b=jhI/Ri7iB2fxIkaZfYs246m6YHFfxRG45ASJAEd/ppqE +ZaZkW+zL/O+3HXwJK9dTDfF/Y/SdaC6545cD0+CWXUAZVE9CjdTsMGHDv5iQUkf TryNV0eXbhfRYDf+xfEV/Z3jjtHjhRpJzHi8+EwSfItgmaQZ32awfSlyyloJ0unA XZRHt6wnKsiMKjbkImFtptmzwX4jJb5MsjUAg31LORWwLRJgsGCC/Io75h41fv2o 9cZ6mCqlZXpYI1UTaG2UAZUejC6ZyNV8+wrb2Eik+9wgnaMeTBFFgiDMqLpLyTpK X2LemWyQA9EgkgoW29iqXd77g17MqkawIwHhX16+WA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:03 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4697787f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:45 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 13/23] diffcore-order: fix leaking buffer when parsing orderfiles 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 `prepare_order()` we parse an orderfile and assign it to a global array. In order to save on some allocations, we replace newlines with NUL characters and then assign pointers into the allocated buffer to that array. This can cause the buffer to be completely unreferenced though in some cases, e.g. because the order file is empty or because we had to use `xmemdupz()` to copy the lines instead of NUL-terminating them. Refactor the code to always `xmemdupz()` the strings. This is a bit simpler, and it is rather unlikely that saving a handful of allocations really matters. This allows us to release the string buffer and thus plug the memory leak. Signed-off-by: Patrick Steinhardt --- diffcore-order.c | 19 +++++++------------ t/t4056-diff-order.sh | 1 + t/t4204-patch-id.sh | 1 + 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/diffcore-order.c b/diffcore-order.c index e7d20ebd2d1..912513d3e67 100644 --- a/diffcore-order.c +++ b/diffcore-order.c @@ -14,8 +14,7 @@ static void prepare_order(const char *orderfile) { int cnt, pass; struct strbuf sb = STRBUF_INIT; - void *map; - char *cp, *endp; + const char *cp, *endp; ssize_t sz; if (order) @@ -24,14 +23,13 @@ static void prepare_order(const char *orderfile) sz = strbuf_read_file(&sb, orderfile, 0); if (sz < 0) die_errno(_("failed to read orderfile '%s'"), orderfile); - map = strbuf_detach(&sb, NULL); - endp = (char *) map + sz; + endp = sb.buf + sz; for (pass = 0; pass < 2; pass++) { cnt = 0; - cp = map; + cp = sb.buf; while (cp < endp) { - char *ep; + const char *ep; for (ep = cp; ep < endp && *ep != '\n'; ep++) ; /* cp to ep has one line */ @@ -40,12 +38,7 @@ static void prepare_order(const char *orderfile) else if (pass == 0) cnt++; else { - if (*ep == '\n') { - *ep = 0; - order[cnt] = cp; - } else { - order[cnt] = xmemdupz(cp, ep - cp); - } + order[cnt] = xmemdupz(cp, ep - cp); cnt++; } if (ep < endp) @@ -57,6 +50,8 @@ static void prepare_order(const char *orderfile) ALLOC_ARRAY(order, cnt); } } + + strbuf_release(&sb); } static int match_order(const char *path) diff --git a/t/t4056-diff-order.sh b/t/t4056-diff-order.sh index aec1d9d1b42..32c5fcb9a27 100755 --- a/t/t4056-diff-order.sh +++ b/t/t4056-diff-order.sh @@ -5,6 +5,7 @@ test_description='diff order & rotate' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh create_files () { diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh index dc8ddb10aff..c0a4a02dcfa 100755 --- a/t/t4204-patch-id.sh +++ b/t/t4204-patch-id.sh @@ -5,6 +5,7 @@ test_description='git patch-id' 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' ' From patchwork Mon Sep 16 11:46:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805342 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 693A115748E for ; Mon, 16 Sep 2024 11:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487169; cv=none; b=G3elH8h9Vp41AP0KP+vS5eHNExAF3A1zrnuCGhl0aVoeEeI4HdplQy3EIcPeLJwthCPn9P92GCr0YAAko1fhIGR3ZepBKTF2tHtlT41UmR0XG1sVAuD3gzqW+PD4TKvOry+8Hhh01lncRidx4wbeZxpaXjSJ6ZaARVOE1P+0oTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487169; c=relaxed/simple; bh=G0zgYrJB0LAi1lAySopPWetK/R6ObdC8dF9cl7yOzY0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OS9Hxl0jxRv6oyiag6F7cZ5JTBYrBN08GhuiNcfq0abFhAo9NNOF7llcgyQSB8xBWpBlvSn9k6sIflBoo7nECtQTfIP2gjfwVklLibqee3ve/ej6OGI4j8cO0rnGxTLlBdFIQwEE6BEvgDEaNXePHBPprmX1DUkKZ1+juFzuubc= 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=NDUQhbAN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z27+Y57t; arc=none smtp.client-ip=103.168.172.153 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="NDUQhbAN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z27+Y57t" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id C3C74114023B for ; Mon, 16 Sep 2024 07:46:06 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 16 Sep 2024 07:46:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487166; x=1726573566; bh=1ZJfGtzqvt yzJWnZb6VOnIb94WGnF7Sluf2NKzaMnhc=; b=NDUQhbANXTNRN8Sope2KrNWRBH RB+SEBxxWbw/veWts+0eNGzZJzkNoBIjf+eioTaTB7Pm2URRRw75v46Be6SxQ3/1 acTT/ZFFmuibjDR+kOsRYV18VnnIndjEzrY9Uq8SVdMta+bZBB2omevbj+QsdXv9 XsN4vP3luA6X5W7NE5fyu81o7gzvJ+Yh+VBU3fyCqYI3e3L/9JBP3X6TH/CsDkN6 aDYn2rdjIttIeOZctXPmt5XqAPFR7IaEJ0JQjunI6ELOKh2ZLjCmcJ/9JYDA7gBf Hkp/MLW5ZmErYTGG6ue8yljYnplpDDd9jrO/18Im4PZLW0ld3i3eol+RbzWQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487166; x=1726573566; bh=1ZJfGtzqvtyzJWnZb6VOnIb94WGn F7Sluf2NKzaMnhc=; b=Z27+Y57tcW2MjfKMAYos4+TSLZq84PRlV6COjGCRlk5U 7D2+KfE4HLTF5hppcun7BIe1TfwstESzhl4uD2+8LEVKkv40oXSHLbHZ4R4e71jB OSmt5sy20aCpsfa3QZFDe2ij9IwRebQ4ZVSfc+uO7sA/VDjJulxKiHFv0ZOg8SI3 v1UnoGjGW+JXEck/t9x16kLnPcPUIA8nu35KXThs1nR+NuswiwSQzmW1rQwxHK/Y 93VSk4i+tVP6DDUy5uuHm6ydUYnEKnpZ8xVgEWAk/LdtDgk5gXYnpCNsdKpH+jCg 7o7WYyfIir/TnGfjSfPiS0AenWTY/7CLGCO+2qIAUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 340d54ae (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:48 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 14/23] builtin/repack: fix leaking configuration 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 repacking, we assemble git-pack-objects(1) arguments both for the "normal" pack and for the cruft pack. This configuration gets populated with a bunch of `OPT_PASSTHRU` options that we end up passing to the child process. These options are allocated, but never free'd. Create a new `pack_objects_args_release()` function that releases the memory for us and call it for both sets of options. Signed-off-by: Patrick Steinhardt --- builtin/repack.c | 57 ++++++++++++++++++++++++++--------- t/t5329-pack-objects-cruft.sh | 2 ++ t/t7700-repack.sh | 1 + 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index 3ee8cfa732f..c31d5653f1f 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -85,17 +85,34 @@ static int repack_config(const char *var, const char *value, run_update_server_info = git_config_bool(var, value); return 0; } - if (!strcmp(var, "repack.cruftwindow")) + if (!strcmp(var, "repack.cruftwindow")) { + free(cruft_po_args->window); return git_config_string(&cruft_po_args->window, var, value); - if (!strcmp(var, "repack.cruftwindowmemory")) + } + if (!strcmp(var, "repack.cruftwindowmemory")) { + free(cruft_po_args->window_memory); return git_config_string(&cruft_po_args->window_memory, var, value); - if (!strcmp(var, "repack.cruftdepth")) + } + if (!strcmp(var, "repack.cruftdepth")) { + free(cruft_po_args->depth); return git_config_string(&cruft_po_args->depth, var, value); - if (!strcmp(var, "repack.cruftthreads")) + } + if (!strcmp(var, "repack.cruftthreads")) { + free(cruft_po_args->threads); return git_config_string(&cruft_po_args->threads, var, value); + } return git_default_config(var, value, ctx, cb); } +static void pack_objects_args_release(struct pack_objects_args *args) +{ + free(args->window); + free(args->window_memory); + free(args->depth); + free(args->threads); + list_objects_filter_release(&args->filter_options); +} + struct existing_packs { struct string_list kept_packs; struct string_list non_kept_packs; @@ -1152,12 +1169,16 @@ int cmd_repack(int argc, const char **argv, const char *prefix) const char *unpack_unreachable = NULL; int keep_unreachable = 0; struct string_list keep_pack_list = STRING_LIST_INIT_NODUP; - struct pack_objects_args po_args = {NULL}; - struct pack_objects_args cruft_po_args = {NULL}; + struct pack_objects_args po_args = { 0 }; + struct pack_objects_args cruft_po_args = { 0 }; int write_midx = 0; const char *cruft_expiration = NULL; const char *expire_to = NULL; const char *filter_to = NULL; + const char *opt_window = NULL; + const char *opt_window_memory = NULL; + const char *opt_depth = NULL; + const char *opt_threads = NULL; struct option builtin_repack_options[] = { OPT_BIT('a', NULL, &pack_everything, @@ -1191,13 +1212,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix) N_("with -A, do not loosen objects older than this")), OPT_BOOL('k', "keep-unreachable", &keep_unreachable, N_("with -a, repack unreachable objects")), - OPT_STRING(0, "window", &po_args.window, N_("n"), + OPT_STRING(0, "window", &opt_window, N_("n"), N_("size of the window used for delta compression")), - OPT_STRING(0, "window-memory", &po_args.window_memory, N_("bytes"), + OPT_STRING(0, "window-memory", &opt_window_memory, N_("bytes"), N_("same as the above, but limit memory size instead of entries count")), - OPT_STRING(0, "depth", &po_args.depth, N_("n"), + OPT_STRING(0, "depth", &opt_depth, N_("n"), N_("limits the maximum delta depth")), - OPT_STRING(0, "threads", &po_args.threads, N_("n"), + OPT_STRING(0, "threads", &opt_threads, N_("n"), N_("limits the maximum number of threads")), OPT_MAGNITUDE(0, "max-pack-size", &po_args.max_pack_size, N_("maximum size of each packfile")), @@ -1224,6 +1245,11 @@ int cmd_repack(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, builtin_repack_options, git_repack_usage, 0); + po_args.window = xstrdup_or_null(opt_window); + po_args.window_memory = xstrdup_or_null(opt_window_memory); + po_args.depth = xstrdup_or_null(opt_depth); + po_args.threads = xstrdup_or_null(opt_threads); + if (delete_redundant && repository_format_precious_objects) die(_("cannot delete packs in a precious-objects repo")); @@ -1389,13 +1415,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix) const char *pack_prefix = find_pack_prefix(packdir, packtmp); if (!cruft_po_args.window) - cruft_po_args.window = po_args.window; + cruft_po_args.window = xstrdup_or_null(po_args.window); if (!cruft_po_args.window_memory) - cruft_po_args.window_memory = po_args.window_memory; + cruft_po_args.window_memory = xstrdup_or_null(po_args.window_memory); if (!cruft_po_args.depth) - cruft_po_args.depth = po_args.depth; + cruft_po_args.depth = xstrdup_or_null(po_args.depth); if (!cruft_po_args.threads) - cruft_po_args.threads = po_args.threads; + cruft_po_args.threads = xstrdup_or_null(po_args.threads); if (!cruft_po_args.max_pack_size) cruft_po_args.max_pack_size = po_args.max_pack_size; @@ -1547,7 +1573,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix) string_list_clear(&names, 1); existing_packs_release(&existing); free_pack_geometry(&geometry); - list_objects_filter_release(&po_args.filter_options); + pack_objects_args_release(&po_args); + pack_objects_args_release(&cruft_po_args); return ret; } diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh index fc5fedbe9b0..445739d06c9 100755 --- a/t/t5329-pack-objects-cruft.sh +++ b/t/t5329-pack-objects-cruft.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='cruft pack related pack-objects tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh objdir=.git/objects diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index be1188e7365..c4c3d1a15d9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -2,6 +2,7 @@ test_description='git repack works correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "${TEST_DIRECTORY}/lib-bitmap.sh" . "${TEST_DIRECTORY}/lib-midx.sh" From patchwork Mon Sep 16 11:46: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: 13805343 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 9ABB8157476 for ; Mon, 16 Sep 2024 11:46:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487171; cv=none; b=Q5LUtD0RJb12/dQf7twRPfpKfImrUwfNBk7E8k6tmL5cYRZ9ndCMnL/UeGHoUxmZ4YOBKhwVuMMEf76oIjxa0K0EKbY58SPVZggX9bZgzjINc2D/5Vr4rhj2XDnvnGMRETOGRgRACZ0nzPaVby/0ri/wv73ALEolCzXfSUMpf+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487171; c=relaxed/simple; bh=3+yNKQw1w9E9FTISRrFs/Falu4Othrcghak8m/MyEQc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WQ5VJ+S+ntawDwovRXkunVzlkP5mSJM9gbOF9CjRloZpiFYeE/hN0jP/xS7ADmApXpCRkLW47ettdA2SGIMRD7BGJH0PrULi+xIfBDm5dEy2NT9qD6KnBRgZZX4rpFdeNyvEj6EYzWfG4kUlY/7mySQkHnEjGZVJ/NpyDcwcZd8= 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=MvYdvTsy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XDDfMLlD; arc=none smtp.client-ip=103.168.172.153 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="MvYdvTsy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XDDfMLlD" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id B2E17114007D for ; Mon, 16 Sep 2024 07:46:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 16 Sep 2024 07:46:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487168; x=1726573568; bh=M5bnu8rJ3B wQ05XHmI91cca2PD0JkumNfKQcMxWY1yU=; b=MvYdvTsyew6AJvetvL4zhPlfaF YNPaxOlGb8ifaYhBjqHiPr1cHDc3EBanqkpIAK2jHL8VbjvoxPWX+HhQgECAL25D MC81ZsfzmWr9Q59clK8pcMD+dbRsTqN47F5F06xKy6IPXB3+uy1GDs+NxLp/1rxM pmy8EpVnejeFTlDImm1hiz3bITXxqG8hNR/EaKGf+gptMkb3YhSDyH40Km3DcbM5 mBZOI2ljYngXaNjzGe0jBR9LOIj/byrRjL6yle6tgI/k8jgudKwJA8dFUzKpz3aJ pmw0ycRhkhPXDeS6DX5Fp08T1quRUBSrZ28X+WuRToyq3veLDPPososD0VpQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487168; x=1726573568; bh=M5bnu8rJ3BwQ05XHmI91cca2PD0J kumNfKQcMxWY1yU=; b=XDDfMLlDWaIpD/7xoalE4FZ009DU1gX1VvExKaIzYZ5o 5pUXecdgXT+QPZmn0hyBks/yG+SzgR4ajy1GjzhNtK00dIAMpu14vjVTneJPgPt1 3sSLSfe1UtwqFCDr1FJH2iYw70O3/s/9KdQaYcISjQVuiCcbOso0it3O2XPAhsE8 Mzg0IhI7TxtaMy4oM1jJQmPkMqKmQ/FA6/GgvF0RQpOVQuIO623mSN4APyC2dQY1 0694YxdkDnDttP2yoXx76KcmFaTXWY9wvtNEPAOKFFxXtp7Be8dWiS3D3HEAVv9Y a95BZQwmGEjH378y2s9CbTbgMb0Nid1NTciiYqkfkQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:07 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0db8af92 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:51 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 15/23] builtin/difftool: plug several trivial memory leaks Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are several leaking data structures in git-difftool(1). Plug them. Signed-off-by: Patrick Steinhardt --- builtin/difftool.c | 6 ++++++ t/t7800-difftool.sh | 1 + 2 files changed, 7 insertions(+) diff --git a/builtin/difftool.c b/builtin/difftool.c index dcc68e190c2..1a68ab66993 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -660,6 +660,12 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, if (fp) fclose(fp); + hashmap_clear_and_free(&working_tree_dups, struct working_tree_entry, entry); + hashmap_clear_and_free(&wt_modified, struct path_entry, entry); + hashmap_clear_and_free(&tmp_modified, struct path_entry, entry); + hashmap_clear_and_free(&submodules, struct pair_entry, entry); + hashmap_clear_and_free(&symlinks2, struct pair_entry, entry); + release_index(&wtindex); free(lbase_dir); free(rbase_dir); strbuf_release(&info); diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index cc917b257e3..f67b9345b8a 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -11,6 +11,7 @@ Testing basic diff tool invocation GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh difftool_test_setup () From patchwork Mon Sep 16 11:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805344 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 75A7A157A67 for ; Mon, 16 Sep 2024 11:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487173; cv=none; b=PWv8vrYfQV3hb96UJlybxPoKQ01Sqweszgm2G9zqAuoMj/tYh0T5fY8C6j0sc1Qdqohx7Z29HK5fRMfDsL6uVpwyRqHw/rXK0UL/84Mjmgb1b4kCU0WdeeKvY6p0Y/J8ZuZj1aI7CgNCHIOHUZcUTxh8wawYVA9fsFXHnuE5tVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487173; c=relaxed/simple; bh=VIbR53GCIevmu8c6Q/etb5K252rsAKsDwwiMwQc9dj8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mjBWdMOyBoAb7pa52uBbG3yZzujwdg9nntxpc+w7SBSOHQGYuaNNh7dgGcWatMFpLsXqp0wcsITG4rWOpTrs9m9sB5rYhW+cXGwnpeiB1MCwyG27iqOPJ5NZomWtvhI8XQAHz/F7CkVFHgi20oU0yMHyu2J1ycq8U7GhGFkUlE4= 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=TUFkxaj5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NQSDUPbr; arc=none smtp.client-ip=103.168.172.148 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="TUFkxaj5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NQSDUPbr" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 97E9C13800B0 for ; Mon, 16 Sep 2024 07:46:11 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 16 Sep 2024 07:46:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487171; x=1726573571; bh=RZH/DuJ1pB dXdCIOqLvms8f66USJ0KoIIAewmYukAiA=; b=TUFkxaj5LQMuK8w5WBm2esdPTZ PD8Ra1Mo64HX/XnZz1rQJzkTqN5dDz0bP7fGU3z8P1Gm0XkUKeJb/XSQhSymPNVX F8HqqD9yhI7Uuwqqb0epBJB9JWcah3ks7C8bJMy4X0U51YrxAs2rtT+54va7xbab vEmSHAPHi3c+lGXznQAEUISDjuX8FcrNBrLyPvCW2BGTAuLuD96wwOkuYP75K2b1 T4GwNjfGgZgUmgXG7Ea2J1WX/bdtmyFS6xofJo4WPHTl4+cepR9v+F/q7d57pXFa iwYtQ0HDLgmsRbrarhqiqeDclAh285qtjXF9ycrAPf3/d04spPbRW2tFQ45Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487171; x=1726573571; bh=RZH/DuJ1pBdXdCIOqLvms8f66USJ 0KoIIAewmYukAiA=; b=NQSDUPbrEnhV360j6tjIUdA1LBKenIwdQBybs/Wbb7za 3aRZZ1tQsEUAwVy8CyCs8J64wRU9xvlqxTyTzx2HZxJ+Ml/vGfotzW7hzp5YIgtw npbAWyulxq9S9TOsjl26bUJEtP187JfKFpNwjghOPg94U6aYvTnOLbMj8MpD73cZ 9J8C1w2L/r2nyRBka+NS3xjFvQkgBETqQ741U0gJKG9SUsZwAsy5wKOvy3XuQtkW Zl6E8vVZzGgt2KpC+yIT2diE8cvP0UlsgNhDHf5ZbARVNusCq9WUnIT/fbGYP+ry CVK7UR+F1S2FykmOMD07Pi093Ls21BPU72VACCj0BQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:10 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 07666f13 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:54 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 16/23] trace2: destroy context stored in thread-local storage Message-ID: <0fb3dc55e58559272cc79c69646be78aefd2f7ac.1726484308.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: Each thread may have a specific context in the trace2 subsystem that we set up via thread-local storage. We do not set up a destructor for this data though, which means that the context data will leak. Plug this leak by installing a destructor. This leak is exposed by t7814, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- trace2/tr2_tls.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c index 4f75392952b..7b023c1bfc6 100644 --- a/trace2/tr2_tls.c +++ b/trace2/tr2_tls.c @@ -152,11 +152,19 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us) return us - tr2tls_us_start_process; } +static void tr2tls_key_destructor(void *payload) +{ + struct tr2tls_thread_ctx *ctx = payload; + free((char *)ctx->thread_name); + free(ctx->array_us_start); + free(ctx); +} + void tr2tls_init(void) { tr2tls_start_process_clock(); - pthread_key_create(&tr2tls_key, NULL); + pthread_key_create(&tr2tls_key, tr2tls_key_destructor); init_recursive_mutex(&tr2tls_mutex); tr2tls_thread_main = From patchwork Mon Sep 16 11:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805345 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 21B8E156676 for ; Mon, 16 Sep 2024 11:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487178; cv=none; b=qjPBqAPTySJoJOAuzgbBPH5zj+9v7MJakS+IPGnp6ljhMGDm8IHLGAB+XdWrbkC7NQT79cJizNPcOt6Uwo6FVP965y0u8DTOYLA8R/VpYpwoXCKy9tVFMRnmeebHRpMiVTqh6QRHworaSdiOGDqw8KN8TPvEWmUsTmv92W9EcCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487178; c=relaxed/simple; bh=hNTk47IQ1+FjjGAkEBcnR96D4OcKRvAZGDxyiMHX/2I=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pfmhu4jUe8Zb/oMnV+H+TrLXaFIE5jWDS6JkkO7Je9nCwbUFh4415crEt94il+ILvMrKROpBgkGBM2BA6OnLhw2QHyvvwxFdke85fyo9b7aIHnLaJRcMTMvpAH7NavUmmwkLP9S27/PogoBUCSMZX+GT2yHs68olwE7JnAT0NGY= 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=iZS8WuYJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=R1lvOXJD; arc=none smtp.client-ip=103.168.172.153 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="iZS8WuYJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R1lvOXJD" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 801B21140239 for ; Mon, 16 Sep 2024 07:46:16 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 16 Sep 2024 07:46:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487176; x=1726573576; bh=x3lcHrh9t6 AApyJ1NTjddk39qA7Xypg7X5U1oGFqQsA=; b=iZS8WuYJpw7PlrwPdmat+DXOLX VvvkS1PIBhcE1TsDOoYJsUDoVPcm6iDXYTqhrmsCjy2TPlDRA0dNX83+4QdJjn/f fWIUmaQ+0P5AhX8fEGmwwdr7rg+4ozMhz/Gly5uDYu9SMXlrP8u9YDQuVheYH3yO bUmMD+NFGa+K5aOoURQ+v3ub2SsgblDU/AE102lYNlXzUxgji4GvmWz1QRDbVGoR UOquLRmFgeC9aYYCKLsyr3yyK65LaDUUM5aJ5Nf4J7j/jWQdhBteisE7/Z/yx6ZP KIntMvMzv+wfGNyojt5+vsjAL4kt13K84/F9W5IkTrloeGaIRfzQF6KysWUA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487176; x=1726573576; bh=x3lcHrh9t6AApyJ1NTjddk39qA7X ypg7X5U1oGFqQsA=; b=R1lvOXJDCp4TDg+Ih2Fi3CdFerRbKZxBSA+UbRRCyxL0 oKCk5a35ETgNqM3nZipwpzSDa/PqF2kGxh6iFbEYgyGSPSwhaV7YB/Jw14FIGtIk /MaC2JtLn+27G2sp3j+TRW4nUDLYPjXMsg7BTrnVAeexJpOjSDs0CAaZL8SwTC5i /qEmeorlp1xCZC4aXRgcw4o68cS1jPy+VwW8Cs6tn6r6ttawxrIFBLcUrRb3vflg /tR2CGX32lCg0Upelf4QgEebjKy7pyCaUF+PqZ7lHieL2FUjGwvo0CALQCIVX/CR Z34tfrU0W9yMagV9kb4Bb9hocoROQkEh2ePErPJiwQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:15 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 60e98897 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:45:59 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 17/23] submodule: fix leaking submodule ODB 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: In `add_submodule_odb_by_path()` we add a path into a global string list. The list is initialized with `NODUP`, which means that we do not pass ownership of strings to the list. But we use `xstrdup()` when we insert a path, with the consequence that the string will never get free'd. Plug the leak by marking the list as `DUP`. There is only a single callsite where we insert paths anyway, and as explained above that callsite was mishandling the allocation. This leak is exposed by t7814, but plugging it does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- submodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/submodule.c b/submodule.c index 0e67984d770..a07debc227f 100644 --- a/submodule.c +++ b/submodule.c @@ -175,11 +175,11 @@ void stage_updated_gitmodules(struct index_state *istate) die(_("staging updated .gitmodules failed")); } -static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_NODUP; +static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP; void add_submodule_odb_by_path(const char *path) { - string_list_insert(&added_submodule_odb_paths, xstrdup(path)); + string_list_insert(&added_submodule_odb_paths, path); } int register_all_submodule_odb_as_alternates(void) From patchwork Mon Sep 16 11:46:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805346 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 42C96157A67 for ; Mon, 16 Sep 2024 11:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487181; cv=none; b=Q/bQNsYujoYldW7/ZL0nYYKVFEvLG0rqKp8Kap5iOoq655h0oza6O8sB+gfWBGqVcFZBrp6MlyBA8WceYoU1jDlEa03QlfuuAYIvvlAOCCkdByYSWX8wvHexDWK3IAugoMZxOrgPSXMltLGtwC5eV1CEQeNEA19grkcq2jnNwf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487181; c=relaxed/simple; bh=vcFvOCpQkqKmnRp8Zv+VU32U2bXShGpn4xxwP6pSGko=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qU+3rmNV1JNAJRzQQOeJfjgxtOBz+mPUlwscs8lr4I4Zd/TH+T/Ra17TcxxQgc95llGzr2Yr4o0S6OBH7E7e6NV253zHSBkT/gyN4WgQHKMvq2izOM2A82R/PZiftTnuqmA7OyrHehHVdvUq+ZUeCTsNSoxY/uolpg7st8AB2wg= 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=f7hZS4s3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=J3D4Zctg; arc=none smtp.client-ip=103.168.172.153 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="f7hZS4s3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="J3D4Zctg" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 58F5E1140125 for ; Mon, 16 Sep 2024 07:46:19 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Mon, 16 Sep 2024 07:46:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487179; x=1726573579; bh=880qX5sU7V 13SxS2gP5qfj8Ab5LBsdAq8B4L02JRyLs=; b=f7hZS4s3//YrJ+lVrC34/eGSaP LpuIIOFd0fVp1c0JkOjLUYgvXKTuWo2GKg3JZwBPd1yx0scnvZ0wHoKaF4z7h+LZ AmVr5JuRGOel1d72HZGytD66eWMMawF3tgdzNgENNVnZ//cfw2FmzU5Xklt8MuAz DCfHy6ueFseHGBJn8AXiS65MDaGGODQ9GAnd6yjwjFmEu60vU7E8il11fycQ2zvj 3LNnP7UFg+XysYoouAdmVFnVSJWMVNjbi/AwwPeKAro+CA4xnyprmc8RyffXIFAo zt1NnIZjDZ8zfWIw00yukwyzkbCwS2O2w/WmRJ5scb+LdaLo1uHKj1ggRUkQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487179; x=1726573579; bh=880qX5sU7V13SxS2gP5qfj8Ab5LB sdAq8B4L02JRyLs=; b=J3D4ZctgI+ZBuO5h5xmpO4wRT8l5N3deDO995wQQygG2 MUoRjy8pOj/56rFZ6McHW8IVhVk9KsouOKlz9q8msjomjw0+U3dyrrOaVuEJxYt/ vmrOO+i13GjM4UyMW+OCPek5lpUkzqnsxaoRkIjy+W1A+CE8tsnpfHjDkKvmoO6k JQrRU3A1s0dP9c5eqExf6Bl7QDd+uZF6XCkMJVvh2NuF39BHSau1mVM61yA+E+wj OOpBBAEcossPQLpWXAC8bHz2kxXygKLd1vHZRbigQfWqU9HvXzk6PYOKkJvTzBV0 lwnl1VIOyToFtO0vGA9mmbo9FqlMpwjIGoKV3NGs3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7526d72d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:46:01 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 18/23] grep: fix leaking grep pattern Message-ID: <411df7248d2868e906d5ba882f9cd9abf82eaca8.1726484308.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 creating a pattern via `create_grep_pat()` we allocate the pattern member of the structure regardless of the token type. But later, when we try to free the structure, we free the pattern member conditionally on the token type and thus leak memory. Plug this leak. The leak is exposed by t7814, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- grep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grep.c b/grep.c index e5761426e4f..701e58de04e 100644 --- a/grep.c +++ b/grep.c @@ -843,11 +843,11 @@ static void free_grep_pat(struct grep_pat *pattern) free_pcre2_pattern(p); else regfree(&p->regexp); - free(p->pattern); break; default: break; } + free(p->pattern); free(p); } } From patchwork Mon Sep 16 11:46:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805347 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 0BBFB1581F3 for ; Mon, 16 Sep 2024 11:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487184; cv=none; b=dI5sTYlwBfVsM/3FLbVXquoUBF3lAYty3U3Q9kNB7j/8lpkgnctf0++C2wFYzsRs5QKzU7TB/Z6gTmCjoS2HUkICWOjcvva8nBCx3DUoNgxxAKVpgOaOL5nQfbsC0a5dHdWHpJbDuTopXdpmRcjMFFf965F0PJjfDPve3lS+URs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487184; c=relaxed/simple; bh=VasDHImpGrQnO0IE/PwOS8bPlpZC9i1IZTDB+9Lz88A=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Aath3OhIyUdPxnrqlNdkBAsTicbHwGg7V1VKgbz8vLD3cIooDEipKbAiKA3sdVPfUo6o+5+d834e40CjuRmSUXS6EhMMexk2JuVNiuKiJy8oypu6mTxjgFRsY3uBeayetvRG8m8Qcca+TUJzM6WrLn7xPo0cPSZ/yrZtIhsJBsc= 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=DJ9Wa8Tl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ExUhM+Lb; arc=none smtp.client-ip=103.168.172.148 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="DJ9Wa8Tl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ExUhM+Lb" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 41A2A13802E4 for ; Mon, 16 Sep 2024 07:46:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 16 Sep 2024 07:46:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487182; x=1726573582; bh=3D5zyi2OUZ YhTCl1DSWT6mkVlwu2IQkuIaiEs7vZI0Q=; b=DJ9Wa8TlooW24mrNGEF0uzjOPt F/xXz7zWncKXNi2t6TKlX4nFbu3Ye3jUc5XQXSKwgbHy/95ehOk0ERZrnjiLGbxW R/naeg7OfNCJfW8xESQXodDf2AYOi1b8VE6Js09x6Z9bdVSR4HyJWrBEH8DDqEim HkDlmd1yHLfWNwrQCbTh3Ha/PTPOdwad9JCq/s5jvHR366LoyntePGc+ng94f5GY OOFkXx2MM0VPm0Nw8NB6feshFoD63uOaY64om+v5Gdx64VAHls1wgWsYybbTLxc/ /xr0wm4lYtHtX5+0dqNziM6PmYICtFTy6rtvXs46wY8esT1OY0NGpYhotr0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487182; x=1726573582; bh=3D5zyi2OUZYhTCl1DSWT6mkVlwu2 IQkuIaiEs7vZI0Q=; b=ExUhM+LbRFtGazSK9eWNAY5rvxQlZrr5XiBDkCRdaGtx l3q0W8dYAKDTeHmEcNaYp3eiOql/cKdY/IIgRFGOqgMz/KgPBiyFSfbbeO0NzIdw DGpB1TjGXMNqZPPCTY47+OOYDXPRnMebZ+WhJ2b6h2dhbC9rPYg9aMmd6kLErx0J K1gzds3h+8C2ZcGYXxuQhMZxcqDQHD2LIvh5cxHSlM/jVBYGB/W4O1CX/JZCMYfP OnS5gQo02EmEV8zi1cLcG+U3edBNWA3+oJhreNzDvHNiUHwIk4uQst/lsaKBU+Zy VwpqwmpasmeF6tcVJeJrb1Q/d/kdE2T6Y7YU+zbEcQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepheenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 88b80036 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:46:04 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 19/23] promisor-remote: fix leaking partial clone filter Message-ID: <690de28bef8c4c7608aaf5c1f92ee24525dcb987.1726484308.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 partial clone filter of a promisor remote is never free'd, causing memory leaks. Furthermore, in case multiple partial clone filters are defined for the same remote, we'd overwrite previous values without freeing them. Fix these leaks. Signed-off-by: Patrick Steinhardt --- promisor-remote.c | 2 ++ t/t7814-grep-recurse-submodules.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/promisor-remote.c b/promisor-remote.c index 317e1b127fe..9345ae3db23 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -154,6 +154,7 @@ static int promisor_remote_config(const char *var, const char *value, if (!r) return 0; + FREE_AND_NULL(r->partial_clone_filter); return git_config_string(&r->partial_clone_filter, var, value); } @@ -189,6 +190,7 @@ void promisor_remote_clear(struct promisor_remote_config *config) { while (config->promisors) { struct promisor_remote *r = config->promisors; + free(r->partial_clone_filter); config->promisors = config->promisors->next; free(r); } diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh index 167fe661504..55ed630e77e 100755 --- a/t/t7814-grep-recurse-submodules.sh +++ b/t/t7814-grep-recurse-submodules.sh @@ -7,6 +7,7 @@ submodules. ' TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 From patchwork Mon Sep 16 11:46:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805348 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 CD07B15854D for ; Mon, 16 Sep 2024 11:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487187; cv=none; b=Okxi/0wHTTCcnSYY0B/bFrgtRYWgFbCkd08xBcbgTQgPZnOd5PHfV4bFbVVM1HY5Uf+7wqLKaQdtBXdB0CN7Ctkq89exIBgmwTdVtg/+2TekUrOagg17yR+7bDBOO5D21QzwlWRF0DIUbqIDAMcjFVmqYu0YnOm0sUIIbkbtRuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487187; c=relaxed/simple; bh=j5lWjvJ5VTUIh4rJjdlmLupm3LVCaUviF05OKR1224A=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EHSVtECzBEZ0yjWSSV70VNZKVHuZjt3wbTMX71vnr2zOOfWDQpCnXYjpsXCvbsu79gQD+Yw99+YLJVkuZ09z/hmvtYVbOtzEwu7XAOTcBu0yvrchnj6B/0gTZq9+OiJxXRudLgTAaBi5AucbVlLXiVQsfmTnK0lMsUUWKkuTnF8= 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=dqO06MVC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VvcmtUZB; arc=none smtp.client-ip=103.168.172.148 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="dqO06MVC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VvcmtUZB" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 1270C13802BF for ; Mon, 16 Sep 2024 07:46:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 16 Sep 2024 07:46:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487185; x=1726573585; bh=2OaP9T77wt 6vivXJHwvT5KlMC5XETTEQEgjghBHbVuE=; b=dqO06MVCE7Mzy+X3Oqo77SUqXI gtuGwCaEhAOyYPMjZ5s2jyAjYJD2Ooe780RBZcqsPZKB9JH2RDm7qmSDAOsWRgbT 5UHAZRn7yYKF3MSSuytTDTht9Ukg+wed23r8aKnbVe5Sx5LJtqgYLFfXSyfAI1jP 9bfmzSbvTFW0MwoGh3M5fkxbsZjA4kOr0/PYL0D6xVXlAyjvRHoL/m2fE+MlyWnF MR6NSKSciVrRZuVUZgccyQQL8m8zFnPERTrGwmIlpBZMM8j6shib5K7SeZNt1XVS zoFe0Jbmr8AgmZnPtEMXZuncz7ThiaGirDSUl1eRvmUJ0sye4/6+Y8Kdd9yQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487185; x=1726573585; bh=2OaP9T77wt6vivXJHwvT5KlMC5XE TTEQEgjghBHbVuE=; b=VvcmtUZBJv69tW8p662q2gZPRuBLigkryt5bVi9ITRuO mUdmZe8MOPvZhOP99h2hpWgMchL9op7BYoDYF3EDXlNEfHX31e00H34CuCbq3aCz FpG8pAyYnQBeO5mfPZ/sReuMtNxVhwq9PkIyLCB38XoSXYZat8zDR1hoP8zdKWOl +HQGbUsRvh8Fe7JGDIzLzmJNQVxVuFARRI/BcOC0SMZ/mLnjJw9YZ2IbMOMZ0WTV ySSnFfiz3sKzsqcDwsJZ62MJC5OuOsDbmxxtP5h0mJJNQfyhjUIcwEMJpSKv09iU rsdto+NKHKSqGEET4gSbLBTJovEgAqIv7hQ9S8IQfg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1b807034 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:46:07 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 20/23] builtin/maintenance: fix leaking config string 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 the maintenance strategy from config we allocate a config string, but do not free it after parsing it. Plug this leak by instead using `git_config_get_string_tmp()`, which does not allocate any memory. This leak is exposed by t7900, but plugging it alone does not make the test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 7dac9714054..3acfa367ad1 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1476,9 +1476,9 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts, static void initialize_maintenance_strategy(void) { - char *config_str; + const char *config_str; - if (git_config_get_string("maintenance.strategy", &config_str)) + if (git_config_get_string_tmp("maintenance.strategy", &config_str)) return; if (!strcasecmp(config_str, "incremental")) { From patchwork Mon Sep 16 11:46:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805349 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 8A1AA156C6F for ; Mon, 16 Sep 2024 11:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487190; cv=none; b=YdiieouihzR0iwfXSUVEwiZGIgtVd/rkbxI0QtaJGLFpNOTYz8sY+pXrqIYz/e3x8Ynd1tgqBfKTnVstnVxdZ++aBPGCgqGXOQ3Y1sMdX8djEnHJ8rDz96ZJF1Mq96k9mGP+2NytkjvUKrGLjQPydtt7xSdG2BD0AaxHcKX/6Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487190; c=relaxed/simple; bh=DaxCF4xjAwf0h5Eg/+2dvdwNImfb15LOASwkrJ+RLt4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dpsYxYIEkGrQk3Iq4uooaHSUp7+c1nXIUndMyBk+xMON4LmqGbtxDtZ54B+mFItzp/9SzPxITmSjQOnS4eheHxE88eRltt91taTuEf5MM6EWRhsAmk8UEHcI1P9Oo+VUyX3Gu8fGQySlrsJQSbbHGgPwc4h5h0Fj1Q2oupkR4UE= 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=XPu5/9Nw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LqGU9CxX; arc=none smtp.client-ip=103.168.172.153 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="XPu5/9Nw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LqGU9CxX" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id E6BE4114007D for ; Mon, 16 Sep 2024 07:46:27 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 16 Sep 2024 07:46:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1726487187; x=1726573587; bh=YJxC/3+AiuJXBl4sMMn9ExVuKgPZsltqb9yFQNZjp5k=; b= XPu5/9Nwx4PJ0h8azih+2dQWIi8mFT/YqpWGUU2xBheKEaNhO5yDg/KOz0vROMon cff2g2Ry1HjL8bDCvLO5VrOR/OJL15Z2o/9rYsa2bNaN4/7Nrta1KcDxoRelVMYT Jon/wv6TBzMbzK+PUfwGyw2P9GST/MZl3TjAAWXXyENGvmsN9+xXQyUjHc9NNyyl c3YWlnyFGPiJO9cFC3YViAQr7Mz1shI44Zmg8I1FkLMmOPd5sTJipGhapRhQ+bwB Y2xnR0U+SDZIbYImiNwZ6gFHy0nbrb0vEOrp/PGBUyTWGm6m21KjAOCum3nyPxOg BkNPO4HCRWNnvIoH2hP92A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1726487187; x= 1726573587; bh=YJxC/3+AiuJXBl4sMMn9ExVuKgPZsltqb9yFQNZjp5k=; b=L qGU9CxXKD3F1SNHvCGKLfXIRaWsqPNcbcTQKocob4HCEscQGKoYHNRbEzQ5Jm5Yk Ft3kT5cCTRm9BC09VAhxxzYGUu3WV5x5TZyeWddptZ8RDnTXoGVtVIqNF1PZ+8gi mvXWHTuWu+Wu0kLREhh0+Kj7UW63IwqyqEA/Bwdlm1Qn9kxNWZ3KDW0nq9wEb5ZH R6rN4RjhiWRyMgVIrL6xYT13lWSSKlKeICk3BzpHgk8r02ZpwlHUDNENN6wGCri8 kocALA9ArLNz64e362uj6DL/L8LLMiOOKdRc0QG0OGGkxtW1SPmVOqAHE5JrCzCp 3u6irUKPECYtxvwPtaEsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeeikeehffdvtd ekvdeuveefjeeigfethfeiteduieegkeeuleefteevteehfeevgfenucffohhmrghinhep rghpphhlvgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1ffa49a2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:46:09 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Message-ID: <46956bd8fbda45a9e2115e2b3b40c1ab20ea3eee.1726484308.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 `get_schedule_cmd()` function allows us to override the schedule command with a specific test command such that we can verify the underlying logic in a platform-independent way. Its memory management is somewhat wild though, because it basically gives up and assigns an allocated string to the string constant output pointer. While this part is marked with `UNLEAK()` to mask this, we also leak the local string lists. Rework the function such that it has a separate out parameter. If set, we will assign it the final allocated command. Plug the other memory leaks and create a common exit path. Signed-off-by: Patrick Steinhardt --- builtin/gc.c | 127 ++++++++++++++++++++++++++--------------- t/t7900-maintenance.sh | 1 + 2 files changed, 81 insertions(+), 47 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 3acfa367ad1..b68a0be62c1 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1780,32 +1780,33 @@ static const char *get_frequency(enum schedule_priority schedule) * * If $GIT_TEST_MAINT_SCHEDULER is set, return true. * In this case, the *cmd value is read as input. * - * * if the input value *cmd is the key of one of the comma-separated list - * item, then *is_available is set to true and *cmd is modified and becomes + * * if the input value cmd is the key of one of the comma-separated list + * item, then *is_available is set to true and *out is set to * the mock command. * * * if the input value *cmd isn’t the key of any of the comma-separated list - * item, then *is_available is set to false. + * item, then *is_available is set to false and *out is set to the original + * command. * * Ex.: * GIT_TEST_MAINT_SCHEDULER not set * +-------+-------------------------------------------------+ * | Input | Output | - * | *cmd | return code | *cmd | *is_available | + * | *cmd | return code | *out | *is_available | * +-------+-------------+-------------------+---------------+ - * | "foo" | false | "foo" (unchanged) | (unchanged) | + * | "foo" | false | NULL | (unchanged) | * +-------+-------------+-------------------+---------------+ * * GIT_TEST_MAINT_SCHEDULER set to “foo:./mock_foo.sh,bar:./mock_bar.sh” * +-------+-------------------------------------------------+ * | Input | Output | - * | *cmd | return code | *cmd | *is_available | + * | *cmd | return code | *out | *is_available | * +-------+-------------+-------------------+---------------+ * | "foo" | true | "./mock.foo.sh" | true | - * | "qux" | true | "qux" (unchanged) | false | + * | "qux" | true | "qux" (allocated) | false | * +-------+-------------+-------------------+---------------+ */ -static int get_schedule_cmd(const char **cmd, int *is_available) +static int get_schedule_cmd(const char *cmd, int *is_available, char **out) { char *testing = xstrdup_or_null(getenv("GIT_TEST_MAINT_SCHEDULER")); struct string_list_item *item; @@ -1824,16 +1825,22 @@ static int get_schedule_cmd(const char **cmd, int *is_available) if (string_list_split_in_place(&pair, item->string, ":", 2) != 2) continue; - if (!strcmp(*cmd, pair.items[0].string)) { - *cmd = pair.items[1].string; + if (!strcmp(cmd, pair.items[0].string)) { + if (out) + *out = xstrdup(pair.items[1].string); if (is_available) *is_available = 1; - string_list_clear(&list, 0); - UNLEAK(testing); - return 1; + string_list_clear(&pair, 0); + goto out; } + + string_list_clear(&pair, 0); } + if (out) + *out = xstrdup(cmd); + +out: string_list_clear(&list, 0); free(testing); return 1; @@ -1850,9 +1857,8 @@ static int get_random_minute(void) static int is_launchctl_available(void) { - const char *cmd = "launchctl"; int is_available; - if (get_schedule_cmd(&cmd, &is_available)) + if (get_schedule_cmd("launchctl", &is_available, NULL)) return is_available; #ifdef __APPLE__ @@ -1890,12 +1896,12 @@ static char *launchctl_get_uid(void) static int launchctl_boot_plist(int enable, const char *filename) { - const char *cmd = "launchctl"; + char *cmd; int result; struct child_process child = CHILD_PROCESS_INIT; char *uid = launchctl_get_uid(); - get_schedule_cmd(&cmd, NULL); + get_schedule_cmd("launchctl", NULL, &cmd); strvec_split(&child.args, cmd); strvec_pushl(&child.args, enable ? "bootstrap" : "bootout", uid, filename, NULL); @@ -1908,6 +1914,7 @@ static int launchctl_boot_plist(int enable, const char *filename) result = finish_command(&child); + free(cmd); free(uid); return result; } @@ -1959,10 +1966,10 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit static unsigned long lock_file_timeout_ms = ULONG_MAX; struct strbuf plist = STRBUF_INIT, plist2 = STRBUF_INIT; struct stat st; - const char *cmd = "launchctl"; + char *cmd; int minute = get_random_minute(); - get_schedule_cmd(&cmd, NULL); + get_schedule_cmd("launchctl", NULL, &cmd); preamble = "\n" "\n" "" @@ -2052,6 +2059,7 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit free(filename); free(name); + free(cmd); strbuf_release(&plist); strbuf_release(&plist2); return 0; @@ -2076,9 +2084,8 @@ static int launchctl_update_schedule(int run_maintenance, int fd UNUSED) static int is_schtasks_available(void) { - const char *cmd = "schtasks"; int is_available; - if (get_schedule_cmd(&cmd, &is_available)) + if (get_schedule_cmd("schtasks", &is_available, NULL)) return is_available; #ifdef GIT_WINDOWS_NATIVE @@ -2097,15 +2104,16 @@ static char *schtasks_task_name(const char *frequency) static int schtasks_remove_task(enum schedule_priority schedule) { - const char *cmd = "schtasks"; + char *cmd; struct child_process child = CHILD_PROCESS_INIT; const char *frequency = get_frequency(schedule); char *name = schtasks_task_name(frequency); - get_schedule_cmd(&cmd, NULL); + get_schedule_cmd("schtasks", NULL, &cmd); strvec_split(&child.args, cmd); strvec_pushl(&child.args, "/delete", "/tn", name, "/f", NULL); free(name); + free(cmd); return run_command(&child); } @@ -2119,7 +2127,7 @@ static int schtasks_remove_tasks(void) static int schtasks_schedule_task(const char *exec_path, enum schedule_priority schedule) { - const char *cmd = "schtasks"; + char *cmd; int result; struct child_process child = CHILD_PROCESS_INIT; const char *xml; @@ -2129,7 +2137,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority struct strbuf tfilename = STRBUF_INIT; int minute = get_random_minute(); - get_schedule_cmd(&cmd, NULL); + get_schedule_cmd("schtasks", NULL, &cmd); strbuf_addf(&tfilename, "%s/schedule_%s_XXXXXX", get_git_common_dir(), frequency); @@ -2235,6 +2243,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority delete_tempfile(&tfile); free(name); + free(cmd); return result; } @@ -2276,21 +2285,28 @@ static int check_crontab_process(const char *cmd) static int is_crontab_available(void) { - const char *cmd = "crontab"; + char *cmd; int is_available; + int ret; - if (get_schedule_cmd(&cmd, &is_available)) - return is_available; + if (get_schedule_cmd("crontab", &is_available, &cmd)) { + ret = is_available; + goto out; + } #ifdef __APPLE__ /* * macOS has cron, but it requires special permissions and will * create a UI alert when attempting to run this command. */ - return 0; + ret = 0; #else - return check_crontab_process(cmd); + ret = check_crontab_process(cmd); #endif + +out: + free(cmd); + return ret; } #define BEGIN_LINE "# BEGIN GIT MAINTENANCE SCHEDULE" @@ -2298,7 +2314,7 @@ static int is_crontab_available(void) static int crontab_update_schedule(int run_maintenance, int fd) { - const char *cmd = "crontab"; + char *cmd; int result = 0; int in_old_region = 0; struct child_process crontab_list = CHILD_PROCESS_INIT; @@ -2308,15 +2324,17 @@ static int crontab_update_schedule(int run_maintenance, int fd) struct tempfile *tmpedit = NULL; int minute = get_random_minute(); - get_schedule_cmd(&cmd, NULL); + get_schedule_cmd("crontab", NULL, &cmd); strvec_split(&crontab_list.args, cmd); strvec_push(&crontab_list.args, "-l"); crontab_list.in = -1; crontab_list.out = dup(fd); crontab_list.git_cmd = 0; - if (start_command(&crontab_list)) - return error(_("failed to run 'crontab -l'; your system might not support 'cron'")); + if (start_command(&crontab_list)) { + result = error(_("failed to run 'crontab -l'; your system might not support 'cron'")); + goto out; + } /* Ignore exit code, as an empty crontab will return error. */ finish_command(&crontab_list); @@ -2386,8 +2404,10 @@ static int crontab_update_schedule(int run_maintenance, int fd) result = error(_("'crontab' died")); else fclose(cron_list); + out: delete_tempfile(&tmpedit); + free(cmd); return result; } @@ -2410,10 +2430,9 @@ static int real_is_systemd_timer_available(void) static int is_systemd_timer_available(void) { - const char *cmd = "systemctl"; int is_available; - if (get_schedule_cmd(&cmd, &is_available)) + if (get_schedule_cmd("systemctl", &is_available, NULL)) return is_available; return real_is_systemd_timer_available(); @@ -2594,9 +2613,10 @@ static int systemd_timer_enable_unit(int enable, enum schedule_priority schedule, int minute) { - const char *cmd = "systemctl"; + char *cmd = NULL; struct child_process child = CHILD_PROCESS_INIT; const char *frequency = get_frequency(schedule); + int ret; /* * Disabling the systemd unit while it is already disabled makes @@ -2607,20 +2627,25 @@ static int systemd_timer_enable_unit(int enable, * On the other hand, enabling a systemd unit which is already enabled * produces no error. */ - if (!enable) + if (!enable) { child.no_stderr = 1; - else if (systemd_timer_write_timer_file(schedule, minute)) - return -1; + } else if (systemd_timer_write_timer_file(schedule, minute)) { + ret = -1; + goto out; + } - get_schedule_cmd(&cmd, NULL); + get_schedule_cmd("systemctl", NULL, &cmd); strvec_split(&child.args, cmd); strvec_pushl(&child.args, "--user", enable ? "enable" : "disable", "--now", NULL); strvec_pushf(&child.args, SYSTEMD_UNIT_FORMAT, frequency, "timer"); - if (start_command(&child)) - return error(_("failed to start systemctl")); - if (finish_command(&child)) + if (start_command(&child)) { + ret = error(_("failed to start systemctl")); + goto out; + } + + if (finish_command(&child)) { /* * Disabling an already disabled systemd unit makes * systemctl fail. @@ -2628,9 +2653,17 @@ static int systemd_timer_enable_unit(int enable, * * Enabling an enabled systemd unit doesn't fail. */ - if (enable) - return error(_("failed to run systemctl")); - return 0; + if (enable) { + ret = error(_("failed to run systemctl")); + goto out; + } + } + + ret = 0; + +out: + free(cmd); + return ret; } /* diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index abae7a97546..c62c42848a2 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -2,6 +2,7 @@ test_description='git maintenance builtin' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GIT_TEST_COMMIT_GRAPH=0 From patchwork Mon Sep 16 11:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805350 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 676A2156C71 for ; Mon, 16 Sep 2024 11:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487192; cv=none; b=kMnzwm5r5OW+RU3o7HnYPDY24awrGMRwkv8dWQYK0HEIh9jQ231/Gvg2qZMStO6sKMuLkTDZqBPuQPiesBfGEnghvEIIcQYbbo9/zYYsuxMKfIbYJ4+qXKK3aaa/w7HWpeGK/CjVxGH2jYBDFRnk7tMfUn84cJ3o0oAnLNWZOss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487192; c=relaxed/simple; bh=LzYiJKX+8TzJZY41NnK6Zh67MMV4gZk8FgSvDHSbKI0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J6SN7YOcq4n3NA+4ZKWxvUFnJJHGeGBnTdRDDoQKZOvBHK7veg19wXeSHDj3pfR/syKzfvecJeDMpjHcAlnZd+PYQOghC5m+ex/DRdMI+/kegPy1WWcwA2/o/lUQqzKaZwY17zkZIHFaMoptWR04jxabVK/o9eGLTnuBERE0Hkk= 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=NoFkCQU1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uIEsjUzz; arc=none smtp.client-ip=103.168.172.148 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="NoFkCQU1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uIEsjUzz" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id C5A051380246 for ; Mon, 16 Sep 2024 07:46:29 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 16 Sep 2024 07:46:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487189; x=1726573589; bh=BaCi1wvQnd tdzDNioDS5oxo5dxFCUqqwLF6Hj7036Ks=; b=NoFkCQU1IRvXUdBZ3eCsUpRPQ8 NAamYVGC1fHsgkrZfMvZYRdc43aEwas/uW/kjsrK/ZaYmBHCOdxY2hF0kYBy9z4u YJJMZ0LqUTfr2EA9DPWCMYTjC92Pb2cQ75Ymbsm+7H/FHm9sxEMcuMxE47fTLCa1 owUECHC+iZ/Ttm0qZOPgMTuCU4FNvkHq5w8PeacVcwanI6S8vGw3iwsPcquoofaq Vz0Qzbc8z1I2HoJD49/EG1PWL6eGiS2b9me/hAdAIvt4/Lrbw8aweLRFebxy3X+O z0lCuJB4iJPLzFDvDity3+2HP98SJaCk9wjmvQtmeFcq95QWvNKIn9B0Schw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487189; x=1726573589; bh=BaCi1wvQndtdzDNioDS5oxo5dxFC UqqwLF6Hj7036Ks=; b=uIEsjUzzCv2Ox4F6nuIdN8nPrxDHkuzGM5zO0yMihrhx ujJd80KK5p869q2xXThkYjiijoQP1KGNqVVpctOXrBahdm2aM54vIIV+6y0H5Dbb v/dtOA1l8GCuUJuZTcZZ4MR16ewBejw2yCxHxpjfEjr09OavbgAOh+RQRPkk0Isz uceeoH8eAREBtJbgX0hIV7n2drmgtCC/CwtB0m9P+KZ5HJukZPImES0lFRKQASLi NXMyFcEn8oe2P9QUDF5LvLvlLlMLMH1NoT3B8iWgANCKGyO/zSdykc4zRPe2kHPE EwYuaIWHjuIvO8eF9EJGVUIs5yvoHCtfUC3dQTdj8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:29 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 188f6aad (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:46:12 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 22/23] revision: fix leaking parents when simplifying commits Message-ID: <2a23df9a6869f58a231cfe4947b322690d48cb1a.1726484308.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 simplifying commits, e.g. because they are treesame with their parents, we unset the commit's parent pointers but never free them. Plug the resulting memory leaks. Signed-off-by: Patrick Steinhardt --- revision.c | 5 +++++ t/t1414-reflog-walk.sh | 1 + t/t5310-pack-bitmaps.sh | 1 + t/t5326-multi-pack-bitmaps.sh | 2 ++ t/t6004-rev-list-path-optim.sh | 1 + t/t6019-rev-list-ancestry-path.sh | 1 + t/t6111-rev-list-treesame.sh | 1 + 7 files changed, 12 insertions(+) diff --git a/revision.c b/revision.c index 2d7ad2bddff..e79f39e5555 100644 --- a/revision.c +++ b/revision.c @@ -1071,7 +1071,11 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) ts->treesame[nth_parent] = 1; continue; } + + free_commit_list(parent->next); parent->next = NULL; + while (commit->parents != parent) + pop_commit(&commit->parents); commit->parents = parent; /* @@ -1103,6 +1107,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) die("cannot simplify commit %s (invalid %s)", oid_to_hex(&commit->object.oid), oid_to_hex(&p->object.oid)); + free_commit_list(p->parents); p->parents = NULL; } /* fallthrough */ diff --git a/t/t1414-reflog-walk.sh b/t/t1414-reflog-walk.sh index be6c3f472c1..49d28166da0 100755 --- a/t/t1414-reflog-walk.sh +++ b/t/t1414-reflog-walk.sh @@ -4,6 +4,7 @@ test_description='various tests of reflog walk (log -g) behavior' 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 'set up some reflog entries' ' diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index a6de7c57643..7044c7d7c6d 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -2,6 +2,7 @@ test_description='exercise basic bitmap functionality' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-bitmap.sh diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh index 832b92619c0..6eaa692f33b 100755 --- a/t/t5326-multi-pack-bitmaps.sh +++ b/t/t5326-multi-pack-bitmaps.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='exercise basic multi-pack bitmap functionality' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "${TEST_DIRECTORY}/lib-bitmap.sh" diff --git a/t/t6004-rev-list-path-optim.sh b/t/t6004-rev-list-path-optim.sh index cd4f420e2a1..5416241edea 100755 --- a/t/t6004-rev-list-path-optim.sh +++ b/t/t6004-rev-list-path-optim.sh @@ -16,6 +16,7 @@ test_description='git rev-list trivial path optimization test GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh index 738da23628b..1aabab69568 100755 --- a/t/t6019-rev-list-ancestry-path.sh +++ b/t/t6019-rev-list-ancestry-path.sh @@ -29,6 +29,7 @@ test_description='--ancestry-path' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_merge () { diff --git a/t/t6111-rev-list-treesame.sh b/t/t6111-rev-list-treesame.sh index 90ff1416400..f63bc8d3da6 100755 --- a/t/t6111-rev-list-treesame.sh +++ b/t/t6111-rev-list-treesame.sh @@ -16,6 +16,7 @@ test_description='TREESAME and limiting' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh note () { From patchwork Mon Sep 16 11:46:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13805351 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 84097155CA5 for ; Mon, 16 Sep 2024 11:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487199; cv=none; b=Ja+1BvAsrqUDw8EkPJL4e56KWTwEx4loCCuRycqRcbLb4BJzAuWRsWOdgroMrpJNBNRZV/LzqPnACybtFaJD9Cu3pZ/e7MJFu10TwfVm12O5MjrsEDmOd40DLLqbL0Q/be61AdLnSJZJrrOhy9u+SN7myOwb9ugmRtd0ImG+tc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726487199; c=relaxed/simple; bh=x5kzF8CwhIlxyVtEPJRc3M5vdDPI9gNtSMvV+yBIDbQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KOCoMaHt2+PDqp5OYc92VpjuPEZaBoakuJtB29vYPxJ85N5OZ9SZcSa4pMCsOouOk3IWa2YK3Nco+UOnZBXKm+unUI1hGdCwQ3U4d2dG/447zV0tJ8pNtSLnqwlT6VynCPSflTCh8Owk/F3dJdppZcjp2y+Rd3P+MxOK59zR2mY= 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=Oep97oZI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GXVLtwn3; arc=none smtp.client-ip=103.168.172.153 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="Oep97oZI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GXVLtwn3" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9E7A61140125 for ; Mon, 16 Sep 2024 07:46:36 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Mon, 16 Sep 2024 07:46:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1726487196; x=1726573596; bh=CRciCBOMuh fmW1HHjAE7k6gAAaP0DvaHPl5bv42370A=; b=Oep97oZIVNDB8IvINtgOYe1E/z gvKYpYvupCQAtb8R5ejUZ14/Et9aTSL6SC3AW1gbrwtmfbZmg2VQfXjOFFvy7q8n R9B/9gOXky0+4YELPHiDepgNToUCEkSd61ScFAjkKt0s41C8VO8sd+xVW8rc9RuD eQCFNRmS5ttt6Bp3otDB6banfENQ4DV70tKsnNJZ2e0MNSkLu76p/r0uERZ75kms oPOnx6VaiYk/8G91AL0CDq9/t9ELvgUHsXPURXs8LtOHmd01Dh+J58VJ2Y/1vDA2 JVnxe50hq5Ys5E//QXSRnBE8fmUZYUSrIKJ2tYbCXrPIX+DWMuXMbQs71iHg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1726487196; x=1726573596; bh=CRciCBOMuhfmW1HHjAE7k6gAAaP0 DvaHPl5bv42370A=; b=GXVLtwn3y4ySBnMIwYmclhUcFH59bh4gV9Pl7oJ0JNnf XIYV1j8SSn3qX4h1KfBe31rbzQYfkHwTQ0uzAaNVNtd543++p1kP8j/8LlzVIXOt 6ULSpdtk+zl0CGplx8DZQHWKrmuuYrKqxOqHU8rtK5wjgz4RXPt+Jz0TTV1GS4iE QUNjPQiSPzg2yvXetf9AoHU8mpV8rtuVvGAIImo1wIVdoOgS3HrCDWUqjycoJIGp pd8PaMfSMbpYJJN/vYqwVABIqeukZ6+ubRHlFIvhNIDE4ExbgSq1x+gaOKDDytfM FzkuvIpnrjTsWDcuUaknZBBb5cH/DSuiDbJvLjvIAw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudekhedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 16 Sep 2024 07:46:35 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2a06f3ef (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 16 Sep 2024 11:46:19 +0000 (UTC) Date: Mon, 16 Sep 2024 13:46:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Message-ID: <57a3a9e9f8d400d3a3f4de1fa39f41ba80e2eda6.1726484308.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 merging file pairs after they have been broken up we queue a new file pair and discard the broken-up ones. The newly-queued file pair reuses one filespec of the broken up pairs each, where the respective other filespec gets discarded. But we only end up freeing the filespec's data, not the filespec itself, and thus leak memory. Fix these leaks by using `free_filespec()` instead. Signed-off-by: Patrick Steinhardt --- diffcore-break.c | 4 ++-- t/t4008-diff-break-rewrite.sh | 2 ++ t/t4022-diff-rewrite.sh | 1 + t/t4023-diff-rename-typechange.sh | 1 + t/t4031-diff-rewrite-binary.sh | 1 + t/t7524-commit-summary.sh | 2 ++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/diffcore-break.c b/diffcore-break.c index 831b66b5c3e..02735f80c65 100644 --- a/diffcore-break.c +++ b/diffcore-break.c @@ -266,8 +266,8 @@ static void merge_broken(struct diff_filepair *p, * in the resulting tree. */ d->one->rename_used++; - diff_free_filespec_data(d->two); - diff_free_filespec_data(c->one); + free_filespec(d->two); + free_filespec(c->one); free(d); free(c); } diff --git a/t/t4008-diff-break-rewrite.sh b/t/t4008-diff-break-rewrite.sh index 562aaf3a2a2..b0ef0026e08 100755 --- a/t/t4008-diff-break-rewrite.sh +++ b/t/t4008-diff-break-rewrite.sh @@ -21,6 +21,8 @@ With -B, this should be detected as two complete rewrites. Further, with -B and -M together, these should turn into two renames. ' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash diff --git a/t/t4022-diff-rewrite.sh b/t/t4022-diff-rewrite.sh index 6fed993ea0b..77bc36d5d8f 100755 --- a/t/t4022-diff-rewrite.sh +++ b/t/t4022-diff-rewrite.sh @@ -2,6 +2,7 @@ test_description='rewrite diff' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff-data.sh diff --git a/t/t4023-diff-rename-typechange.sh b/t/t4023-diff-rename-typechange.sh index 787605ce3fd..e6f4fe441e1 100755 --- a/t/t4023-diff-rename-typechange.sh +++ b/t/t4023-diff-rename-typechange.sh @@ -2,6 +2,7 @@ test_description='typechange rename detection' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh diff --git a/t/t4031-diff-rewrite-binary.sh b/t/t4031-diff-rewrite-binary.sh index c4394a27b56..1b8cd3e4c97 100755 --- a/t/t4031-diff-rewrite-binary.sh +++ b/t/t4031-diff-rewrite-binary.sh @@ -2,6 +2,7 @@ test_description='rewrite diff on binary file' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # We must be large enough to meet the MINIMUM_BREAK_SIZE diff --git a/t/t7524-commit-summary.sh b/t/t7524-commit-summary.sh index 47b2f1dc22a..a8fceb6a47c 100755 --- a/t/t7524-commit-summary.sh +++ b/t/t7524-commit-summary.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git commit summary' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' '