From patchwork Thu Sep 26 11:46:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813317 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 75A8615C133 for ; Thu, 26 Sep 2024 11:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351169; cv=none; b=jfZ66HCCLhm6sEF/4sETlfM6aOwFhSoy78X/wF8Nosl+9M2z07oahyLR5ISjR4V2wIeEh3gaLKHu9jeFUqVBEGNppgIg/nUORocKQY3EeNhwW6VSH0YWQccB8oeNyXSr8lRc6/qtp8ejUQfhdxjeVgMS7jPW4OumpEGwX14Uio4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351169; c=relaxed/simple; bh=lNcvcT0Ptll5cEtKf32WIi4ORKzsbi0qptuFZwI7xak=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h2ev2lzAfCVkEPaOwuWnBmxKCLt9ykNHvstutyP8CD0ED0d0LpkDM4kuqIVPq1MYI2Q6O1lTm9o/se0ALgvwrnTXVOjdW0QIjIotWGVMnGLJemdSwVWrnHH9dvWKD/Sw3q3ki/XZlq4bzL88ULyohVeMiEYTBzSXDaKedDHf27Y= 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=VBAL8Jdh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lkVZ9mAS; arc=none smtp.client-ip=103.168.172.144 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="VBAL8Jdh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lkVZ9mAS" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 5BACF138052D; Thu, 26 Sep 2024 07:46:06 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Thu, 26 Sep 2024 07:46: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=fm2; t=1727351166; x=1727437566; bh=r78A8I/csO Vzz1KLgi/TG0c4X8b0TGyOr7EvOV36vbU=; b=VBAL8Jdhr2TByckFHoO/Tl4gKL Aju/f3q9Vjwrd4dwhxThaU0m2+soeTBTgUamV8LDKa4i8+DdXVDYnEUCzYMe/86m V0MoOkI+dh9hEq4VrNz28vDYDcmnN054jphS5jZm/7AMqbDFNtFsfuUUCnwzJ4j1 iiMbsSmnp/fP0rlwL6lDzi3OYvBm+8wh09sdR/6GFWuME9WNDEK6qJGDxce5EDS4 1Y74zuyYtboj1AwYN4LYDE4GP9kC055uGu4M5wnVttjpXBmZVj3VRD6me245SHQ7 kExWBf4MM3SIcn3FN4XEXt9qYsfDOKf2VvYFOQIeyVpCpMrgE3L1iZDysj9w== 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= fm2; t=1727351166; x=1727437566; bh=r78A8I/csOVzz1KLgi/TG0c4X8b0 TGyOr7EvOV36vbU=; b=lkVZ9mASm7vv5bE/FOMytm2HkzseOXAYCXHKopeFZR+M Vv/1WQO1xBHZjm+ClJtMUsIQg3SafIl1sJeRYTSj+BpADwNwJjcC36nolaDAODAF BP/RjeOmZM7OnaonJEjOvZto4mpEJ0pwhsHlSxfJfWXGPgBTxfA7rotiWmYGY8v6 gLHqay03zJdz1DRAfiNtoIBFnbXXac0NT1P2uIXoMLF+6YVRRK+Rv574vR5zDeYJ EciSIeQGRRI2EyruUPxdnMVB4prON9JF4pefNWKAtoZqqZ/u6fsKk3mIEmlf/def n+XDOpMGg9EDa7+6Q5taqoY3Akj62fBlV9YBKBCeDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bd644710 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:26 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:00 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 dc1fbe2b98..282ea5721f 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 Thu Sep 26 11:46: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: 13813318 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 9EA87170A01 for ; Thu, 26 Sep 2024 11:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351170; cv=none; b=vBbyO5OnAIDOmOr/MpMFw5NR40AIKNacH1Sz39KH0MI1/H5VtIDkkBhgtBRZh+A3W/tsX48cG/kJ1AAcL76U8Kjda7awR0bzHQIiku7yIOoDVTGAcXARK033WxmkJ8PXMOmZdXO6JgU0+QHTgPWCjMEnYmnHHLKXMSmvflyTc1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351170; c=relaxed/simple; bh=4B+yInSySv8wYLvDqalGbjvpIwx6ZQqB6o/dYdNUUbQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W1fC1s+J5hS/Ecp0NH85Kg4sLkzAcLx6sqA6xBlIpUuM+mTs8c6Km0bToB+knMxFHiciRjYYvA+4BsWgJFmtZV3GWev5Ygblksf0ze1ku2AJ9mEu1TVRb/7c4E0qBU66PnDvrEetKgFdJBYlMPc/GYxCQhe2tP3cyN+FzVfP9r0= 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=st7VgMVV; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KNCkOyiB; arc=none smtp.client-ip=103.168.172.158 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="st7VgMVV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KNCkOyiB" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9A7CD114028D; Thu, 26 Sep 2024 07:46:07 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Thu, 26 Sep 2024 07:46:07 -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=fm2; t=1727351167; x=1727437567; bh=DG4+Zt75eX JWltJbH8ZW0p8onZyKD2xTPggPIXGVa+4=; b=st7VgMVVgpV12aIMmC48lCmdCb T21gTGJxLRB3rfnIhROIluI7K1yuuYlxWn9uPS0EoMrNbGa/065xebvA9VoELK48 WC2/gvXqi1xyUrqjraSQf15CtRI370MkZ/6OyIyH/1KBAHPXrzLiw6JrBT2A14tv YFH1ktgRBobWqSrXDjy7B94QMUHgMc0Kz7pNhDihLKfLm/00tj8PQ0IYirx/RK7z QIghis8OAixW/1lguzyzD+OuUsV42Nez1zqiBMKSD729mK59ibvhgy0AwFDGgBhC Cy9KIxlW6uDyYG0byYiyTTWOq5jLNRvGa6tDy+mdxPgQDm7gByax4+ILJr5Q== 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= fm2; t=1727351167; x=1727437567; bh=DG4+Zt75eXJWltJbH8ZW0p8onZyK D2xTPggPIXGVa+4=; b=KNCkOyiBVuXg3bBIEHWs53/RgnTro6VkZczWFTS7JSdC QSYeOXD8XxCLmOLTVu+uv0LXG0/2JiLnuhqyvCKeQQxzja66zInO0uSk7ze+iYxM +Ytqy0EtjmuZbKpAOz9vOcLbQl6Kz4Fdp++kUZG8Ozd4UT4S9W0cn0ClEnH6Q2fj cDSyM1t1KjoNl6HXzhwGqRyJHP4KmvUJpwmdqcLiuKGmmDA7U3WzoEtTkRd11Ytw +KgTPoFxet/HxNNh4F4d7PdtoMRQLM7eKEVpxvS1KUpptaftL3HWJOOVd2w1SDeS I8rq+fxmbNY0jIWym0/TenQDJu7ZDZycBAsY6Kj1Og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 986b3ffe (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:28 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Message-ID: <4a59fe15ae30548164d1433d1d96fb2726512cb2.1727351062.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 282ea5721f..2c249cbca4 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 Thu Sep 26 11:46:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813319 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 D8410175D2F for ; Thu, 26 Sep 2024 11:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351172; cv=none; b=FbnPTiSBiqrQ1vraNzuRkvGsFRzRLmLOURFltBiSh9MlBA0v3YNtIRMKOUFgUTr4Bg2Hxkvf2ii7Vbda6ugc1LkU+U/osnR12RA82/AlXbklEutjp6kfm3+PIkeYGvm61X8o0GnKxGPKK94m6SfnWSGKYp6po5IbudQlvJZi8kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351172; c=relaxed/simple; bh=N29Z6FCFX4LIYLi4VuafNX1bdgnYjuYAa0dOszjbEwc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hSn/9vxxmgaU+ZgUWnSmNfq37XUZQzIBzq+wiyRWgYuFJdzIRxU4HJBTiC5tgP3XwWqli/CWfQQ5U3+LCV6E+Hy+JUH19kyacSk+/GH5mACRj1oA5z6hzqyovoAUD65Hz1juTftNyfxJbiKqFnLjO9ihEIGwmLNBeunQ28IzhcU= 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=AIMntsZ9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=G/JVKWXL; arc=none smtp.client-ip=103.168.172.158 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="AIMntsZ9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="G/JVKWXL" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id E74981140287; Thu, 26 Sep 2024 07:46:09 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Thu, 26 Sep 2024 07:46:09 -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=fm2; t=1727351169; x=1727437569; bh=cOtAXVypPJ zDa3172izHSAEX8Z8/gnl71DjQa0yTJGo=; b=AIMntsZ9SPPq2uKP8uhbKGtpLt aQW8fILP62GqTiEv3pVGq5H9dFaOhOpASX4ZV+ad/Gmwpq0QMtV4yS1u8AF1Ree0 kRIiU4vLd1R+DSOYuxeQeIUxGwFRJ9cYzbXpIYaQa8naKHn/K/jQlCnTIdkFR9+/ vbc9XU0a6WDvSlBB8026ihKhce0JBQlIWnc/cu3YaslVny0h2BsndcOtI8z4JNR/ i/91YG2efkhKzfpr9xJD+45LNaW1DzsM3VZxuXFQInmfh8hLeuWd4cXPMp4mBslJ Ot3Ont00PXxZfCQreUiu9F9dN3j7GaezhGF519mVEG7DGYLnePgR13IMcWbg== 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= fm2; t=1727351169; x=1727437569; bh=cOtAXVypPJzDa3172izHSAEX8Z8/ gnl71DjQa0yTJGo=; b=G/JVKWXLiOOjERid0SzJvRukM85zb3S8gjroH1JIHyYo +3pRaKMi3kc3AVnTna8DuGq5T26LhwOEBMVXlNJRgYlhBluOj+cEbWUmRXn9c+OB OKjza0zY8tKUVMhr87jFi0+dqOc/3U66thcq8WFHTxs4joaklpuivzvVw38ANUp9 Wd7ltYfyIRrZ7B58nQZ69C52Wxn3tx3sC1UgHUgMI5ubfpgLeJ/iPEJXj8vESsHy pfkaJO6yoXfsM2lKgD1bdCPPXD5JqFH/ND1h8QjXlC/OWdZvPDCOgZlJO1eUA5pi jzLZKZ8Msl0Mg44Ty6KhVdBC8dO46qZppbxjpljfPg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:08 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id afba5aab (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:31 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 9a618a2740..3c7fabfda2 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 1d273d91c2..9eae0d8356 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 Thu Sep 26 11:46:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813320 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 DCD3517AE05 for ; Thu, 26 Sep 2024 11:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351175; cv=none; b=O8ZEIy6/csseXBCf7YTfBLneVLGdnA5zLwQPW8/6h1zl1mNKHEpCmQqnyKDAWyPK7QwZSU3dA9+PxSbHZYfEcZ2XYkWDj4tfQn1aricQarrMl9nwPRtX0sIaivV2/xETzgJxzIN+HQPx9F4m7U5qbry/XGryajBXv891mcYb/O0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351175; c=relaxed/simple; bh=5H2PcYOus7yTdW7d9ENh/+m/SRXz7dqfPokhfYQxcEQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HNEimmD+yRGNNaed0S8aMgFVqJqMjhy2RNlxfHaO1jNJUgeRnSrmlDIoZdsBYvh6BUYfith5NblGfn1BsIkPembyRjroGIplbcdljXkoP/aDysue+28UYySIqVF8VSvg1rQt1i5cvnuTkBk6EwmNYn3PAqshSz/XoHBlD3BZ1mU= 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=px54YGYr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=m9T4Ep7M; arc=none smtp.client-ip=103.168.172.158 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="px54YGYr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="m9T4Ep7M" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1D2DD11401B1; Thu, 26 Sep 2024 07:46:13 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Thu, 26 Sep 2024 07:46:13 -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=fm2; t=1727351173; x=1727437573; bh=FrZTdVLJ+c NH2aXeAlKtxeLk5aa3PbgXMvoewntfgWs=; b=px54YGYrKcunXZWxO6G7ijiV34 PxTyvQUC4LY1Lczb0bzbj1ZvdqD8aXP+hlOFJkVAf0aDt+Abw0hKqJoHQ663I8CE XbHB/cU+D23kmV0MtJoiHOoXaKl6kAYc/6ARQV20t3q8YRRD0cUH30hft3C2bh2g qvDfWw/0w3vd0UJGpcAEJjbW/Tp8SKAzOsG+YXxgzvVuhGUab15CJ1mzuKTGdNa9 OgktfV9MauGqtW8LOGYxgw1n4YrUmvJd8wrXHXLWoAjIDnBf8rr8cjhpGtb8bWa6 /T3JcotG2/ELy+BXGFedWyvqNoMeLsbIxnBtl5xPGn93m52BIF8oQM5YIIHg== 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= fm2; t=1727351173; x=1727437573; bh=FrZTdVLJ+cNH2aXeAlKtxeLk5aa3 PbgXMvoewntfgWs=; b=m9T4Ep7MtjXbUGtd9yHB/Ier5JsAU0/y7luZ1ctWJR4X HKFvcxWdO6QV/A3vfsYHWRO3zcFeXN/3HJJ6y0qM6svX0M2a2bNdFGBCHzXiWtc7 seNv0xQRdqkPGKInm26eApON7Iuf3LEJHL/d2VHQtmNFdeTHLsOo6Vk4u4auITRu wStf2/B4fjQlbLRUzm5syu2z7J7jXs44hlUVR1GjdPQ+lqTO5RpcdNnGD+DlgiV8 8OJJCBw8u4E7kir1hra4+Ir7UIZyc1qjyUlDuaTEx3sgglp8z26MRCXJrpKqIze6 ZBa/N+5zKlsvfql2o14HR4LGJKRPAvkQBu5gAAMoSg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:12 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e579ae4d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:34 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 04/23] submodule: fix leaking update strategy Message-ID: <7cdd2691b77d328447855f898540f7efb2a415c3.1727351062.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 bf8f9a4012..ed05dc5134 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 c8f2bb2bdd..471637a725 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 97d0d47b56..0e67984d77 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 b50d29eba4..4deb1b5f84 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 297c6c3b5c..0f0c86f9cb 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 Thu Sep 26 11:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813321 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 495EA17BEBD for ; Thu, 26 Sep 2024 11:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351177; cv=none; b=A3yNl40DzhR4jUBG6Vp8/cweL2qlifsjBf+z0c/AVMQ7mCA3Vpl35469n9MxWtyrT9xdsgLf62rJjzz7U8LDBcv1JVc9qUHRXIDk/tQGMVqr06v5LWopHysMf5OPh45ryEN5rx/1vNQIyNJFHIcKURyuEIFMnbYP7RhE2Umc3M4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351177; c=relaxed/simple; bh=YJegBarcpHygr7d7rWW6JdWTzpnGPQxeargJYD5ckZo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IGxaWHpRw7gbXTejFXH/W0opeYtU5cnifwBUP7Wsxhx76VMusZsos3AqqBzEN//VV0rjYYhDCdqOV4cb5J9m97k54pBQ9UyJr69OU01+hssOacscPGLTzKIG+ekgYPyMG/mjic4SizfzFlonMIeQ17lPxZQtzFL02MNjFn+p6u4= 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=L9j5eurl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JCVSHQO2; arc=none smtp.client-ip=103.168.172.158 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="L9j5eurl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JCVSHQO2" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5E90B1140242; Thu, 26 Sep 2024 07:46:15 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 07:46:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351175; x=1727437575; bh=3nBpF8mtMZ zcF2o5nsFgKOIIC63o3U3tDzdMuOhD1rQ=; b=L9j5eurlnm8bpnYiUKOKhx+5Pr bpfwDhwUyPpoPaCg0FQv6hjTXJDHS6DL46taWAclbpo9YFhBKRX3baxGTcd7rtS6 GZhnV+NrqC3+42FvSldJVqr4p981hw67ybkt2ZASXeNBJK+o+L3Cyc0K7wi7I6C3 tcdINCaMsOSvN/biLWWv0R+LSokKSpuCFyy4cJmoRDgfGSJ1yiEhu/RX01y5jtng Bj9MDHBYElqBwziTdaaYKoF6anK9i+ZXo5Zp4wTqwRFCAUQCIPCik1Jd6vdznsEI YGk2S09IAJSKj9QlEInDWeWzcNf24BMsSItpjoqChKZ38F6C8GQiXPk7bPTA== 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= fm2; t=1727351175; x=1727437575; bh=3nBpF8mtMZzcF2o5nsFgKOIIC63o 3U3tDzdMuOhD1rQ=; b=JCVSHQO2KrNTLse9GxSBmbNa9WtnmIw7quFRfPmC82wg 8dD5f8xFLe3eSbA9ccZBeS4/X8rBrikCIwbCs9KKY6Pdp0+iawTuegSrkLmBp/P4 zjUtHxyAeKKahfrTvBTY7n8L3s6ibxxV/bA3N71IjOqmVcL11JDvFbqgjz8Wifub ARUwT9GEqCErY/gRl1N1yzgp/358keiHtIItSVJ4NCVBPNWoZiTzEjb1jE6lZHs8 oaNmcytT1yB3yrRhq5kQiqGtg0lXUBP5T1WLZROkT0GUy7IjoqWJqgcDjiY1QPZT C9v9zfHwpFvXi6dKlm1msrLfHrKkNzW9QBkn63zvUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:14 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f683e52f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:36 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 05/23] builtin/submodule--helper: clear child process when not running it Message-ID: <0d0964a2bec7c6e6375a65a5ea9dc79a18ad325c.1727351062.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 ed05dc5134..fd1b679408 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 8d7b234beb..9f68893261 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 Thu Sep 26 11:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813322 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 509B515AD9C for ; Thu, 26 Sep 2024 11:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351182; cv=none; b=imxkpuvpdtSgKhEigdfX3ED1n2fB+Ptuv3/CjTPO1PSA9ulmCgxAaLvelFvNUnvbBKDRHlxztQOAWHdAqvaUBhy6W8H2N1redouGLfVH3Oyf0JdB+pApxc/nt26i7vFbzckfDEP6X6+9fkJBXfWpFr/I3Av8wMhnaW8OZgMEIjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351182; c=relaxed/simple; bh=bGu/PXxKaHnHMs4sPvlSoj+Nx7CrDWrZtiWsPKxFMbY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cO5lbagpJv5jhpG+7M2d6jZCz0Oq2c4wbnFkQ9p1W5O4CmselOgQaasF0mrFNkkEepJcmV3xoQMKz3cnnRq1o0aIc1QSF0J2W/T/42A7P0tjN5GXJww7lf4WkRs0Oz7dS9HqZ0NdhmGU1kyI196BovcDEXSI3lrx3c6g3RfLc4o= 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=mwGfGCol; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=R566r97Z; arc=none smtp.client-ip=103.168.172.158 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="mwGfGCol"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R566r97Z" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8C37D11401C1; Thu, 26 Sep 2024 07:46:20 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Thu, 26 Sep 2024 07:46:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351180; x=1727437580; bh=gs2WHV3oxh 4JybMSCOA0pfVrISrAbMFEd1WNL38fA+E=; b=mwGfGColgnHg4Hvv1uxnA9kwdz kEw6rOl2mGHZ5/3Qie9oac++WCP1sGh4NVN8Nm4R+Dpf4WogyxV1ILJxhvIOZVw+ uoiGSHYDaa6EqGvWQqSHb4GUMIqqponCIwdPq9p48qQmAw6pttWqsMiPSi/tzZaN 9ZSv1r0hbQLN/ONUkAg5Gx4T4gA4f1SJqbi/9xb57GwWxKa5aWlJFTGCpBa/bUzH kaaZ+9OOjhkV6EotKTvRwFMgI1GX8CMJTIJFYt7Gc8n5ygvfg4/pwdwqWjqhv0sa 5FnN88Ie+bpSgQaRqCyhpe3Hegm+pV8YBPh1Lf/bnFUVAnCYorr4iDj3uQIg== 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= fm2; t=1727351180; x=1727437580; bh=gs2WHV3oxh4JybMSCOA0pfVrISrA bMFEd1WNL38fA+E=; b=R566r97ZbOsL+2fRHfmwp6gBY8zbjkEv/DXHHgJjfZWX 9kUKYeKEHswgiNQN0iu/F1UkXEqqxQixtUFTp87/FxbC3sm2oMXzjrEU860fUO4U Ypr1EPx6cUrYxy0CHqZLrcsTX2YBBZCp+okMVfTBr3RhwF+fzCj4Waxxkkmhlhj1 LQ+PC36rrqq0NMKpyIRQta7YY6CIca2tHtRLn7pCItX7+A1uuMHle3ZNF1iuEiE5 P6uV4fzgHMncZdU+AIvQEMdEvR7USgzDxAuUwjVImtrHhd0EOsLBn122M9MGmQRe 2JAwy+BmjsMRiFre/kkH0foZVXsVUAX797ooeI3JCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:19 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bf344658 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:41 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 06/23] builtin/submodule--helper: fix leaking error buffer Message-ID: <52d12e034b8104a0283958ada013b028322ce421.1727351062.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 fd1b679408..ff1376f69f 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 d6040e0a33..7e1afa9ce4 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 Thu Sep 26 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: 13813323 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 BA24717DFFA for ; Thu, 26 Sep 2024 11:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351185; cv=none; b=EmU7K+bWaXf3iD/eqIqpfvR8RdsCqmTDW+soA1QCGAJs+/jZ39TrRC9ez+Q0LsNcQHydhkfqCX/GXlWSGtvXRA8N7sNcgoGmnymSuDKcx3YB0kjO1PAB8j+wW/qMmvLNAhbdi51Qde+nFZIRnflicqTj7k7HIFSZQjEQ0gpuvoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351185; c=relaxed/simple; bh=c0gLBYicabY24G8XEXHPL4fSlX1bzMv/kl44c2dJ2yw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Dex5pFtzpO0z+RqMUWOq3OyOA73Z2PrXGFKSHoXDnzlV4VRRcqLldh1d7OCU3FS9SJHENKe+XrpalxaEFN13qs3niWRp/YLj581flDvQNQdLp0HzR0/zVkMre3MRyq6VZQQH801/3hFgGPByWgdpdhTM8YysJaJhPm2+wG2fi08= 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=ZNrfWheQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OObAVtMG; arc=none smtp.client-ip=103.168.172.144 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="ZNrfWheQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OObAVtMG" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id B8506138067D; Thu, 26 Sep 2024 07:46:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 26 Sep 2024 07:46:22 -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=fm2; t=1727351182; x=1727437582; bh=i5CpnXiF8L Gggi3liHGf2ZjAZJLvB2W5QmTro5BDBvM=; b=ZNrfWheQFJwzSCKvdwMoz2kX+X 2sBnNkLshATxnpbzUvmdseZcOIDEgdSiY2ELjYE1REoP6rxCNHUERazcXu1BQcDh w8I3jpIsRVlx0Ed85MchQsd6D4UsScCQO1Ptt70lElvoA19OIujz/zz52LQdmpGq t3UVSQqrpFWbrToAqfe1+pw3ce0N6P8qC6VKDEedX0Kxcv1xcMKCXoHTKoUjhKnM yU1AMugLPDqY3rmJnUqTE+Fho1CXZ13bT8Xyzs15x97vC5JNk3lzBIonDUYwbgeF tV/pADDPjR/BgrUpHapFXCN6uyXXTgnoLF37eevp4+EMGLC5/p9+KYiPiCNg== 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= fm2; t=1727351182; x=1727437582; bh=i5CpnXiF8LGggi3liHGf2ZjAZJLv B2W5QmTro5BDBvM=; b=OObAVtMG1kIDncplgts+bx7MUpboU82uFK/OScAfKXHi E/OVnQ648Z1wzXttiYrcmfplT0PkUQswJinFqN9al/KfuQ7h/Iyo9CvJgGgUhkAm Qgp6CnY7FlQ/nEpnCvCjfIqfdboSt4+i9eiu1P4v8xprz/GfINECbKqxPAWexxip Z4s1eMUa7bII71MkInmwGwx+EMD4OzHGSt2pRRxJ6Oa7x2NL+zICMfHXx16m28ji bW0dIixXO3Y76oLcTK6W7bOibHSM20xhZ9LnKIqDONsWFXE62dscuFcyIsEko+T3 9bLCVxv6KUcPG3I1dJ9JHJ1C0Ka2/7RqaKx2SxJBbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3c693832 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:44 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 07/23] t/helper: fix leaking subrepo in nested submodule config helper Message-ID: <96bd7f01d5d1800a0d0520c0d790cc524e8b4c8c.1727351062.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 6ca069ce63..6dce957153 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 31271f8e0a..af0de496e0 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 Thu Sep 26 11:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813324 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 DEF63181B82 for ; Thu, 26 Sep 2024 11:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351188; cv=none; b=DTDlA850Q5BTlZ8tmcFGsUUtQ6pyEM++XkDaht+GSShCAOr6tVGMS5rNYI5zNKbICoObqENngW+nl3RUshb96JefY4RAR6R4KC4ep447Fz1mJkbmWjJaL3pkdM+5Gwez7p4ptn+nU5pi+buYlB1XQao/aneRnqgAljcamRPNK5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351188; c=relaxed/simple; bh=m45xsLzZm3+sQx2D5IhJpk731io/BkNE0zJFW8aStvY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fNHhQQX9SUjlU//5ecbRvUS/aqcEZaWO9s+9PuqWoHdP6puILeOgk5Bw6sm+b/VVRVdilZjdR5QjuwnlJAU+tTFk/ht55awa8cxniil1yCNzfVgDzbyuyO2SkO0T+XS1UTqb0vgMC78WEg/FAiu2c1a22dRdptMi1MH6G400nW4= 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=bRdCtLzl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FEY18MPO; arc=none smtp.client-ip=103.168.172.144 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="bRdCtLzl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FEY18MPO" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id E7A63138061D; Thu, 26 Sep 2024 07:46:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Thu, 26 Sep 2024 07:46:25 -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=fm2; t=1727351185; x=1727437585; bh=L95vkZGbZs xHfGmLKvTKlID5Ma+LwgS3inQa1DbKyIQ=; b=bRdCtLzlXU7UDXqGzBpwqEOtE7 ilPy2NHlWSgeQa4FdHrv+IVzgP1JeGuIYnUz+i8RmGXqw8Ak5YU094QLGYfey3bM MqUkFpGn9rOzVvRnJLMkwvLsfHb2KcnP9cUjOXZuASMaJv7ax4EYW/aNlpVGXbGH cNE7mSlsAKWooWzrbZfr1gBFRwB5xJxqb+P4NPloHKnxyZrukJnr9kbXyZL2bDoL UY3S8gZYVa0krVa6fe/Dy2ZOAgWGSYMZzQDM66gwRdflwh+u4KDBBwF/Plo9oKQc lOp4bk00EhJhTPurMpd5J5suDJIKwrJzpDAfCbfgeJdc7ApdVEDufqFLQO5A== 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= fm2; t=1727351185; x=1727437585; bh=L95vkZGbZsxHfGmLKvTKlID5Ma+L wgS3inQa1DbKyIQ=; b=FEY18MPOZqg6gVfUMjUsMEqST0BvOrtZ4m+iK9nLOWV/ r5FsJ+Vd6vXbNQjZ+jgTfX0cyg7ksh3pcIO4lLMtGA7YhVxmuZ7ByBf63irH06Sd rsd4hWtNKwNK1IVVLTpds5dLx5oyUHrSffYChrA6j8aDdphwOovlcy3/J5SzTDNm x42EA/iL9uEzIEb+v/mPCusKY5NeA8aP9R9ptl2pPNEVWkYpIcYbCfNl6hvqH6gW VhZI1bRvtH3LxY+nswqS0hb4tywlKwLydKS1I9PMI8Grd35q3MSDtbN6hb5a4yMD PWb0Z22xLG/PhGrYyLo6i2UlTUddtEUKcg0Uxr4vfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f4f723fe (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:46 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 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()`, which only causes us to print the same message as `die()` would without actually causing the process to die. We don't free memory in that case and thus leak memory. 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 ff1376f69f..a9bd93a785 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 bf7f15ee79..d7fe910bbe 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 Thu Sep 26 11:46: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: 13813325 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 12AAC1714C4 for ; Thu, 26 Sep 2024 11:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351190; cv=none; b=kOxtIPRLVwbQSNgQhGz7sQ5ad7Q05GNgxHi6/dWuFQP/wmGOVl0qa9OHGDdLAup9qDY73lYYu1GcR5SmbtLeAlNNvutNt22IdCOg0fx9ZY5e+CVvKsDdk2CDY869WC5cPm2kt4KzbjyWnLZolR4bUz73BnAduWDvSP8xMF4Ehek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351190; c=relaxed/simple; bh=CTTt5zg58ibnysdgV5vTdz0h56+m7eXqCbK7qVfCidg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pnaNI7QXfAvmUVl8IzwzNiFiIkD63JWfkiEHj+bVzIdvFGBoUOTOHtFHG0l7T+qB+s1NVHnUGiOlhMXKP4EXYET+533btXnXygJ6r/Vk2QqQBx8uTUqq3TCqYljycFRNZW4B2EQbCJwN3kbOUDxdMm4CqhBUGSoJYrVKUJUiGEc= 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=l9UdUrFw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a/wyqPuD; arc=none smtp.client-ip=103.168.172.144 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="l9UdUrFw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a/wyqPuD" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 10778138067E; Thu, 26 Sep 2024 07:46:28 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Thu, 26 Sep 2024 07:46:28 -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=fm2; t=1727351188; x=1727437588; bh=5krodC0Rw6 0VZvL9vJz1gZVB9qzxcNXAJGu/JcwQGvg=; b=l9UdUrFwt/mo2NMzFmWSo2hHIh 9hKFiNm1H3YSA5TVccXUTsNY7ZSe07zhl6VGHcnqTvd5vDcu87ao73i8vFJKwO6e NY3EF4vBhtCDXqt6Kq1niG/J4b9d+nHl6oyQ5lRObCOf0jGiCvN6YMqLHOfMhWRb 0piMi2ApN4jVoTpUICFEJQB6mfMGdm1vLtfMcNheU0B7ac2GD7f4pKCv8mJbN1Bx IJkpK6P3iGuOeLfPBRMfwpRHzDi3xyX5MSW4ja4IQMWpi8Fx+dgIyvnr5q/bqcSA 8yg+4uXQsNnOulG4aY0sBZBvDM+OL90HSclX+xEt8O3XzYPOPA3OqbsAxCkg== 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= fm2; t=1727351188; x=1727437588; bh=5krodC0Rw60VZvL9vJz1gZVB9qzx cNXAJGu/JcwQGvg=; b=a/wyqPuDuQkqVH/mrYue+TGKi31YjHl35hH76LQbJ8cg 6Rgpa6UQfmRoOBgRA0jdYqDrokP2mkj2Hetk/jeQ3aQwcEex7X7jdFoHtbrwZLYA KMhMFvsNo1+EX0G827G5+EsberNAAvyAOCUFM7lvL0VqXWelV28M6UHve5EyWVZs vEzOdBjCRbscpbKpNEcBt831hRXQonCCNeAFFm3lUqBW9HchBxDZ8kplmgVsFYTL 59cR90ewH4XNQEGmU2ihmnHpclxS4CwlctrvBYQEc5F4p1HYDLZhaX5HGlvNwhEg OGj2vdNHGqk2qXyDKaN1k6oEYAY51bqLGBiUEOmfbA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3d35125e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:49 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 5a23376bda..787bcb7a1a 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 3da5b2b6e7..69e44c387f 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 2f9bea9793..64145a05b1 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 a88b02b06e..edce10f998 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 Thu Sep 26 11:46:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813326 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 1D29B184101 for ; Thu, 26 Sep 2024 11:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351194; cv=none; b=gdbNBdaLl4qElqOUxyBM7x74MvClcCpyvHE9eJbnBpwWeeuSE9ftvDhvf6nu4lXTfoJyzsJyoRKajA1GnKcCEG9Hp5Kb64SxyhkCEFeeTHymiGyTA5qb/BdeTWLlCIqRAEnAUVhQrOOq28cfdJ3Jsbdqp/7WESQ98Sz4g2E1T04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351194; c=relaxed/simple; bh=HDjqDwizK+SjvKJjEDDf2VPW/GeJMb6TCurWfoPtIYw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tWXx6na+70lmxzAqsa52pdaHwgYL8Tt7/u2LqNzdkmCDtFs6vGP2xUnnmBGwcUcwPFYn0vhbQ+57nLWKQqi2ABhqRyxQWQBhmd1Y0URDu9WtBjInfnmbhjir32/TzdllcyGSbCWh1IRhGrGXdYsV333zEY48+Rp4a1E4bP7D3gs= 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=sJ/CjrL+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qIPitmDO; arc=none smtp.client-ip=103.168.172.158 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="sJ/CjrL+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qIPitmDO" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 3BD37114024B; Thu, 26 Sep 2024 07:46:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Thu, 26 Sep 2024 07:46:31 -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=fm2; t=1727351191; x=1727437591; bh=ygYBHGbj1B YAY7PiiH9PleYauqmsPzrfI10wWmvES1M=; b=sJ/CjrL+TVEg70+iU7PSilLGSE 25EKAP6VpNZ1gAwfMiv4sYJwvagpjCy8P4FeKzX2J1v1fSbUrV5T3Y8EkXAOTUy9 hOUwSAKBD9huNiBodpRMsf7jSuhWeqo5ImM8dWwCRVMHfyavQrD8nL1Po/pZAYRI Q3ofj9JD34FY0QO192NqkjdfzasNCZ4GCct0jIklqgdha4FN56LU2ZyKznW5A6w3 D1CwWvTIKFpWKeSTMlpMAr4zvq2S+r79vVDhE/YYeksOv2jEcWSmVDakkGY9AYBg NfCh7bcONzr2OtURTDUtamvs/gvTffD2LZJTj6M3Wj+7ICCGwDUbrOJiJDTw== 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= fm2; t=1727351191; x=1727437591; bh=ygYBHGbj1BYAY7PiiH9PleYauqms PzrfI10wWmvES1M=; b=qIPitmDO0iyBj1w/UwjHOFv4LHbBN2/yQN/QePCOlI0K SHj/i/03p4LLU1YGu4shtO/kALEjlcL5ZHuHn7yvMzVvbLsuR9K1JkZYg12FxxqY c3/8QMO0KXc1J17t348Z8+UmaNeAz/u2+08UbHnp1bq8E3y3qOj2N2MwQZ8vw0UF Citq+hILz8PmSX0iEkbgYVY69ElLqbMihnRLCUrQ2BOcR9OgvCaP1NfjEiRc6QEA 7wGMwTjM674R1sIsDd6tufDnkGoSQ7YnUVcLFqf6PJhQluetmiDxgKDlyaDRV/sv OCPta95hPcg3NOuF8ZTaFSbGu+hL3dnqIqb9db206A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fa7c2e17 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:52 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 10/23] builtin/pull: fix leaking "ff" option Message-ID: <2338b5e2a81b4036bf3740265126afddd2fbe6a1.1727351062.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 4c54d8196f..5d9d9e467e 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 a94387a75f..7fd8c086af 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 Thu Sep 26 11:46: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: 13813327 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 315E21741E8 for ; Thu, 26 Sep 2024 11:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351195; cv=none; b=pAp8ipznabtEhaaU/wjJ/hCbQwoiUFZQO4uvY5vqeEXxhmvH/hcwRRAWsI13fBQMj3Eo1V4pwdL2UT6qrKnn9+ikPlVLOsZdFaRG67SbhPCCb3t2KOLF4yt4aptqFiyH6ZfUAVoUAwcXUrMPi+Vpv3uDzFKPJ6YgJC3sY/MBxNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351195; c=relaxed/simple; bh=dSMRU7mg7mOQOJTQF32YVILsvWJIJ6V5NcWh/f89+bI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=md5MaLlXCIse2t+7T/1CMcUbbIDqQwCneP3D3BdCQtsX2Evi57ByLYLHhRqN1Hh1pRPZKacYYdpCQOY8eTw89HPL6NFnllz2LN7vGtYayIkt/NQtHU0feti+pDVm1+NcDJLY8/q+e2vhofH/+RNOXKKGA1x3KEF5Px1rrCpdhPI= 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=UhgXhE4s; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TY0MbfBN; arc=none smtp.client-ip=103.168.172.158 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="UhgXhE4s"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TY0MbfBN" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7B0661140252; Thu, 26 Sep 2024 07:46:33 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Thu, 26 Sep 2024 07:46:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351193; x=1727437593; bh=ytSLfI7Dzm dkNM7KV/93JBuGuC1mitUXoqti3Q24uRw=; b=UhgXhE4sdSNGfOaXwv21DQpf6H I3UjOBbiyGmgBEjlOJjWJQGeAdYR/98ao8nkYIPIAmpqqNU1sTOchvaF4t/t+4kN 1UMxkQZiDfoLaJNMN+sFmd4WNqmmdzMol6TMes7YvkIgX8RwEz2loEMz7sx+AjzD ECXjmIwuEFhPYYzfTAdaUUPGWDNX49JK5/4+jxNeYuPM8IdBxCRuAppdKCL7bHyB t3+nMuO9PZA870hL4dXSlZIs6CK9KVToZjDkMRnsDJjlho7dfKD2TUGDpYX9ZVfz bPG+Jqs/D40C/YdKgQUR/VaS8zu4Jsh8Vl7QHwMvALzCMMl920Lc4j4up4OA== 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= fm2; t=1727351193; x=1727437593; bh=ytSLfI7DzmdkNM7KV/93JBuGuC1m itUXoqti3Q24uRw=; b=TY0MbfBNZkh5L4X5uwL1l39AqW/QaRGJVBAWmdDsRF4a 6hIxIh1qspIcS1zORDxe+5aiOH+V14n8KIS+H/k/71xsXqGZ8ETL18JXm1yfgzW9 dzRVEPPBo/VCOjQLqndbLdNSPddl5Pl+nfD+Pj6SLuRT8IOSXvdrNHYYwr6+6Y1y 6iVVQqGmZypV/nHJTxfJQk1taQpxlSeHGppnHBplocsxweyF3iRRPDh2UlyjwV0c yqNstzvgBeLCNNXgQUJp+oVlew2IqfCI2lBmWu5DmPG11OnhP3peYoDRR/u95lMv fmyO4lsASFGe383MyENWq8iXYaMLOcEfiTck7ZVsLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 64c58d06 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:55 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 11/23] diff: fix leaking orderfile option Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 829a44e416..f6b624dc28 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 472479eb10..6555b8a32c 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 9901c8ca8c..b95d3c1e83 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 Thu Sep 26 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: 13813328 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 64D73175D50 for ; Thu, 26 Sep 2024 11:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351200; cv=none; b=DfIbjWDoZ2mhZu0gxbJnrHJVqKAMU/bDZO5UodCTQZzODrUgkDq/PcJbBzR0im2DSay7TafcKdgZixNrm/KLL8G9Qjoy3ODhvSDE7xSPNcJnQfhHsViWMYXIxLErJAKfqQuWEBktvlg8qRTw+NzqqHJzRIfutzWKJScy0qSydWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351200; c=relaxed/simple; bh=f/Cupn5tFLfVjJhT4mh8M4kPBZhe5YLHUYu8Hc/dV04=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZZv2irSEqsIINncsMxzZSXWp6l/IvfVgq1SmNPYr9TVvw1PC90TZRJUVz7TGAY3ei+CIwxOiS/cP+cqDuuZnhsPlCpvYb5zAKA0uemeCcK0k4l8MiT/+iyLMPafU9K1cOIOIZAJyCXTVz3UOvto3B6XuJd/eFIRV/3jURfED/zE= 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=TWCpStQR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HO9ugHaq; arc=none smtp.client-ip=103.168.172.158 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="TWCpStQR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HO9ugHaq" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id AD9D611401B1; Thu, 26 Sep 2024 07:46:38 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Thu, 26 Sep 2024 07:46:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351198; x=1727437598; bh=O9/B2pQ7AV /aXHE/IkvoS5tijV3doDeJK476AMQHrZ8=; b=TWCpStQRfY5DFd2uWQQEM+ybrx detQg/p6b+1CAOWlLg8jprGT9w0j0kN4iPQLXoLBA3cgiUGotCU4lUg2YEEco3Pj dAKlk5BufFACITgvXc9nmtxgERzyVSeyPhzlPY8TI+am8uU8zIR67cGsHDn8kuZ5 l2BzIHAZ/eftMGuedaAK1f5wJJwlq/S15pnQZuzJmIFIeyY6GmqS9b8giRIvdXbe e+YUdV2pyNwy8r5XlSZsIvZ6LOWZ7fNhlOCg/Wiy79+AjPMNur/k8mwWlsBGoA8q QFiEZguwmH7BCe48Rgn9x5gTOenPPu/QDlY6YdBUUv0iXaZ8VJp8UutsuUnQ== 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= fm2; t=1727351198; x=1727437598; bh=O9/B2pQ7AV/aXHE/IkvoS5tijV3d oDeJK476AMQHrZ8=; b=HO9ugHaqnn7DqmpV2SeLgHBiHcavzrxtsAxL12bJjwgC PgS3JT2Dz0np40JpKKl9e47JUNcbHz4D9rkO+cjUnJyxrKaBqIK7izCimPmA7sFR jWeLfhGvwNcRuEU3JV+3MVHjqLHT9ImSMzi09ymyRCj+HifO5658rH6/o1yyIol2 g1subOaCEDmry9j+4Wgc3Bfyw/L4f8LsdBijbOnffGeCHCsj9HZVm4Org6WJKZtI lGvtZ2rUyr/j+Xz+ghQo2f/hkkfnjLd3mPyJxwg2VW5/A0BhqHETvHiyKNBOGqO0 6k5tuGONmQE3TF2Fpl1IZsdewApDGLEFQgWZLMLbgA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 69f2b28d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:45:59 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 12/23] parse-options: free previous value of `OPTION_FILENAME` Message-ID: <650b89bcca8bec87718e791302adcd4aa35b2a68.1727351062.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 30b9e68f8a..33bfba0ed4 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 Thu Sep 26 11:46:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813329 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 C52B01779BC for ; Thu, 26 Sep 2024 11:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351204; cv=none; b=trB/137JPueJzuFashAxAK1RrR0x26Hp4BUd8eqCH1tfXIc+TWKcpjnwvwQWDpMiSTYdWCh72jGb22TZARshwBG7D4FyFMGuQYmEayN7rgiRy71V8hnEvJlKd/2A8+UNPNchl2I4Km588rSeWe3X+yszmQxwHEvP5wVDVjAk6q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351204; c=relaxed/simple; bh=34byaM45nlnPecc6+tcFvJyINJECNEBrNB1+QZpJ72g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VghcVo2u7E2onL4O2JDyuVgDX9Q72c/WwVvBdNYIXc7n3pd868I6Hx31vz0AMX/HvFWbGPL+VybvWTzdOfEaojZLDKrhZgc89Ee8NdKYYo95bhcUmYzJByn05/SqLRM7PMVUQtBafc7cLA9eF+jdPIJqoBZ1jbxYSmkmA1dRiE8= 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=jngGqiWT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Hq4BlTPp; arc=none smtp.client-ip=103.168.172.158 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="jngGqiWT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Hq4BlTPp" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id DBC5A114024B; Thu, 26 Sep 2024 07:46:41 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 26 Sep 2024 07:46:41 -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=fm2; t=1727351201; x=1727437601; bh=GxrpDBeRqm 1BntXZg7goCJOp/eWEPJvxKOW9ewDUZbo=; b=jngGqiWTviq+YMqtzG6DRaekHG 5unmYu7aUNedi5YM2dOfPpf+3ji3ExVLpttRl+wymhfJlUIFWEYojz6p5Jst+x1R KqllSnukdJh1RRgtducwVj9tpHPBzjYiS+f9T30SiM2BnHUThjcict5yJKCKyWqG JgezRLyGsVH6O4IunHKfklPZgWvWC1FN43xvVkWbi046QfJQ/MiAYRY5vIxTT+h0 shZgCsZwzSH4sKUXPnLCxxQAIQPiZ4ByhaX7SIMmaEYk1AD5LZsdaIQEs0w89JP0 D2Mcc4aA7AA+uKVh41r2GRFgJzYYTD1dz3yn9GldMdtrM0F898ozqZcNIA5Q== 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= fm2; t=1727351201; x=1727437601; bh=GxrpDBeRqm1BntXZg7goCJOp/eWE PJvxKOW9ewDUZbo=; b=Hq4BlTPpFiA/tC255KDwPtdfsHdbErmT8YBTgpGzUerw gz9zfkhMbhph4iNnbkS05TrJeub16+C9yZAi9HZsh+LQ9b6JR9TqeNx+85gdPoUR c5SiNc3N9/qi2SDa//N1vlDnyvlJRgPVmlPa1oGP9nhyqYSHTMwwTH1czMUGBjzC 2o5CfNBepLM3U+mBb1qvCu1v7qVPqqM0K0Qds4EqyWyKkppCsWzYjpo9UO30/X0w CxP8n3AOfevDtZDAgNqITZqnBjHi4jb+ZKcFLxLmqJLq+BcKZTFr08Z0FYWI6Ksd MIeKVuQfmNwPF4yFLs/OwfrVbSe79gjWyDlyKRCjnA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 325dc1d8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:02 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 e7d20ebd2d..912513d3e6 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 aec1d9d1b4..32c5fcb9a2 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 dc8ddb10af..c0a4a02dcf 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 Thu Sep 26 11:46:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813330 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 02A44178367 for ; Thu, 26 Sep 2024 11:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351206; cv=none; b=ZmtlhWDl6YYmdsLtRyLS8aZDJivdWnTr2t7T4dEwfy1nMVXfyb/dxUaVFkwzleFvAvn9DWJ4U7Ih4OJpM9kyRyiJ1XSnKHPCDJexOgR2BNd9a4V1EWa+7vlrZXD/+FWFWBIu/c1Fcg8R4STqPFDzMygI5vOvH2RrODNyhhTmASY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351206; c=relaxed/simple; bh=jep8UdZQ4EYrFwpoCbsOWwQR+4N2SERR1S9+/rj0Ih4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qEEsYfmSX942QDx17D4vPZ1I8EXJxB1USZuvRZLJgJjdzyCkrUi+F+UAabStoABF0G+MEwx/MxRP01CoWC0WMKCe12xK1txoNOMJb3ACOvJyM2+9XOdnlD9DwwoBD3vBn+VMnp80bK1hHKf2qvZUe8iV4RWHPQlHHXl5dhHNk9U= 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=Uq5rygDk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=n7ZnADW1; arc=none smtp.client-ip=103.168.172.144 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="Uq5rygDk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="n7ZnADW1" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 17C73138061D; Thu, 26 Sep 2024 07:46:44 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 07:46:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351204; x=1727437604; bh=/jSR/xT5cR q1c+NhFacms0B/kPuJaQE8JCpteyPNvZI=; b=Uq5rygDktidcXfQX+RuQwQmkoM 24h1QpUlVMduQEVh2g5id3Ci4Jt0dKWGU/RC+pmpPDmoipUugug49bMES2tpjaYA 5SScTDmYUO3Sx27cnZSFvPvTysAnhX7Gs+jZzRCX3UyZzn0xsWftcNsWzJ6nfVQ8 A/ovRF1CxpGOs2pv87yBDYcxtBZIBwIl/r/+HC4a6SRGs3JADlDwZNurEyLMiFN3 455709P5GzVImPDW5Bp1L0518fXYWENnDF/qnAmFJDkGWvkEtJ3NGAuMkCgdhKF9 ElKgS0JF/wA4jUKvz0otEz1Ow8VI8UHL0ayBKKvjyfpJre+VjUB/bX3taK5A== 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= fm2; t=1727351204; x=1727437604; bh=/jSR/xT5cRq1c+NhFacms0B/kPuJ aQE8JCpteyPNvZI=; b=n7ZnADW1FrPTY0/G0RFXZ4Paj3tsyR27LMmBYLct1DzD 6+8OFLiG1T4ahuTQiYqIM/5jVoT7wfggNFkTNrkh/TihNMBr9Jkci1lgop6+Csax TbrYn/JYrITxCA+nHvaTAkn0yJZr1pR5kzgXa8aHyIYIGXE1a2KrUNPwQtHR1Wld WrmS3o3BAYBHTaOhNsmBBzRoHE9/IEiSz8SjzICWRQuTdSFT5rVx1KEohoIxK7z0 PV6URnMAYTpLKjyZ1MmwT4X1U078qZnnQCVO5qEg6+6nvpJuXnobZNdXBTS+yB11 85EDXPN0cyfiY2zzEJaq7VMC76pEuj2KZpeQ4OJCnw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a44cd8dd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:05 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 3ee8cfa732..c31d5653f1 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 fc5fedbe9b..445739d06c 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 be1188e736..c4c3d1a15d 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 Thu Sep 26 11:46: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: 13813331 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 1C7E618455A for ; Thu, 26 Sep 2024 11:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351209; cv=none; b=tgyex3lByoncMNYek1yU/tqzUigIkpaKu08kR7XQ4trbkqcgHOyzyF5+co0b3chkYRft8zxa5dQJEjzDm3qiTo7Z7of6t5Je3gg9ooYkRmLZbfRaQohkm3kzGc+9jF+yLMGZ0RjAT08ymRON0sEFX8k5jWZ+aTREewxNx8ikq/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351209; c=relaxed/simple; bh=5Mh1mIUhXHetIiTZ/5fvD+hShueJ4jGUCqHaXdQAf9E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jxSEDG9N/zBmQJUQGOsZrxZ4OhG9QDXt844g7cXqKAUdOE3xsApI1j1iUzTZfdps0RO6uFonalHGaOzi8MYMAZQeAS4R0NIKuYokdN232GJkl3xgByHND9CD1gyKuHPBiEYaqgNSPzLAn9S4B4FxRskzT0edj1BN0+uSxClJd7E= 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=ITAdLW6k; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Xnuod9nx; arc=none smtp.client-ip=103.168.172.144 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="ITAdLW6k"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Xnuod9nx" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 47043138061D; Thu, 26 Sep 2024 07:46:47 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 26 Sep 2024 07:46:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351207; x=1727437607; bh=49vc06f8wK DN1kYNnfIUHtDNWH6X+tIRbH+IG7ZjFvk=; b=ITAdLW6k7iRLcW2WV5kPl8nLRx nwrCiTziiejbvGmKxOBKXkluzQaeWFFZc4t1/bRlzUfdh+omigs3mCkFKA8GAeqe GuNdc5lFoJxZ9G6PDbeWZ570pkM4Jnrqs4S56YLPXlDjGpKTwGzy1Spe/i/1Y+FS bXbeB83k9oWcE+TCHG9Ceh5IRvzRiYovglQOqLMt+Ad8jk5FYq3QZtbsyK6rru/U qMeHrZ2ecufkMfqFAUPEVSjSnPpGqFtcUv/VIXW2fglxXHpMkFOTujfeFrXQ3yT7 AhXqYG+nuIcxfSRVCLau2BWRdN0VlvJ2sY9U0RSmCG/WFmu2xuMSS/heVrRg== 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= fm2; t=1727351207; x=1727437607; bh=49vc06f8wKDN1kYNnfIUHtDNWH6X +tIRbH+IG7ZjFvk=; b=Xnuod9nx8i86Nqo62Yz9TEV5o8irrpT/r+XHCl5SsGWn x9WRMa8DuQOUQp9icPJjvajdfpJN5dClV3GUR8nSHoInGB5iJbuUJlyEUrZfvyUN 4JQ3qV2xtTyh06VU4wCHSx5+CiXryJhTSTzwm/HieiyfOSgEYDI1IWhoZ0tstu67 6zj+FeGz78ExGyywhwlOGTipYonM1J0v5yuAKSQi7uqgauSVml+4iq+T/yyBdNwq spqfor7D1RjwfSdn+a6NajxnxeO4FXhMK6x1MKcs+pc4+9mQ4qhK5KdwPHtEJXeN JBZH+D/u2jkk0YkkEmuyUQvh2ZvjVdJCcDk7AOEqJw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:46 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c7ce0ee6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:08 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 15/23] builtin/difftool: plug several trivial memory leaks Message-ID: <7bb07ec2f07dbbfac06af039d1f192558150f4f9.1727351062.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are 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 dcc68e190c..1a68ab6699 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 cc917b257e..f67b9345b8 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 Thu Sep 26 11:46:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813332 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 3B3081849E7 for ; Thu, 26 Sep 2024 11:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351211; cv=none; b=obIpMpoEQopKWmPxdkUubOETThjMGJpy1jBoqDAOYm85fMflHpZmpUsWzHRrTFNIhDpvphnHh8kUVtmUtYaHArlB+VtBYT02sstjUWI1Swtc8HnqNORKHoIgihGKOcYYSC+QzvrazFgy9WBsPaJSQVwSiAOXn58ce/eks/fsXBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351211; c=relaxed/simple; bh=pDD7D9CcnXwaAmsKfNBN7kj5HNBRCMFffkZkL6ywj2g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=paChOqtvWivP84PNOWOl9thA+yqTOygDYH96tqE2MDGLtBR8c9z9OCU5+IUnDq9Sxsr1txgLIZgkUMR/GXDGXk2AECaDbAnhZHs+RhV9GQ8E54RhmUkatm2umD15/FGzlXtxSaTUDIBaxByjKmjXhd5125i0NNeBnFS1HJMUvUo= 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=lrpn1K6A; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZWf2mEvB; arc=none smtp.client-ip=103.168.172.158 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="lrpn1K6A"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZWf2mEvB" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 77ADC1140242; Thu, 26 Sep 2024 07:46:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 26 Sep 2024 07:46:49 -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=fm2; t=1727351209; x=1727437609; bh=CWtWbvbwts iDKJRrls3/nQgEIvJpKLpMvoBzqJ1jt20=; b=lrpn1K6ACNKJdXpprc6lajWA4U PQrI8PpxvzwgBW/UIGcfyRBrekPVpfYCzUTaOJdqCDmSgSuwtqxBXtc6irEG66iL ww+aiGWQq7oYykhBHHMQTd6VfXKWv8gH2OICuBDAzjS+QlinLAa9L5UYpMDFltIa /tHfx/Dn3H8O+x2Y7bAgCJB2K3IIMZPCdWD9lu2HyXZQNZFgi6udgk4yTgClkySk MHx+gEHAuua/QB+g87fzbxPza6vd6JKKofqfyY4Tcns5frzGBE74OrYdxOFZzuX8 AM7ao/MGmY9Bj5++hGOS6KtSXohG8UMwmJYmeAj6ZwtYVG7UWkyS5s3Eao8w== 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= fm2; t=1727351209; x=1727437609; bh=CWtWbvbwtsiDKJRrls3/nQgEIvJp KLpMvoBzqJ1jt20=; b=ZWf2mEvBvC7J90Ma5M8/UtLX6mc5V7BUb2gg+51Ng9oY E4lgGscyDa8iXBuSeIpT3IKu06u+5PvayBJBr6Q5bAgl+F8TRyGr7gtKoE+8fEoM CpgFHD5ZM4RLfGU0yYlCZoSd74QPAJlvOq6y5pA21J7v7OLwDaqYSZUGJa9+pssP uj2vI7NDBvnnlQWALSEeRcjruKBhMzPkdvDxtG9dsssyXt+HiTvo1wr1QCnvAx15 mnq70wf/IZWY9bBZC4uR4+sXvK7MWtKR4sl3fw7nVrdF/Lb9Mi5plGt6BP4kZs9p s27hRPV1lts6t+/Pg2NBqndhv/I62cCWG5dRcLX+tQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 61d89448 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:11 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 16/23] trace2: destroy context stored in thread-local storage Message-ID: <30928eb8f9ce4c2e6a82f566ff740c31604b0d5e.1727351062.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 4f75392952..7b023c1bfc 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 Thu Sep 26 11:46:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813333 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 9A566156230 for ; Thu, 26 Sep 2024 11:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351218; cv=none; b=dveBtGcdtF4uStrLDMewrr27aw2l0i74M0DVyHwgsDuvHuA8fYG2BnAclpy96/O8/sS6U7pTsGVxAksB0oYUby5yJxdtQfNo1yTPvW3VTO+EFvBNfYOJArMSJ37sRAGgLkDVKDD1W2fwvyRsgkohX//iLZMhcWk1Urb9Jvv3gaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351218; c=relaxed/simple; bh=eE+V8n7sVcyh95gUJ75HmZN7nxtmVvdIOL1aOVnN4oE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RMaSmVw+l/w5IzanhQ+a0j4/QU8Gq4nVGlNBqfr6USpztWxEHJUP9JRIsdDa9dZVPicg0JXp1LafSeqKG5cm/q3PEvqw25vSyiAkEAfUYD2SPWGCoLuNyg+fRjBDOrszDBXmJEM9MvkKyMlIPHLeEBUHCzJIStI04x58tFoGFD8= 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=VD9U88g1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jzv59YIO; arc=none smtp.client-ip=103.168.172.158 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="VD9U88g1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jzv59YIO" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id AC68B1140252; Thu, 26 Sep 2024 07:46:55 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 26 Sep 2024 07:46:55 -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=fm2; t=1727351215; x=1727437615; bh=QmPkWzLTXQ 9o3eZQlN9lt1gQRgVa1Fr0E68IvoiC3zQ=; b=VD9U88g1626TMVgNk3+Iki533P GFZ1E6Tqp/70RHCTx9lHUVP3UK/dLpmIRCi5aSOp6nFE93PUVl9RZxTt3N2BVyMh YeL4op7jYm6+5TtC9lMH62aH0wkym9+Puqqyd6OiWHxMHyofJ4TGuv+bljJXx5Db 6r7K3IxddYs68P4dnB3sWhfp3Caq7gHB2RJ1i7g3l7S2h+R/KF5XcOMC0u4ZrqTU x/Jpw02JEaeRZumvnsghi4FXMoEbX+0HF9f+R13DwvctX7wFCXH/33C2dweqaMFZ HDdw2f/6i15XNz9WfmPMJ5pMzRIg2knmGw32f6jP1ZDwcg1pwwCyTLjOArEg== 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= fm2; t=1727351215; x=1727437615; bh=QmPkWzLTXQ9o3eZQlN9lt1gQRgVa 1Fr0E68IvoiC3zQ=; b=jzv59YIOqhqzkJZPq2dvuU4emXsacWbdIvYBqMR28Dzq H931qwo7ZCBF/0X+usZU2Xf/pzYWX2MQqsngDtOCXRXDJHMgHbp+xSWrNXNv12c9 ICAH2iaST3HHB+3SLIufs0xscA+SMidbDs6k5ZZ8yR0OLphddfgBo3utMwsYcNKc 3sy/fzF903lnrnhPXcUxLnHzzXcmw0Yq9p9jSMf0JuUbr3Jd+sKG/xgMgwHbSNut G25DESRDxC2ex2S3A9Wc+XS945jmxBkdjuyp3UXyzQY9BtSeua7eoQ0ySwslfFip M6yDurpJQkTTIZFlhe/bVkvDqssVBxG1at44hqGDGg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:54 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d5c0c7dd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:16 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 17/23] submodule: fix leaking submodule ODB paths Message-ID: <35f5de5467f97dad04ae53e6de08b5efc6e2cf41.1727351062.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 `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 0e67984d77..a07debc227 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 Thu Sep 26 11:46: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: 13813334 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 A15781849E7 for ; Thu, 26 Sep 2024 11:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351221; cv=none; b=h+Ehsn9+XQCcW9IqgqRBH7AzO1ITTu0zdCABj4kHJiPEnBRsd49ctolvCbXBURdJeuQETZiFXQ8JHbVYmDnyP9XDwvmyptxgb/U8bV43vzIEAWALOkfLttZ8FPgHEu9dHGIPiX1JXzBfSPTgJP0MPBcwytBHrrxisZfuRHJxVl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351221; c=relaxed/simple; bh=c/CV+UnPp6YyL1wTDy7nKvtM0F2D7zuI4L8ruv03+P4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X9s9S5MFC8oAs330fQn9FFEF/0MNFyqksEpM3EZJLB+03n5KZkVr310dwZu39xSj29xQ6maxnQlGiWSTincumbB8fRW26gkE4NzrBDvbE79LX++JVIF2/qPNFeRb/DSEd3yltJOGTjNKL8mSaOQMqnxlkjV77bN2hvXqx5LhnF8= 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=inm2hQqE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VweB1C0w; arc=none smtp.client-ip=103.168.172.158 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="inm2hQqE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VweB1C0w" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id DECB0114024B; Thu, 26 Sep 2024 07:46:58 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 26 Sep 2024 07:46:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351218; x=1727437618; bh=5V9VDGRbpc a0AU+XHre1obAgpVurqNz5tI0Tura1pUA=; b=inm2hQqEQ1rc6zdItHCOiz6MRx KlzX3NthZ1BbChaoICGCtggsHNiVqEwtSHQ84BgGEaTrxStPeXdVbgYX2JeYZAD9 1cR3R8wJPHjRgtUJyEL5Q9MAm5g4ii0rcOUW0T3VsPyGRUKR5na0AQnHpbehrmqk LVheqatDY47PdZv5BgwCQ1F9XowOFZEofvbM6V68MWt+DYSGp6VteDtmRu6NrKKY mH4WergOr7QHSsAGyethHrPCLdDy6V2C2N1Ig3Y8CWgy4w1XSdPtSTA8W9fjA9CL pkwsk9JTSsJIv4DZJrm1/KFDe84xSztBupiF1Yb12nIVj6e6Czjiir2PcuQg== 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= fm2; t=1727351218; x=1727437618; bh=5V9VDGRbpca0AU+XHre1obAgpVur qNz5tI0Tura1pUA=; b=VweB1C0wVuEUwabfaDPM222ZtnnOaYtAnxIv58BDJu61 4eY6GSh7/R7zI27swSZIk1rMElHjxUDa8XQ18+YWkBIQBfO59kSKqjZV+AxotKhF hepDgtQ0P//5thE1z8C2ZI9VSEDnAoNe7b54Tmrakbd+41grqaPqwlyZhK5QZX+w PEp8HJE6hGQmALSfVCBLN1tBdpbVS9JKjIJJilGAL3fx40y2bXGFpOwHV/pjJ7k0 NBC3OUb+35U8358r+U8bImq06aVs2hBekzAJU708IzpL0tFEpdJacKFJhRV0rvVE oNrDhKKFjhIWVFHENMp29F39SRYqkRzVyGzcCc/t4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:46:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3f33725c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:19 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 18/23] grep: fix leaking grep pattern Message-ID: <3d1cece660a622a2b4f7a068cdb4eeb5ac6f8a61.1727351062.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 e5761426e4..701e58de04 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 Thu Sep 26 11:46:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813335 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 03FFF185931 for ; Thu, 26 Sep 2024 11:47:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351223; cv=none; b=kSNPerDR7EeSl/su1sDL4jFB6RMOnLpq4gZsedsGYRqzpYy2XPqpx3CJe0SxFuEZbUFeXdc5WUUo4X+3bxJD0xvziaUHpEqsMPT9hOGnJOO/wj3zj0pyE0DS559IiXDlw88U/gXp6p3zhRzhl4louojiIok+P4MtbtRkOwzZekg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351223; c=relaxed/simple; bh=akXhjL9mBMsT3F0JkkzTw1autuMoV32UjNucaM8p7aQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UlMKbPJBOcZWL1v5C+8RUxbbi6rDPoTkoUAA19tRJBNePoF3ura63+yjkTZrwXCZJPq+qAbmi2rY2FBfPoGGBYCIIesO71fXiRyRRFGwtolgl6reTNezLWioHs1sD7AWO4AtGotIPtAnXvxkyDzwrYyKw+3Of0iFdaoYkT701L0= 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=J3B4qRHP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=j+2yKznu; arc=none smtp.client-ip=103.168.172.144 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="J3B4qRHP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="j+2yKznu" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 1547F1380684; Thu, 26 Sep 2024 07:47:01 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Thu, 26 Sep 2024 07:47:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727351221; x=1727437621; bh=o5ZHdr2XBJ oWgsDTJpfrIdSLficG3nXYvzgnXdYHxNA=; b=J3B4qRHPxNMZJY0CG4YmOILkUo o3YhGx5VeOFVlEH8inhD+I5tIqb62H0+KNmp2Zn30z74e/ibykktzOS/qSara+Tk XpivJlfe5nD1NoKVGeAhSgsE1LWzJPtxjyocCfQs6+fM8/xb/+4iwTNCiCHCqsde GmXRo6+iy1By85nDDJNrFi5Kua9vT517T8QM1IJkRmYYzCRI/MKt9eNz45tL6Mkb Fw2lICmrLZ4bCzJNsogqHCZ5j2HDyTL7xgenthC47ZLborqC1pa2uALRpOP5Rt/L UZrEowZK8Ngz48cz7x1xFKj6+ZC/lcU3vCkicJscDLQKBp8fLhi2ZheFxGyg== 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= fm2; t=1727351221; x=1727437621; bh=o5ZHdr2XBJoWgsDTJpfrIdSLficG 3nXYvzgnXdYHxNA=; b=j+2yKznu2PLjIBOdguf8rwE5Q2Q8C0O+OnQa2kQQjX0Y PvAlc5mB/6Dkiz+6pU6Vi5VAWVvHtVEP7IewNVHJws0mBLafCDK+4dqYf+HGHWth 38g2SlgjeszaQStwy+H2WDzk3IsAUzzAPyab3mle/79FRrvtImkLzR69uB5RN0R2 6SG50ssMxxyvMHyWy9Ve2BlpyEIFXbyX4Z+dXFNLr5X34yuYz30p/zBKbhFClE/F MCtklP8p+Rr5DflNwVdPLJXa5CF7KtIF+mHvGabg+gya9d2dI8xa+yYs/Mxf7kFA Bs01ZYxdnXBUCD7I21hKrXnfFir0LZCj33dsBkaCBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:47:00 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 33534e5e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:22 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 19/23] promisor-remote: fix leaking partial clone filter Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The 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 317e1b127f..9345ae3db2 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 167fe66150..55ed630e77 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 Thu Sep 26 11:46: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: 13813336 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 E5BC518595A for ; Thu, 26 Sep 2024 11:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351226; cv=none; b=hme9dJJjC+QH0V2mPzgbwmxRPCfd+QLkg1F3sEj9NvQ+Ujg+cvF7t1GdGaLsrbQGEj6ESi6d4glBeA1lsVn8j+GvhUzJTHMWxJvn+JBnaFi0Ix6FzlKh+F1lanDS7mXltF7GXlZgglUmGg/oDIhTyjuk/I3snnpUOVSuiY5WkOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351226; c=relaxed/simple; bh=NOsy9tdQUwROSqcrQUqlxRXv0TXl/rFFQCCO9Es/jM8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VJxeZMeBGDFia8xlVIfuO4bqmA1T9nX1Rdve0XWJ0b1a6LAbXyZHVam66MEUf8Dk7bFhX+L3K0LbuNej+inyyNhxD6hFTSduqhMI/Aj5tFcZgCDABHCNdBVR2+ZbrEIgcunRRz/sl5TZopmQ0v+zwIN08mVbijwMvNTxduDBPJM= 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=QJdt087t; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FJ1fTfZW; arc=none smtp.client-ip=103.168.172.158 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="QJdt087t"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FJ1fTfZW" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 3A61511401B1; Thu, 26 Sep 2024 07:47:04 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 26 Sep 2024 07:47:04 -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=fm2; t=1727351224; x=1727437624; bh=+yIf+MeiKV DJDQ4DQX3Z6wSOgEjdu97ZIaGbDzYOCXw=; b=QJdt087trGdvxbO1eInjuqrbyp gbqVHQsN0ZSa09SYqzy9KOJNfLfEHFi5kBgaJQRJJjzO5xSAkgFLMH9EqMcpSfUU t2frVwMWUFUHFERcB+/z9hxmEQqFYES/jXGQcQewt9Lop4sX1FpVautXpclV6nds veqOlvjxx75tilCPA8HS+E0r/25NLqeph0SFJKnAzv5RSkmwjb4xjHeBUFHvaJlx J8D83lGUpHQplDPvNvIqmlphHBDWVjqQFfBmyE8LL0+2/C0xrntlo9f1E9R9vYk7 1kbVyyjWJossbiL1VgK7UeQlLSLYCXWk2DYMPRpPvCnW0uwbkb7jfsD1NR1g== 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= fm2; t=1727351224; x=1727437624; bh=+yIf+MeiKVDJDQ4DQX3Z6wSOgEjd u97ZIaGbDzYOCXw=; b=FJ1fTfZWF/7/kt4J/y8Wkn0vdi8E67iLe59V01byqyJo Kae8K2oA4X54HkQU2iKqZ4hGOHMXt89xu0X3XUodWyzCJgQxikqNvpvhcSSlyBqq hu+iAyLsU+HP1dR+DNBRysTnqZfJHnvjCb3/qwh5CT0w3NCn/l8gxdkwo8vC5EbH GFt4ZCVIsivS14qjI6/nV3BIfSM3qebGls0pf2qH0A9wo20B6tv1WcmmybehL1rJ tW7wWDchyfiBcbXo0nFSJgWI1V5PgWqSuxUWui6iMTPh6ZaazdiILHgEsT8EIjIf m1e7wczG2UDm00rN9vxmN1EhMtjn2dWT5xxUAuYTnA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:47:03 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 96eb85d4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:25 +0000 (UTC) Date: Thu, 26 Sep 2024 13:46:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 20/23] builtin/maintenance: fix leaking config string Message-ID: <0a72fc83f797d0f0f753e54b8473740a041702ae.1727351062.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 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 7dac971405..3acfa367ad 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 Thu Sep 26 11:47:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813337 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 57B2518595A for ; Thu, 26 Sep 2024 11:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351230; cv=none; b=t68OFEDMURB6YiHIYmlYuzj9Elv8Hpus2AQqksyaLQ6ATetZGabMclse3+z8xIYW6zTnPUGKgnzJpFnwjwjjTfGUqmUFCC2+eIxJJDELARIcxgpOq0rkhE9xKcxcAD2o+kpzAqzgHhi5LiDyK34j4NtoWwydIeFagVpQqbMlw10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351230; c=relaxed/simple; bh=nQVqt3mCduKDWQlSwK6KSHlIq3XpyI649br/VXvAW50=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CZfDizarWEWLDTZSFyCSxGulrIvc6GPmQXPJEvd9jnZhdZ1il5Dq/Nfb/L2VLflZU2+hntXcuWpGvTlBzvx0fJshlXDcvYrnDx7f3YT3NqO1USPodazmW9WB2YpQoIRAb4UpdV4dLwUbpSLBypfFy4Y87jwNeKD6rPlLCFz1pRs= 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=R19pXNNT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iRTWMKtS; arc=none smtp.client-ip=103.168.172.158 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="R19pXNNT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iRTWMKtS" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 669D111401B1; Thu, 26 Sep 2024 07:47:07 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 07:47:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm2; t=1727351227; x=1727437627; bh=yKChMOyx+eRcJ21TemwCXXrtJvoud9vu4FE0G5eGenE=; b= R19pXNNTWQsCpkR40pXVEp6RR5BPhNtpwfS90zhQaBsLu7mctfpFId1603X5HBTu Jpwzt0SVM3a4QW16BUgSGlqSg32sFjeIDqhG/gcAU8oSZOrQBYEOxDSeKG66BoD6 QMMkj6//iYSLiDlXiaqFQ2PW4uL9cZiDJYVUo3AYJznGAveZAhBs8dt9bNGarMkR WS2sTsAnyoPIZOulbvUtrBqraDsv2el8Y38gjYWYodh6D+isdTxJozSTai9YKAfj 5QSmVHKXBbz3ELxfNrSLmly71G9Y4YxZ7XKOXF+DTq7yUwMrTplqS+zuKErPUw6W 9oimOAphSThc+2hJTin4JQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; t=1727351227; x= 1727437627; bh=yKChMOyx+eRcJ21TemwCXXrtJvoud9vu4FE0G5eGenE=; b=i RTWMKtSxfJb/r/8yxxsTPwWAhSbDl+xocwJpR0PG5Hhx+7Mprpi/XddVmfuS8SYc hOoFw5ZGDbs4J8Qm0BrYWDf9v4CShhuv3F7J5PJTlqbY7tXo55g5FKF0R3D+NchG PJ7Lu4ZtpMKin5+t+eSwB2NKy4QehWanYKxr8S0N+g4JAOz6hfTevpGwh5SdRUMk Tt/qy31nhHnUfJG3sRPtrNAeIZAmpji3IMPLCPSHC15ltsLI2AMNzEHBY0vSnGiY iZ6XgjjGATdPFdPE/hl5zKb4jlzzn7qwu7dqCK4WPMOUakNHn+YHcDOjRBSRtjxw P1bYD0HW4XdA6xZtvcH0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdej necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpedvvdejheeiffelgfeifedvgfehvdeileeuhfegudeu udeljeekieduiefhgeeggfenucffohhmrghinheprghpphhlvgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm pdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehjlh htohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgs ohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:47:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 78da665d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:28 +0000 (UTC) Date: Thu, 26 Sep 2024 13:47:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Message-ID: <95200b8a766e2ba7a971ab79b6d13f03bfa3b8ac.1727351062.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 3acfa367ad..b68a0be62c 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 abae7a9754..c62c42848a 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 Thu Sep 26 11:47: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: 13813338 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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 76DAD17C9E7 for ; Thu, 26 Sep 2024 11:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351232; cv=none; b=DcK66juJXjFLE5cWxAShZaLsbEAqm9rDyV0GCYHwlqtkvRcMtRqkQyH+ZCP5zm0S2JthB7uUJlMnNiAJ7KbCEk5spDMK2ecVUWMeiWRsi+yQ3TR8TfO0s7wPsMavEWbPJOLAxd1R2wXAs6qD3NZhO/vTOBxJlAOmJjrAof2B30w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351232; c=relaxed/simple; bh=LfoLiZVw0Lhpzdg0odGVf4R5LPqGjjneVSxRlOEFXhs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bouxIMQ0cia2yrh2CJYKS26g4oJd8UxnIIhH9rkTidwy4rDgI2AcyHCpzwa+B6wr1PTMHqUMTB11mrIXY+H/3yX+3pC20lTQeeDVoj21ZgtMU9vOoaEOlRp7vJz26ALdz3QBoy6+CaOr/LQ9rmEVuoplj/glXcdtXk+EH2+F/DA= 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=HAykDAmz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AS0aPRtT; arc=none smtp.client-ip=103.168.172.158 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="HAykDAmz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AS0aPRtT" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 95E231140249; Thu, 26 Sep 2024 07:47:09 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 07:47:09 -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=fm2; t=1727351229; x=1727437629; bh=0LfSDKdkrg ZDMOPYEbctadthjKt6uEGXCQQ2Ua7B3Qg=; b=HAykDAmz7OdNvpMQRYmei6CPTI 0QfGru85VfWUyiyz7bHu2eNOr9vffiyqCFwrAmNu+LYzE12pig5fuBaDySaJyXJ1 Y4EBEXuSqg0J3jSyKhK9csSQLGLzlK3+MBFhJFNJ3EwDjiMWse89YaqGw3oYt1tJ Y2mw3qIa56ipMgEJjaalUIkXou+bqVZNVL75XqIcu9i4jMZ+zeZN+MNaOyovsngO HDKFwyvLzNqz7mQGq3j74wBDUAp9yJg7fH7KMi3fZ+y0y3kIyYOK0jmMXoHYTzPw HVuz2srt927HrhTrF9SU6Ws/Kz77U/DyezcyiHb2AIpUXccHmvzTp2KP84GQ== 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= fm2; t=1727351229; x=1727437629; bh=0LfSDKdkrgZDMOPYEbctadthjKt6 uEGXCQQ2Ua7B3Qg=; b=AS0aPRtTpyP2FsyxatbOmad+QAoA/v3dYpUXHLoWz0P7 4TaQ+675qWdN5KN1oX7P3NruQpwQt6nUIY1eHnnequWBdNml6TGDJQK+/VRIRrBl jThKxwVZtXKat94axKHYgbn8v7G7ugGx9d/M65aa+Tmnes+gXSrAI0j37geJ9ZbK 0kpqstFJzVCFf9zh6ihrsBsQn2D0Z50er3LMa1XRhY8dL4P0IvFwiz6MuhZYKDyI M6ElQNF+0uW0pWl14nEpOdRFD64o1pdc8zv7WlWelOnWz3R11Y8de1DjU8we3Tj9 wo+VT184gmOokh29CL2OPO7ZBmZngRA0BZwTvy55Dw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:47:08 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e66ab40d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:30 +0000 (UTC) Date: Thu, 26 Sep 2024 13:47:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 22/23] revision: fix leaking parents when simplifying commits Message-ID: <8e7ea54863f9fde80bc99d654140146cbb1247f7.1727351062.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 2d7ad2bddf..e79f39e555 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 be6c3f472c..49d28166da 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 a6de7c5764..7044c7d7c6 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 832b92619c..6eaa692f33 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 cd4f420e2a..5416241ede 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 738da23628..1aabab6956 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 90ff141640..f63bc8d3da 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 Thu Sep 26 11:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13813339 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 8160217C9E7 for ; Thu, 26 Sep 2024 11:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351236; cv=none; b=a26tcKBKT62jbSSSEAIz8qZhqMQPbVso7cf+pbLPLyqOSAHCyvrVAjrTBMAM8aut6OisBleEw1T6paDbRN2cZLpSkYxajfl/IZphv4yKDQtt1AiEhWvspyDSYDoHysYl0w2tAOHoZ61svE2iXAHmerwVToA9RzdqBbjnNdDt8TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727351236; c=relaxed/simple; bh=bSULJlxtVNqnJX8mpHGotBpuObbIv6k8aPobOOTv0JA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dD9aa5KaJieu5RqfccfIXpU6sQP5Qb1STppOq5gMfb55unvo374d1oOr77KQFFleEP3W6/xdyJRUAURzc2ndMEeNyaGi/GyOskKBaU8nCK58/fP1ebstv6Qm1F+ZrzZxBqu8rYyMzICsS3VygmxeMZRwlZZbnGD78AQmv2uQ4+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=W3F/0Tsq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LbNoh4Ho; arc=none smtp.client-ip=103.168.172.144 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="W3F/0Tsq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LbNoh4Ho" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id C6F1C1380438; Thu, 26 Sep 2024 07:47:13 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 07:47:13 -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=fm2; t=1727351233; x=1727437633; bh=GQw7GlHGqU 1RpVgcbMcB2CRzIDPh2g4DVK4wZI0fpFA=; b=W3F/0Tsqil/W1fVb5Z7ktZtYel yu+ND+qCjN5A0L+PeNz8VkkVrFHJ40vG0OrhVDXRq9l0tC5pfekvMuC53pPf7ytj Z9BUg55RQcK+isYq7NiVJDAkurFkKiLcE5eFurnQV7HAS1VZucsMS9Nmb4hAVg/u EmqY78qf7ra+BAPutyXCXyGPovt8Ra8+7jWRRYJK0/366GmbM6fp4XANxR6JnI8y mM39G6s/gsWvQxWCiwm1uR1B3h7d+TLq68aC/HuNfDtrBNqGzUzNigLqlWsulNxQ Vxu+8lLT39V1EYNbtlQSnGPHogSXNfR4JxyTRYzM7RmNi28VBzwB8PP9BSlg== 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= fm2; t=1727351233; x=1727437633; bh=GQw7GlHGqU1RpVgcbMcB2CRzIDPh 2g4DVK4wZI0fpFA=; b=LbNoh4Ho/FgqokGSAZp0IjEjfslTzVArPxax4CFsP2ae 2BYtqxVbaWtvPydih5xE1ulHZkdQEIxx5HjXEqvi5WBA1A/nBVsCRBZh0nx50PSu kqlhVT3EtAP1An2fehIsN9OIq6bCTPGD7btlXcW9rPErAg/rK/hlX5zXNtWDn3Pm 4DqHG4jp10GFMc5x1MxP+IWvLWisLjzJSRhmKPCMczbKKmGXjW8j6TcpSZb3IdBF O4SX9d3+tprJIimFeoLfkiYSc/TrBMhzTxW9YBTChPqYlKaqLI2vWv12lHESPIwT 2hqHQx/FRbvzcL4RrJd7ssHmvDYf9yhtOxnPit8kQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 07:47:12 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3d577f95 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Sep 2024 11:46:35 +0000 (UTC) Date: Thu, 26 Sep 2024 13:47:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Message-ID: <8cbc41425f1100928c64c02602e62e1070998ec6.1727351062.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 831b66b5c3..02735f80c6 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 562aaf3a2a..b0ef0026e0 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 6fed993ea0..77bc36d5d8 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 787605ce3f..e6f4fe441e 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 c4394a27b5..1b8cd3e4c9 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 47b2f1dc22..a8fceb6a47 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' '