From patchwork Wed Aug 7 12:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13756210 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C0481E6744 for ; Wed, 7 Aug 2024 12:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723034649; cv=none; b=Uewt2QRlPxr/xOMyChsC75+8NorWOWAcKMsWCxcN6AzoX3mpIdmFu1cNDUQLh77YUhWG8GLszYB9ZS7vwQBt2Kpmr3PYKdPLUVuwXKrrBCaCFqPkiud9+eR9lTGUNf/d4k+RuaOfbTsYrCa985R7ysu0tlMlK3SjYldvhGAbnRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723034649; c=relaxed/simple; bh=cSjsvq54kHdKX98EhYGQyRpXvjtcUEM+9WFMuWBdZeA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aL7f4lvTun96bolFe0Og/cWC5zD+k0fNJGbAhMaCgq19u5mOvADvEvKpDC8lp5kBLxW2KkZjcXH0Ugez16GlsVgptMlYSvnPKZib3ho+yUsTxjE1GumVChFWEpvLr/aEZ+keyg+de2TmeL25wkydwOAMp273Ff3ElyvS6VGcr+k= 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=qoCpkYwq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kixGpZcB; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="qoCpkYwq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kixGpZcB" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2CFAA11508E7; Wed, 7 Aug 2024 08:44:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 07 Aug 2024 08:44:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723034646; x=1723121046; bh=1NS8aK/DNG ieuabCVBfZL4neZzfyFwW3rGOmHUtmYLA=; b=qoCpkYwquUrH7G+FM2Ixff5EQE jcbjO3x0h7Lc5ELz1qfuM8srVZUSdfrsP7p5kZUAZIwjFq4XC85t/D1hOyBX+4NM WXWSQqI9eSfk44Zso5pSkItQFxgj/oBbb3kOgr+0GXXj3Tgw5YYWemwwlAX8NKM3 ZklhZnICPXhUol8G8zoP4pxCCa88pSk1VcHJy2rwVn1iPlbC219h82fLA0d2uc3q swOx0wJzh7VACl0tZIx5ysdTfwXOdFvy2bA1UZq7PH3f1wFS6XJBjhqSIm71/ADg BDEijA6D7N7YeVo4CzDDFpwGYlR7VM5cxzVXTdeGVCe9awRgb4xhCTsQ6D4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723034646; x=1723121046; bh=1NS8aK/DNGieuabCVBfZL4neZzfy FwW3rGOmHUtmYLA=; b=kixGpZcBjWJnxG30ki0TD/W99ZJ3jPyNWJFSas9V5u4B RxE1wBbQU92prToajUMFWrF76n5yeI/yEOt0Jw9sqP+RCRZJnh33Qeq7F7j3PWJJ 90v92H9Cq762Zhk5+4eB6uLC5EqKtXeseGUNNwMw76+trAR3TghCb5N9fEJ5FBpO hZtYDk1GLAWxYZ9D8D17RnghkYxMMBx/lCIbSINzaoIQdQ2RIgwj9pOrCQ1xHMKS 6LZ+EuXjqAquLVj8fxKNIHIX1PbdJPG7f7W4IFJTv7ZrNWBYEniHYKQ/NsslDYme p2XF3i0m4WsL19dyfgKENQlCeBpThUQYvJPaeCz9hg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledtgdehhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 7 Aug 2024 08:44:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2cd8c1c1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 7 Aug 2024 12:44:00 +0000 (UTC) Date: Wed, 7 Aug 2024 14:44:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eric Sunshine , Jeppe =?utf-8?b?w5hsYW5k?= Subject: [PATCH 4/6] submodule: fix leaking fetch tasks Message-ID: <8f8371c18a5f0a0f9b1412605199a21db334e90d.1723032100.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 done with a fetch task used for parallel fetches of submodules, we need to both call `fetch_task_release()` to release the task's contents and `free()` to release the task itself. Most sites do this already, but some only call `fetch_task_release()` and thus leak memory. While we could trivially fix this by adding the two missing calls to free(3P), the result would be that we always call both functions. Let's thus refactor the code such that `fetch_task_release()` also frees the structure itself. Rename it to `fetch_task_free()` accordingly. Signed-off-by: Patrick Steinhardt --- submodule.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/submodule.c b/submodule.c index ab99a30253..f027a6455e 100644 --- a/submodule.c +++ b/submodule.c @@ -1496,7 +1496,7 @@ static const struct submodule *get_non_gitmodules_submodule(const char *path) return (const struct submodule *) ret; } -static void fetch_task_release(struct fetch_task *p) +static void fetch_task_free(struct fetch_task *p) { if (p->free_sub) free((void*)p->sub); @@ -1508,6 +1508,7 @@ static void fetch_task_release(struct fetch_task *p) FREE_AND_NULL(p->repo); strvec_clear(&p->git_args); + free(p); } static struct repository *get_submodule_repo_for(struct repository *r, @@ -1576,8 +1577,7 @@ static struct fetch_task *fetch_task_create(struct submodule_parallel_fetch *spf return task; cleanup: - fetch_task_release(task); - free(task); + fetch_task_free(task); return NULL; } @@ -1607,8 +1607,7 @@ get_fetch_task_from_index(struct submodule_parallel_fetch *spf, } else { struct strbuf empty_submodule_path = STRBUF_INIT; - fetch_task_release(task); - free(task); + fetch_task_free(task); /* * An empty directory is normal, @@ -1654,8 +1653,7 @@ get_fetch_task_from_changed(struct submodule_parallel_fetch *spf, cs_data->path, repo_find_unique_abbrev(the_repository, cs_data->super_oid, DEFAULT_ABBREV)); - fetch_task_release(task); - free(task); + fetch_task_free(task); continue; } @@ -1763,7 +1761,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED, spf->result = 1; - fetch_task_release(task); + fetch_task_free(task); return 0; } @@ -1828,8 +1826,7 @@ static int fetch_finish(int retvalue, struct strbuf *err UNUSED, } out: - fetch_task_release(task); - + fetch_task_free(task); return 0; }