From patchwork Tue Nov 5 06:16: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: 13862359 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 A35DC1DFE8 for ; Tue, 5 Nov 2024 06:16:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787415; cv=none; b=juvs0Krw1ogg+yr55q7raJcKRAxsHU+VoKDmYpSh7JF34srlaWgWudFgT6hWiBKbF0BmV/S9698Ru8sqDES2Z6Lsg8NaeALQFiHgl27R1XR/f1uF8lLm9qCXVblVvmNjZhROIU2T4oN4HX1+OtPEDkH0o7Te3uoUFCjj9Lfz7XY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787415; c=relaxed/simple; bh=5rSC2cIRbBc8lYaq8mLf/R11BRnUYBy9Lcxzc5mJLvA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H59kbe/aZbfD9hz+Mee5PmwNB/IPbo83lZsx4c1vy36/BQyH7JI1XB1n8DiBqldj4G6HvJL/ghNoN8PPZqvx0oIGryNVvBouHaNYbZrPUf2hmFM4/RPoEZxExc58CpsrxZ9EZdgHct7uPCnbVanN3PuYmK3Lyy0wlOPEtyaKT8Y= 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=LvpZYYfe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lCii+yjy; arc=none smtp.client-ip=202.12.124.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="LvpZYYfe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lCii+yjy" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 8685D114018C; Tue, 5 Nov 2024 01:16:52 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 05 Nov 2024 01:16:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787412; x=1730873812; bh=oU+5mlY5Lr nRhkAWXQ8gmfzfsQ7cZur3LV6svAwlF3w=; b=LvpZYYfeGLnuZ1q0q43ehyYRF1 1+pf62Zn5tWiVLFF9JK5fL1FRw5JaY4Rt6FhHHq60SsArvzfqcJWmPbHZgpdel3/ LWnem2lyiIEbqegQlnaea2bL1qASw/LuXeIBivRYkfbvPRd8O2Hm8QW8fhdP2cEo cdKx09BGOr9bPGFS/xSO9z3iXHKhyRA3rpmgISPJXFNzX+RbPmq/gKK91Pip2pOy vBR4fbUZ/p99/RcKpVvZgFueK6uTLqfgM8s+iyC2ljYSnT6tAdd/M5gHQIcdhUDX a1glTguICoSvnTKO4M3svC/ULLm+cwUKF/q19OgZLGMe8Q5hSFuyR+X8zPOw== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787412; x=1730873812; bh=oU+5mlY5LrnRhkAWXQ8gmfzfsQ7cZur3LV6 svAwlF3w=; b=lCii+yjy6j5iGU8BoWGilAV5YCpODEk6LHKmh3odglkNgYAmDmi jdlR/em2UC7CFnYdAUrrT9BHdOJMHgvEH/9p1Mnfd1idqTcvIGZqTMsCCi8/6eU1 Sw+i+XWTKk0Bizsr0WYbMmPCWtll4MGtPgTjzpWPz0akg8OtXBnzDvUvVoRpHBj3 kuOGtKrb73P3kL7XFN1c2Mie6pLBGV+Zp9EZxrzhoTOOqZbECg3BQRgTv2x3fAUK SakY0GUXwuFzAIeEX4kKKuPjgO8rVI7mmhT8iw6Ml5idrHzuIuIgF+TEtUneMvE2 JATqgv3itM4OlzTwtr1r8Rimbgt5QD6BmBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehkrhhishhtohhffhgvrhhhrghughhssggrkhhksehfrghsthhmrghilhdr tghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepth hoohhnsehiohhttghlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:16:51 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f612f5e9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:29 +0000 (UTC) Date: Tue, 5 Nov 2024 07:16:43 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 01/22] builtin/ls-remote: plug leaking server options Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The list of server options populated via `OPT_STRING_LIST()` is never cleared, causing a memory leak. Plug it. This leak is exposed by t5702, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/ls-remote.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index f723b3bf3bb..f333821b994 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -166,6 +166,7 @@ int cmd_ls_remote(int argc, status = 0; /* we found something */ } + string_list_clear(&server_options, 0); ref_sorting_release(sorting); ref_array_clear(&ref_array); if (transport_disconnect(transport)) From patchwork Tue Nov 5 06:16:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862360 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 4373E1CACEF for ; Tue, 5 Nov 2024 06:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787418; cv=none; b=oUhLFCs5EheTCVXiYDJf5WDjZgsfDRuz7UynpS7aJnrxxkNDAbT7YLtxRHxJz+tOjdI0Z8PrW5yUvZwV5P89r9YGR9echVAdo9Hu1TouEsn7O4EselSVVrPL4Nw2AHxK/F1XyTT3kzL6hod4B+vhhH/iZ26QquId+uolVsHK8cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787418; c=relaxed/simple; bh=0MLZFXeGkvYB3QfhXpiEk8OUmZHrmbZA8PrYdS7Pzhg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GBJ7aJgHTt9iwfD5M7leOmu+dLcZtFu0nvzRPBCIGl/RehpMH/l71BAfArUa2v1JsOCPiZyjPHx39Y6r0BJZvvYXVIr/dvdwrVd3aEF52eK5ldefME72UTB2UKqd6d8oVXF69jmjjpUXyVTnMI3MmXK79DZf2yGPKYoz/6znAvE= 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=JvrZmS6H; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GCxC3SeL; arc=none smtp.client-ip=202.12.124.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="JvrZmS6H"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GCxC3SeL" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 4A709114016D; Tue, 5 Nov 2024 01:16:55 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 05 Nov 2024 01:16:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787415; x=1730873815; bh=6WNRruvS2n ZmwmAuGdZXSGwKSxMwNsEyxiW4tm2hJys=; b=JvrZmS6HWNLDlSYMoCqVoBIwFS japHt4yeM2cyx3nyq1PRKEDQ4fQ+UxLaL4/sAjoycQi11gSzXUxWWqSTjTV9eSap pPL3wskWzk/gMphXorEiPubIm994gLiwlYtU5RDR0EQL8sbkWsWNQ3SM8RjcRXk0 qPe7Py5QuxaI7mK+jUekRD/9uIAXvKEQeSBrdVnGK7x5zAQ4xgkNvlf540zRm4Z5 ztHwz47uWUOV1WZpJPCtHXgHFPf1BBPwI2KAKejIRjvyElmDMG4ANW3zWkAuKhAl Qww6dCoYDkuRkHFjECWuwPFi/Pg8jb/Fmqk48ONS6l0oSM3CA3qMYCKcMz/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787415; x=1730873815; bh=6WNRruvS2nZmwmAuGdZXSGwKSxMwNsEyxiW 4tm2hJys=; b=GCxC3SeLDq6nuz1Uj5uewIaWmsa+KJ+QLaGknWlXdYTaR2Ee2vY vbr5QvwQShEF/9WH2S0kJx8C1LUYxIJOxf/o41c4olTs4Xs1Gh4BV/JxKJJi1jyn jONtblUPnttiooGMst0zGGfdZowwVrZ+v6czhkyNF4NiNGaX89y8ui3wJaJYmTOw mQUm5FzJZGJfndkSGLq2gpvr2E1IGWVH/3+Y0+qH73lsfvmawGdd/a7iqkWrAtb0 pbrGJpeWM6H5xCMytmMLGVNGZhPnb24njDfI7nT4QzgK5Qnr5YsfOvnaQV1Yqd3t zCOdt5nnpXUZckQyxWYpK70e5kbHFvqohaA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfh grshhtmhgrihhlrdgtohhmpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdp rhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehtoh honhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghl rdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:16:53 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4937a3f4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:32 +0000 (UTC) Date: Tue, 5 Nov 2024 07:16:46 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 02/22] t/helper: fix leaks in "reach" test tool Message-ID: <17136f4bdb39cb1ccbcc06ec4867d7606fce2202.1730786196.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 "reach" test tool doesn't bother to clean up any of its allocated resources, causing various leaks. Plug them. Signed-off-by: Patrick Steinhardt --- t/helper/test-reach.c | 10 ++++++++++ t/t6600-test-reach.sh | 1 + 2 files changed, 11 insertions(+) diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 995e382863a..84deee604ad 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -127,10 +127,12 @@ int cmd__reach(int ac, const char **av) exit(128); printf("%s(A,X):\n", av[1]); print_sorted_commit_ids(list); + free_commit_list(list); } else if (!strcmp(av[1], "reduce_heads")) { struct commit_list *list = reduce_heads(X); printf("%s(X):\n", av[1]); print_sorted_commit_ids(list); + free_commit_list(list); } else if (!strcmp(av[1], "can_all_from_reach")) { printf("%s(X,Y):%d\n", av[1], can_all_from_reach(X, Y, 1)); } else if (!strcmp(av[1], "can_all_from_reach_with_flag")) { @@ -153,6 +155,7 @@ int cmd__reach(int ac, const char **av) filter.with_commit_tag_algo = 0; printf("%s(_,A,X,_):%d\n", av[1], commit_contains(&filter, A, X, &cache)); + clear_contains_cache(&cache); } else if (!strcmp(av[1], "get_reachable_subset")) { const int reachable_flag = 1; int i, count = 0; @@ -176,7 +179,14 @@ int cmd__reach(int ac, const char **av) die(_("too many commits marked reachable")); print_sorted_commit_ids(list); + free_commit_list(list); } + object_array_clear(&X_obj); + strbuf_release(&buf); + free_commit_list(X); + free_commit_list(Y); + free(X_array); + free(Y_array); return 0; } diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh index 2591f8b8b39..307deefed2c 100755 --- a/t/t6600-test-reach.sh +++ b/t/t6600-test-reach.sh @@ -2,6 +2,7 @@ test_description='basic commit reachability tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Construct a grid-like commit graph with points (x,y) From patchwork Tue Nov 5 06:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862361 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2749D1CACEF for ; Tue, 5 Nov 2024 06:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787421; cv=none; b=XcePBgCXaPH2wzaUaUD//Wv7PrRQ2bG18GbrSF7YxnJJOCwqJ0xMjnRarcb3BfcAksF2tPXPc8fUX66sHu4d43fS1kxaCVhc1rN/YfDY2qnFiQ3qcNkcaDUItaLdRgyK9us8Aea3mPUxE0oRAxHVVfRPMU/a9Q2RDqOuKQhdqr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787421; c=relaxed/simple; bh=G7tZqCi0CVju4B2rtHxuoVkvqGJbrcrJxaQ2Ji1Mc5A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ap8sbmkq98vIINhR9Wxt891o+iUCg6hvp8rBlWs6NObyYebkWOcppt6Ag8tIM3QQGAGZoDcxh5wY+XduzFiQ9Q5K9G0SQ+3nl7E4Gv7uSb+lgVjn2YOR1IhABMOHs4mXWto6+fy55NOKuoGFhq+4yIBGwSjBQrKHqRhwIYhUQVY= 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=2QppbHde; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Iihp0I1h; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="2QppbHde"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Iihp0I1h" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.stl.internal (Postfix) with ESMTP id 05B2225401A9; Tue, 5 Nov 2024 01:16:58 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 05 Nov 2024 01:16:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787418; x=1730873818; bh=1Xevuea/r4 DjKYwI98hRImH/XC9cv9WAastaqy4Zjiw=; b=2QppbHdeaDhQIb96n8Ro3n1pfN s0D1jE1AQn8euQpwopW/5lepmwpF7FpjKWdEh1W+/OL7JRfGZd3xFAhwkHQYlN7i THABvAx3AFObEYTsUePdOC2H/7Em/0YDO7JTW+7LqIuHdaRGTsOLEIYAjm4W+dgF jqEAEuKBGZNjBlkDD5k7U3OEBpSF1efZp5xOGZEqq7SgGov/Xi/BJFZm4UBtMBfe VPhdAdaCg2P42rk/40Dfn1W8//MC/AN0egdPqryw5dj7Medierr7gf6EomuQAGjS W5HTePrTgdwPPm9onTItqK5HXFXxGqg/Z2HP9ROPCKVpzYN1NROKmQwtOd3A== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787418; x=1730873818; bh=1Xevuea/r4DjKYwI98hRImH/XC9cv9WAast aqy4Zjiw=; b=Iihp0I1hDCUj+l+X9vogVYNyvMqbEv4inbOubsLkoFUtUm9wcbe CGNZ9qtFshv7qjta3laWOotPqWlqqOpMi5+seTYkjzfFn0ey8FqHpOmJ/vGKOpPS w+1puyYvi7cXDHHDULjA7yx6ZnEPOxgkjrH4UR23KgzKPysS3AoPfQwhx0Vw2pb0 TLaB6b1S8W2Gy6C+lWagDNDGxucceomkGb/EMn85mPttBYQRKQLlxLAbpW6NG25Y 4oW6JA3QUfXDvXvVYa9CqL/jMdZBYzApc4thys+0CbVcacFXL3UGA38HeljElFaG Wcz+g418ZfYUL2BLvDhg7K2OKsTL5LxnYCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmvges thhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgsh gsrghkkhesfhgrshhtmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:16:57 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 604fc5e0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:35 +0000 (UTC) Date: Tue, 5 Nov 2024 07:16:50 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 03/22] grep: fix leak in `grep_splice_or()` Message-ID: <74b214701942b6412965b53b3aec4580ef6fd242.1730786196.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 `grep_splice_or()` we search for the next `TRUE` node in our tree of grep expressions and replace it with the given new expression. But we don't free the old node, which causes a memory leak. Plug it. This leak is exposed by t7810, but plugging it alone isn't sufficient to make the test suite pass. Signed-off-by: Patrick Steinhardt --- grep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grep.c b/grep.c index 701e58de04e..e9337f32cbf 100644 --- a/grep.c +++ b/grep.c @@ -756,6 +756,7 @@ static struct grep_expr *grep_splice_or(struct grep_expr *x, struct grep_expr *y assert(x->node == GREP_NODE_OR); if (x->u.binary.right && x->u.binary.right->node == GREP_NODE_TRUE) { + free(x->u.binary.right); x->u.binary.right = y; break; } From patchwork Tue Nov 5 06:16:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862362 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 AA2A11B6D04 for ; Tue, 5 Nov 2024 06:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787426; cv=none; b=mXQMGyWWdb2sMuBcv+VGPMaXhjU3twU8ajr27P3OxDx3xV+9V6fO1FG2Rs2q9Hglruinf5wYgSHF4VhcEoWunE/QKYOjlKyKGsfEqAg6z0o4j9SJ3K4ewHpCpE02KiUE7J78QqdlSRZWfIeWdjnnxOYIeOlkAYMtY59iNhsE+j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787426; c=relaxed/simple; bh=TWDd2MZ4m3r4gK7/RsRXm+qIM26EHfeUjYYkQWpN9jM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I5YDM9ao7rSk0/xvrvzkJaB2+Ltqh16bfWPd01sOl0i6xAs9B6kEerJ2DCtMXZ26L1qR0SMYwmyV6JQu2bclVAh+ifUslGzt3uzUQM5kC7SGZ48/QOY94sEZKJnLhbEYpGwaNFxuS57gFHIgGbV8x4WrfZgBCudF20JUwdyZSEY= 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=ec6fAywC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=W+G9BZKv; arc=none smtp.client-ip=202.12.124.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="ec6fAywC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="W+G9BZKv" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id B53AB114016D; Tue, 5 Nov 2024 01:17:03 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 05 Nov 2024 01:17:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787423; x=1730873823; bh=v+wOuqPYeP QZ4nSvEMO0RUZTg/18UUqRdIndd1MEBg8=; b=ec6fAywCZGTq2UXCDFLSlAYKWR FViXpmoTOdDtpbYFGr3NU0guiRQRgrceyeqPWcmFVvDOKdKtQU9697mxsqkgJq+y OQ9T/mB8m3P01rVc7HFlDg03ZDaycxvbfoZZr2kwGhWancpDgKoa2o5o8vksK4Mf Kebpx21eMbvrOyLElcvaJ0H5O4tG43IGmGno+TW6df3M4vQJAu5dZV/wfP9JxmzM OBZU/HAEIntBBTR7fZLI1TTqDkpbw17X4aseOJurrWIVnZSybv/jr1Z+n9vTZEyZ V9ocq/nu2kwQK8MHukyjISgaAof5AfIdJlXrM97far2Fr1JBx7TuieWpyojg== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787423; x=1730873823; bh=v+wOuqPYePQZ4nSvEMO0RUZTg/18UUqRdIn dd1MEBg8=; b=W+G9BZKvoW3biDx2SO96yLXzVcMI2U7UJ434mfP2Fn03AEf7BAX zgSt0NjDxLcmOXrRgtydPwbk6wWyBXEQv/83ULkVEkW+WxNWixQmd1y9NIOq1vKa XaBDX76J25W+/SioJiOG2ElTq4Y3Ot3OiE60j6GHQraVt+/LIYhZL6qQIah6YIhl F5kzrPxeJUAA4q+UOtEstJ4RU8T/7a+cGgI4IF31gbuUko5qq0thPoR0dCtoRQGO +hPGLmkxwb9QujYYW2SHjIkviYzmLrGO2TP2wUcHcoMeEVDCoxNVFqkIJFIkbBEf JsZkddQ0OFioiZzLoY1b8JekpQ6zF2Rx6eg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfh grshhtmhgrihhlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtohepmhgvse htthgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghl rdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:02 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ecb4a12b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:40 +0000 (UTC) Date: Tue, 5 Nov 2024 07:16:52 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 04/22] builtin/grep: fix leak with `--max-count=0` 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 executing with `--max-count=0` we'll return early from git-grep(1) without performing any cleanup, which causes memory leaks. Plug these. Signed-off-by: Patrick Steinhardt --- builtin/grep.c | 13 ++++++++++--- t/t7810-grep.sh | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index f17d46a06e4..98b85c7fcac 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -906,6 +906,7 @@ int cmd_grep(int argc, int dummy; int use_index = 1; int allow_revs; + int ret; struct option options[] = { OPT_BOOL(0, "cached", &cached, @@ -1172,8 +1173,10 @@ int cmd_grep(int argc, * Optimize out the case where the amount of matches is limited to zero. * We do this to keep results consistent with GNU grep(1). */ - if (opt.max_count == 0) - return 1; + if (opt.max_count == 0) { + ret = 1; + goto out; + } if (show_in_pager) { if (num_threads > 1) @@ -1267,10 +1270,14 @@ int cmd_grep(int argc, hit |= wait_all(); if (hit && show_in_pager) run_pager(&opt, prefix); + + ret = !hit; + +out: clear_pathspec(&pathspec); string_list_clear(&path_list, 0); free_grep_patterns(&opt); object_array_clear(&list); free_repos(); - return !hit; + return ret; } diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index af2cf2f78ab..9e7681f0831 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -9,6 +9,7 @@ test_description='git grep various. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_invalid_grep_expression() { From patchwork Tue Nov 5 06:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862363 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 700841F754A for ; Tue, 5 Nov 2024 06:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787429; cv=none; b=Skl4mbO98IBi5/uNeqnF6F12PXy+m7ugBvf158lau0wcVaY5hfugeuvGzwRJbgFHL5WS7mIxbrjCV/bO2cUIMKIeMGs4GD9RwLl3HDlQm1DOlnXamTmHEkk1UGLn9sFgUutZU6bUuv4PqHgzir1yiMZeFoGAAIEdE1NHmpf5tEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787429; c=relaxed/simple; bh=kneY1QSORzARx5Ng/w+RbzYBwGdX4fkj937wxi39PqE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UcgLY/7L0uSyuZlfXEY9LdRrkSgrc9nI73ZGW1XQ3Kp4vuB+D1OlNSxRSUAXN8HUOsbkMgU3tX6BMxoIsKpy3E01KU10RlJmn29HiRSUc1Kx0UapoBmRZF7sJEm+7v6pNntLjqh2cdJPat8WtiUfi4ic/bzF3Nv0o02218wBv38= 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=OT25LXCq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nSwywtWN; arc=none smtp.client-ip=202.12.124.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="OT25LXCq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nSwywtWN" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id 6F5061140162; Tue, 5 Nov 2024 01:17:06 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 05 Nov 2024 01:17:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787426; x=1730873826; bh=5jJ1K5EsbA HNvVPvIVNIaiiBV/BkQeW1zHmtuZxF8H0=; b=OT25LXCqBTzGXy13FDmb/YfLiW hHrTK6YZ1kCuHhxe1vmDyhcuSs7w3PeQHtDQvg0ltXHVCyMBVC6Dku3DziZXFl7+ m84KMJaxX2xuEO+R6OpRBZCkBkKx1EJcLSyvZv8s46FVANU3z4qVbrdA+MeL/pCj UQUNTJxYWjgItRZWDoas2GCKQnEneN43Nk0gUeNzhYtNOaBkq5T37/RxIZLY5qFC PwNG09rkxeNphyA4gFbocVBC7YR7w4BbUjswFqlgOI32kkXKn/TE2UiRSTRq+Tp7 bgFkDjJ8RuTH3Tcdq7QK+pxmo4Wb7aH2eATuSNxQpAfrXXIdAk0Mj009Ej4A== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787426; x=1730873826; bh=5jJ1K5EsbAHNvVPvIVNIaiiBV/BkQeW1zHm tuZxF8H0=; b=nSwywtWNTZUVzOUyUmlwpfrj0liYPzDQFIYw1t9PuKV5J0deJfR f6iK2Kq2sRD1l/r4bneJ1JJhXAYfthpCjKqzizyF4zS7AvAkH3Hr+mHSQjYIp727 DWnCELbp4qAe3V5lryLkl2wc7M3+TAB/kL2+qpR2UGdcSCNA3r4tHgXxRPj3iyRM IFGWwo/II41LBXs32xKUa2zsSc1WnIB7Xhto3cJVNrULOq3tojBW55hQc4SNUSFa NXs82V6h+KuxwM0ptH1nb8+jdgeWEjjwyqNz0IW/xs8dM8cY47D5qDzqbeHK+O1L x4apJs30Z0O1wljOE3sUVVA4iayBQ4w2ogg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehtohho nhesihhothgtlhdrtghomhdprhgtphhtthhopehkrhhishhtohhffhgvrhhhrghughhssg grkhhksehfrghsthhmrghilhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhr rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:05 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5b5f4c55 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:43 +0000 (UTC) Date: Tue, 5 Nov 2024 07:16:58 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 05/22] revision: fix leaking bloom filters 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 memory allocated by `prepare_to_use_bloom_filter()` is not released by `release_revisions()`, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- revision.c | 5 +++++ t/t4216-log-bloom.sh | 1 + 2 files changed, 6 insertions(+) diff --git a/revision.c b/revision.c index f5f5b84f2b0..8df75b82249 100644 --- a/revision.c +++ b/revision.c @@ -3227,6 +3227,11 @@ void release_revisions(struct rev_info *revs) clear_decoration(&revs->treesame, free); line_log_free(revs); oidset_clear(&revs->missing_commits); + + for (int i = 0; i < revs->bloom_keys_nr; i++) + clear_bloom_key(&revs->bloom_keys[i]); + FREE_AND_NULL(revs->bloom_keys); + revs->bloom_keys_nr = 0; } static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child) diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 3f163dc3969..8d22338f6aa 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -4,6 +4,7 @@ test_description='git log for a path with Bloom filters' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-chunk.sh From patchwork Tue Nov 5 06:17: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: 13862364 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 187C21D79A0 for ; Tue, 5 Nov 2024 06:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787431; cv=none; b=JEHix2J+dx83diGeGwqXJZWnDiq3WnfyQarHxRXoQo46cb97HRTCD3v55LZvoChPMzG0hZxpIBNiNapkIVDGAkRviM0tCd9qJRtriEuRLfQv1C6u2e+l7n3Hb6g4Ev7KP0TZxmJR5hne1RMgTMG6ljFIpg/HZxt+aHXcerYdKUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787431; c=relaxed/simple; bh=mdnT9ygrsskBZbcvuAf3VgmBYmZx9tq3nf0qNpRzWnE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OYavzfDA2HOGtI0ztubA5EB49b1KH86O/x+6YnW1vfyLRh+0QSGbTFsWk1yqmIJUIhWiN8YMGMtq3ThM73j5QpwlmH0SDiDO63CXJNwhCsqbJQRdTxvfTKArZeupdJuCHe2irAuvT0f9jUVDYrtrx/Z6FbLfxFzdwMORay6N9nA= 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=o0DgXMi3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dX+SnoXt; arc=none smtp.client-ip=202.12.124.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="o0DgXMi3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dX+SnoXt" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id 1E220114018C; Tue, 5 Nov 2024 01:17:09 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 05 Nov 2024 01:17:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787428; x=1730873828; bh=gbB4E3JCqA 3GS6dqkfiu9Ldcvc3naSIksPLka8oX0ss=; b=o0DgXMi3hVup+KrewmooUZX/Fx yyF2DsQwv4sU1Z/gi2lCEZUM6u0m5THTxx3/s3ZF6d2HvXpyg+LdUfwLsuS0MUXk anuhfrM/msKgrf71jjNkytMnCZ3zhSz45fCOZ4xCQj0JqmqF5BNCguIo2aUZ+pJx CuRxe6khH03Fy4pV+cogw5GdMyER6xGs/rkFtpZU7tDP3RmnSaFlJz51yCGgMJ2u vLoHrQ8+CVMWhdOnRMsaCr95P3gxJMgqjSQ4XDOgZKWZX/Rc4um3g+i838hO6ylQ MUN20vnerB+LWTskzjKWHlOGrPZi0+vM14RhtABQyWnzqaoIVX5JsENWLDJw== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787428; x=1730873828; bh=gbB4E3JCqA3GS6dqkfiu9Ldcvc3naSIksPL ka8oX0ss=; b=dX+SnoXtV/Mf8RQ+M73ZpdJy1ZIxnbOkGRTMZstNGpF/zWfhAdy RXTfH5aLzhxgzpTC71qIyVtObGYVAslzf9Tv84Hry9wCXmDEuvKB7A29guOFtdj1 7AZy0inXzfZOWHc/tO4h4HzaBhOsC46pojc2+cLbMVG4szcOFhLCc8Lfx6/gpubF OnzpbP8KpU+cRoC4a1Bm/+6nMKJNquBR+7jdd/A8ee6y/V3lmkwkiqHOL+QSMLDG F3PEgXYb6+Epzz3ffbO3YCuMZRGbd9eH7ve0YWG+4dhOAB8WCimHEF4CzN2IA02G e1IhLwxEqcq1yk85uvq93Q0xjDoQg7wtEJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepgfefueeltdfhfefgteehfffhffegieeukeevteefvefg udelgeegueevudfhveeknecuffhomhgrihhnpeguihhffhhophhtrdhnohenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm pdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehtoh honhesihhothgtlhdrtghomhdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdr tghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpth htohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhlrdgtohhm pdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:07 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id cf3ff7e4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:46 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:00 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 06/22] diff-lib: fix leaking diffopts in `do_diff_cache()` Message-ID: <24d9d9b1358d55dd304aea064515b61830a12b21.1730786196.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `do_diff_cache()` we initialize a new `rev_info` and then overwrite its `diffopt` with a user-provided set of options. This can leak memory because `repo_init_revisions()` may end up allocating memory for the `diffopt` itself depending on the configuration. And since that field is overwritten we won't ever free it. Plug the memory leak by releasing the diffopts before we overwrite them. Signed-off-by: Patrick Steinhardt --- diff-lib.c | 1 + t/t7610-mergetool.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index 6b14b959629..3cf353946f5 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -661,6 +661,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt) repo_init_revisions(opt->repo, &revs, NULL); copy_pathspec(&revs.prune_data, &opt->pathspec); + diff_free(&revs.diffopt); revs.diffopt = *opt; revs.diffopt.no_free = 1; diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 22b3a85b3e9..5c5e79e9905 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -10,6 +10,7 @@ Testing basic merge tool invocation' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # All the mergetool test work by checking out a temporary branch based From patchwork Tue Nov 5 06:17: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: 13862365 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D01AC1D79A0 for ; Tue, 5 Nov 2024 06:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787435; cv=none; b=Z13Qh6Z6Detk9gZI3HL02oLaD6L5oSLikbTEE1rZcmTGmv6HVSJRgiCJKMWsM5HLcneQXR5qIsm0Ptt2Ynk8AKe7/YTl3kovN9Yxc2N2Y5+gnc0fNh6QcBp17Gra02rsQjfv1jSzXz+Wblxs+0RXpgbEKzHqS1TpYaQ2hePuldY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787435; c=relaxed/simple; bh=2TMfsOTIh3JnTCD9b7qzzyJwvE245Yzp/a3IFACQGu8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XjfCemU8WSdSaijhDJD5wgBT4/P8iNUva6js1lG+UIwq6Cp4BuZo3XhnxGM8Mpw0J7ZfGUv/EAoCBkjDE3Oyl0wcEWWzqq+PQZH4M3P6J/t51fycXAJmfnxQNJJ0rmWGTZVJgeDi+HLWvMloqlTLpri5a9sFhkj+ZUYQ9hWeAa4= 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=YgFijdEJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QWfkl17C; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="YgFijdEJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QWfkl17C" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id D4E7D2540076; Tue, 5 Nov 2024 01:17:12 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Tue, 05 Nov 2024 01:17:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787432; x=1730873832; bh=DtfNjyoyKH ah2GOxH1ObLOaR8hni855r4j0yqFHbY34=; b=YgFijdEJ7UaXP4z8jWOPIYkqFD czUJpYjr/3nSkRVxG8qjn14eHE5+3jaF3QzuUHJxVTRF5zwv05RlqYIAr2smK/0+ Z0VtPiIVKCxrsc4I92uD8qIrLigG2clu4eVzMltycx6YWAxYgXSDyDS9muYGmxDK EeO67lPJCWeVTjiLZ9D+fmWQcJ+cg5Wi78FiyYLNJet6ryDmWVSu5foiEZ90J74y dUpnjnJPBgRFW2HF4WacjDnfjg6ikODeUQWbbcxdT5DCx+1PxWV/x9u6RHXrKUdG mJ0E1LKI65PgvNKcyenTv62UihDLn/KOdKCL5dguUt7gMH3PwtZNtbocS/pQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787432; x=1730873832; bh=DtfNjyoyKHah2GOxH1ObLOaR8hni855r4j0 yqFHbY34=; b=QWfkl17CtSsRZ2hRKrO5ekmL0wGs2gQt1HyDxtBxSicKIVyEaV+ gS7W82pJ+49TouaYm2EUpFUQVcR0HyyWzyA+vUSMNBVyia1iWWB83n29X5bW2GT3 cB74fl/q3M3F7aLLlgWJFbp1ygMbVsD7QmnoPqLeMN+U7ntJqJpFX+3T5oDBigHV KJL2Hbwd6ZblAZ/eIc2Wzt0XkK0X7uyN8IjnjJaaMfBDM9WNvRJGx6GmFXSU/Um2 m8QQkcVAn2GydzhrcnA/xxwDdn/vIqcgMOfvy2ciX6nZX+6j0MgV5f+r4VGO09wB u/UXR89dZCem6aJ9rQnJZDBgOo/k16pAVyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfh grshhtmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhr tghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgvse htthgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghl rdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:11 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 96da6a67 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:49 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:03 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 07/22] pretty: clear signature check Message-ID: <58ebef7e757803bd7c2292f0494386464f2c581d.1730786196.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 signature check in the formatting context is never getting released. Fix this to plug the resulting memory leak. Signed-off-by: Patrick Steinhardt --- pretty.c | 1 + t/t4202-log.sh | 1 + t/t7031-verify-tag-signed-ssh.sh | 1 + t/t7510-signed-commit.sh | 1 + t/t7528-signed-commit-ssh.sh | 1 + 5 files changed, 5 insertions(+) diff --git a/pretty.c b/pretty.c index 6403e268900..098378720a4 100644 --- a/pretty.c +++ b/pretty.c @@ -2032,6 +2032,7 @@ void repo_format_commit_message(struct repository *r, free(context.commit_encoding); repo_unuse_commit_buffer(r, commit, context.message); + signature_check_clear(&context.signature_check); } static void pp_header(struct pretty_print_context *pp, diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 51f7beb59f8..35bec4089a3 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -5,6 +5,7 @@ test_description='git log' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" . "$TEST_DIRECTORY/lib-terminal.sh" diff --git a/t/t7031-verify-tag-signed-ssh.sh b/t/t7031-verify-tag-signed-ssh.sh index 20913b37134..2ee62c07293 100755 --- a/t/t7031-verify-tag-signed-ssh.sh +++ b/t/t7031-verify-tag-signed-ssh.sh @@ -4,6 +4,7 @@ test_description='signed tag tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index 0d2dd29fe6a..eb229082e40 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -4,6 +4,7 @@ test_description='signed commit tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GNUPGHOME_NOT_USED=$GNUPGHOME . "$TEST_DIRECTORY/lib-gpg.sh" diff --git a/t/t7528-signed-commit-ssh.sh b/t/t7528-signed-commit-ssh.sh index 065f7806362..68e18856b66 100755 --- a/t/t7528-signed-commit-ssh.sh +++ b/t/t7528-signed-commit-ssh.sh @@ -4,6 +4,7 @@ test_description='ssh signed commit tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GNUPGHOME_NOT_USED=$GNUPGHOME . "$TEST_DIRECTORY/lib-gpg.sh" From patchwork Tue Nov 5 06:17: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: 13862366 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 41E481DFE8 for ; Tue, 5 Nov 2024 06:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787437; cv=none; b=iJx5prvRq0ELXMauwdoyvoYGF1rI81pn5BYkvQYD/sEcaLEm31YcvPeKq12xwJkk9qNVlL4lzDw22VUqrCA1pLzNe/vmjSrpP5qg0YChrVFNq6+EaFCKNjzccloLb9eurlFWLJYFokmNgHiDo8ix67fUkht05slevv+1/yt/wmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787437; c=relaxed/simple; bh=jeDgV6xmnE8Hg6BGySLVEiBIJtsBlhbI4LTRIR5Nl+k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JosND+GsHXEa3VDYvjPeH8D/ldrPf1VSFBb7diAqdnUer0nXU2PZuMF6i0iB5I/sHdBT0b0kqzEoQ0vXT+ggAzlcjZ6mf5GzgqhiVYREhUraJDBv6bMIaiuPRbxZvhqVcNE7/hsj0aT0JZ52rD9cxN+k5xrug/FquBCHKzxEKjs= 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=WvV3p96k; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WWHnkP/9; arc=none smtp.client-ip=202.12.124.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="WvV3p96k"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WWHnkP/9" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 84E3311401C3; Tue, 5 Nov 2024 01:17:15 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 05 Nov 2024 01:17:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787435; x=1730873835; bh=dYdnbtXUXj 61tzkzZZcrdct4dMcUhhKwFB3yh7/LGT8=; b=WvV3p96kIkFlL96rwxdHgq3DOK GuwVBnsW8blsbjm3i5uWFNOi+o3k7t38jfGdF8mZajte1yu84iu9CMrfSabSLs+w ccqhu9KQwfiqJ4cJKmDQbK5SroA9Ky8mX1cD9jsfZdIc3zeBZigC5J9BNavyTOjb WxMYcKHyxwg+1OJ//27OZsvBSc6jaWvwm18/GHp4ndOciHjEr4p/BNjScweXFDoC QJHs0GfNVpMewUx59a4WJMw9uXhN0ac6QtgmCeVnTa5yy8LuqgO3JVeEtttXnMxG 4jtcX51OA8Cw2xwz+H6QvGdVrfmpM7MxKZDU7AWkSyUkCWGZKnPbpO2WEGbA== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787435; x=1730873835; bh=dYdnbtXUXj61tzkzZZcrdct4dMcUhhKwFB3 yh7/LGT8=; b=WWHnkP/9o53xjswlIXaWZrZmDQ+NknheKQTfc3pdz+GouICopFf 6OD9fktRpISUMu60k6O9HVVd/J9wkbON6/XnjIQD1uLXYYjKKJwVjpmWVTwmYv80 2xy3Bexo+uxo5wrACSI4BTtpFPswXNkXmN+7RqeBVNN6kkuvWet7pr/s9ObKY0aF nN/+Fg7gkSHMZV085lRAhPL0mGCV9bOIQytZieC5XwOc+Z9rSvjmak83d1U1u42j pm6QSV0S88K4Pxp4pogHAl7jAKiDq+2jONYVBt+thsEh51GrehgLIdVOhicrjUiL xd21JPVwMIhu++864Yn7W68Ut9JlsOTF8iA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhhishhtohhf fhgvrhhhrghughhssggrkhhksehfrghsthhmrghilhdrtghomhdprhgtphhtthhopehjlh htohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhr rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:14 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 48e94aa3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:52 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:06 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 08/22] upload-pack: fix leaking URI protocols Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We don't clear `struct upload_pack::uri_protocols`, which causes a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- t/t5702-protocol-v2.sh | 1 + upload-pack.c | 1 + 2 files changed, 2 insertions(+) diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 1ef540f73d3..ed55a2f7f95 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -7,6 +7,7 @@ TEST_NO_CREATE_REPO=1 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test protocol v2 with 'git://' transport diff --git a/upload-pack.c b/upload-pack.c index 6d6e0f9f980..b4a59c3518b 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -166,6 +166,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data) object_array_clear(&data->extra_edge_obj); list_objects_filter_release(&data->filter_options); string_list_clear(&data->allowed_filters, 0); + string_list_clear(&data->uri_protocols, 0); free((char *)data->pack_objects_hook); } From patchwork Tue Nov 5 06:17:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862367 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28F5B1B5336 for ; Tue, 5 Nov 2024 06:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787440; cv=none; b=s+VbEP47kadXsz0PdHYFF7juP7dRT4RzQ8vebJX7XpvHDeXvVqQHXoL9RJKXsWXL8udwzeLi6yZIYaNdCZpgBW+DPJ4wFI6+LZxbGlRYY1DFH+w0YTWK19Hd6PXhrfuV2vkdixV0aIhZ0C3b06p0+FDD19NjE0Dl7DeTYjRwFlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787440; c=relaxed/simple; bh=AHj12aPbiHWS0uT00uKb8x1tEpfNZwM6VzMgIYEBXoQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UMYDDX+teSkUmbnmKwHqZm5UWqJYbluPp32b3DHm2QJ0BqewsXRuDI5sTsV5fmpEh9F2SJ8Wd/UQeKGFwmO7VKHvrhezhaiDiUzK4B9sSCwb7+NcVffIOxU1hMLAXj1ZAoFx7MkUdUiYyRaJ6qboyq9IGXuwj4SOJid8wjqqbp0= 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=PcPIyp5U; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nLJ6wwLC; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="PcPIyp5U"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nLJ6wwLC" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 3D18F254018A; Tue, 5 Nov 2024 01:17:18 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Tue, 05 Nov 2024 01:17:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787438; x=1730873838; bh=e+UpPi9o6i oJNhf/Hp4D4oNtN6bpU3HATOuD2XSABtg=; b=PcPIyp5U832Pl+LqeWcCNI8MIr RML7q7lp5LwAziaRRnEd5GoPjNjgUSyvB8av2TLW4lijIM3S63GJKHzQ8Js62C7s zDXkVRdmm4/4A4ApGWzfmbK8H0gT3azQeaLwRrfifuody+wZt6lrD9hDU8LNPd5M cqXRUKgCR6ct0yF0HZ/2i+Mqk4RHe90Hkh870ljKF+TmBjk5bExLJ1gqYbhOiXDq i+2SPbWCKTxZ1Gd24jGkPPAazuqrPxOC28pjZjkPmk8EjHSRbdMjfYBIQjjuxyFW HBnuIoI5xXp2ImbfAfpxvmiAki91RuIC7McIZPk3MCfVyT5NNrFOntHw/YEQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787438; x=1730873838; bh=e+UpPi9o6ioJNhf/Hp4D4oNtN6bpU3HATOu D2XSABtg=; b=nLJ6wwLCT1W4wgEGcZHUkCs3Z0DPpLUVrG3OTOyCkAWw3Nc2uTX PZ6LnHQmjxiiK3z9H6x1E9jEprZkubAJEPLCdR4PPtqAJMf01aqNNhVb77tw3U7i 69yyIix33cOOUaUtQJ6T42UPUVKeOuQubR1NxlwtgI8oqmpQgueBv345EJ54ODAu 2INSNHzJemE0TuWSHL50c6cNxwjxpo3Vx9HqtyRyf414QnB8U6Tw6dnSVQMZ48Yu XoIJP1cN70eSs1YiFD9JRdd1pHs85M+i68/oW6BxcV3nmke0Ud/RMaYQygu1D1ub 3DsSz7Sa2gaj4ju2IYQpwGiVeifD31c49dA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgtphhtthhopehjlhhtohgslhgv rhesghhmrghilhdrtghomhdprhgtphhtthhopehkrhhishhtohhffhgvrhhhrghughhssg grkhhksehfrghsthhmrghilhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhr rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:16 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f379c41e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:54 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:09 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 09/22] builtin/commit: fix leaking change data contents 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: While we free the worktree change data, we never free its contents. Fix this. Signed-off-by: Patrick Steinhardt --- builtin/commit.c | 9 ++++++++- t/t7500-commit-template-squash-signoff.sh | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/commit.c b/builtin/commit.c index 8db4e9df0c9..18a55bd1b91 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -728,6 +728,13 @@ static void prepare_amend_commit(struct commit *commit, struct strbuf *sb, repo_unuse_commit_buffer(the_repository, commit, buffer); } +static void change_data_free(void *util, const char *str UNUSED) +{ + struct wt_status_change_data *d = util; + free(d->rename_source); + free(d); +} + static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, @@ -991,7 +998,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, s->use_color = 0; committable = run_status(s->fp, index_file, prefix, 1, s); s->use_color = saved_color_setting; - string_list_clear(&s->change, 1); + string_list_clear_func(&s->change, change_data_free); } else { struct object_id oid; const char *parent = "HEAD"; diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh index 4dca8d97a77..379d3ed3413 100755 --- a/t/t7500-commit-template-squash-signoff.sh +++ b/t/t7500-commit-template-squash-signoff.sh @@ -7,6 +7,7 @@ test_description='git commit Tests for template, signoff, squash and -F functions.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh From patchwork Tue Nov 5 06:17:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862368 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 A5EB11B5336 for ; Tue, 5 Nov 2024 06:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787445; cv=none; b=A9MBUgaoSK2SAFa0+lyZPnSWc+RbPzkCz1HWdK8uDJmhE9TpkXop9EUp6UxGfgeeUIHlhUsaOMJA4FObQWf29l7SQTPvT6NOlU8u53MK++RwNWDvaOxNr8+CdfVWwyuo1IxatEOh0B7uXMMh3L6aAnYPf3vYJrayb4fee1V7Ew0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787445; c=relaxed/simple; bh=kE9CG+AKANsk+W+5/LZNpEMG4u/baXAte8+JqkzM9Fk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jfXGMdIoJAf+0vijZ5G83KD1jgIPNx4pRD8hHAPklcRIFPYf1bSwizyUwGuiOgE96wHDQjCJ4QvhcmR3vADI4vrh3Fu4jjye5uFLur++QVJfv8qz1P6b0I6Y5YxVpClVpYl1qTUH/jrr+xaOFXklhWqFf+1t85lxx7AcIcSENRs= 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=e60k5Xfk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lpfekX4Z; arc=none smtp.client-ip=202.12.124.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="e60k5Xfk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lpfekX4Z" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id EF3EB114016D; Tue, 5 Nov 2024 01:17:22 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Tue, 05 Nov 2024 01:17:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787442; x=1730873842; bh=pWdazviE/S mKHExwZ4qusnmGTDZvg50nQoKlog/2OuI=; b=e60k5XfkpQPt7kT4hMm3uKelAS RTWSaGJLWMfNHTPIBNR7nG/iBxcO29lTbnHHaQNEmjSnL+50CyxgdemZwixG+QO5 qCmpUYF9rnaxe8e9KeyXo9dHLW6wlvqqSGxUfQxOLFykitrsaN/XZk2/LtEOMUIn /FEFEECxRKV8G6AlAasV5mUX9f9M5Lqn4kQMznZgDjnPsZ7S/qwqui0vJ+3WWcOn Ds8IOIjM5QcJotDBaVPHRGvkEQR2GRGOZXOdPA1UojPLjx4rhhwFu/1s+rDXAswi /z73WkNkpfT2knpQOYkZQIhk7pxAKxYWac2/xw8hD+aNfwV49MH4M9DkbY3Q== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787442; x=1730873842; bh=pWdazviE/SmKHExwZ4qusnmGTDZvg50nQoK log/2OuI=; b=lpfekX4Z8YNq/ukD7qMZsx3YQfOlSkrWXLsV1JorMrpU+Pjiq0d uvCvL4QOJsU5BJScU6uiBqflOljEhVYSzrpENW7VMCVq36cK1SwB6bpfF3eFCZR7 lO7AoIc24SuVPlhU+X+2SN0YLwNpOMFj7pDvdDW6usjlgdgPSt962Fn6gNYtMJQo BHBLJanbmXVjyIcGLjU+owvLAS+cRYePTg1z47IFPcQjjIie9AFe6AyFsyjDIVsO eCNSLkr45BP9xbZyRmbLSUOjw1QX1YXSa1ymXLMcYD9Pe2pQ544SWNI0V9dKLnN2 w+qPmWLRaVXbLPS9FMTtBedtG1QKDGz+RQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfh grshhtmhgrihhlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehtoh honhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghl rdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:21 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 382ff353 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:16:59 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:12 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 10/22] trailer: fix leaking trailer values 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: Fix leaking trailer values when replacing the value with a command or when the token value is empty. This leak is exposed by t7513, but plugging it does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- trailer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/trailer.c b/trailer.c index 682d74505bf..6bafe92b326 100644 --- a/trailer.c +++ b/trailer.c @@ -249,7 +249,9 @@ static char *apply_command(struct conf_info *conf, const char *arg) static void apply_item_command(struct trailer_item *in_tok, struct arg_item *arg_tok) { if (arg_tok->conf.command || arg_tok->conf.cmd) { - const char *arg; + char *value_to_free = NULL; + char *arg; + if (arg_tok->value && arg_tok->value[0]) { arg = arg_tok->value; } else { @@ -257,9 +259,13 @@ static void apply_item_command(struct trailer_item *in_tok, struct arg_item *arg arg = xstrdup(in_tok->value); else arg = xstrdup(""); + value_to_free = arg_tok->value; } + arg_tok->value = apply_command(&arg_tok->conf, arg); - free((char *)arg); + + free(value_to_free); + free(arg); } } From patchwork Tue Nov 5 06:17:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862369 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AC061FA25C for ; Tue, 5 Nov 2024 06:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787448; cv=none; b=lj7urEqUkRsJ6Ex5jHoZMGsk6WoZ3FsFFLtifCelokwybkuLqdmRXrAAo8/KW+XDt/vTiE1FdW3dvPYvugxVFapoTcItcdkMt0YhkY9ClDNj0IydUgPC+2QK6uUUBoI63zBA56mDBM9x0KztBrsUoAKUkHw/vNjh1j5aPiEmZUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787448; c=relaxed/simple; bh=vA4Tf9iTVhnFO2ImhPZl5QHn+1iBiA9FclnOFl0t4qc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Znu0DboUI/8i4JGPPIo2j1C/Wx1H5H9nEIlU6xlAdALgcTcTimjz4LljMIt/s+VdW4WEtuY98mcST52Sp4gXN/nVHtuldwNGy/vYXIQtpt+LI9JyQMv6OAKLho11qGsojlzyYAafGdjkRRspZQ5IXnWPP5BG5n57yWpezlqCAik= 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=TyQIqkrG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UMb0+Rb2; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="TyQIqkrG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UMb0+Rb2" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id B243F2540076; Tue, 5 Nov 2024 01:17:25 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Tue, 05 Nov 2024 01:17:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787445; x=1730873845; bh=XmXwYZVWy3 D5JIX08C7nWbknqetoExDfb7x+zQ0GwNU=; b=TyQIqkrGicvZr4xCvlM1XSP39X YFTQgWCxDWdebZRbaGFZkgiUroQE/l6NR079ldTxJacRAh/ucF/jHTMOg0UHN4M1 lEHVsPLeKK54rpQfpam51x9fuaksTLat10tC0I0GslOq912NnIgF1CchCj1zhVhP 5lOw8ugIwKztCxWM4eW/J5Ser/WTC545vaBekGY6hjyyYSFLNdjHybln6VgpAxhK BWDFHSkQfrlp43bGowSgIg4M2UU2RLUhmhNJ7fFEH7BwccApLdZ8Ho0XhjKwVw+d PIasXvUSt2mOCyJA6otasXLe3c12wwZ8rW/0PdQdu2aG+8XBSNP1NzY1tj4w== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787445; x=1730873845; bh=XmXwYZVWy3D5JIX08C7nWbknqetoExDfb7x +zQ0GwNU=; b=UMb0+Rb2XQW64hAFUlk1VxghBJ9QMCdCR9g/iMv865AzZViL5Ra 4DP/3r0uK7/3mjntl8XKa+RXSUk4IaGACC9E/9QGOPIhPBv4TTesu3W17dD/1X0Y gfF0C0Jp2BJzJ8w7Wy4J/GCXje+w3KPflTju1R8L2t1J40Z74ClCHXYJRwnBoNJ5 564s87zY+JFzLZmClxxF3OwnkrTtkL7uvVYHfyVoRwVuKSEIDzKQte8icVW0wVwh 6FBoct/9wbGDlVEGv3u341EnWRtoPIY75PwsICyeQPoosul44MgF93jSiXtNCUPt 6jJOgZAQJUQiI/PWdyut8aexUerTZ2FE4dA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtth hopehkrhhishhtohhffhgvrhhhrghughhssggrkhhksehfrghsthhmrghilhdrtghomhdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjh hlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:24 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bf788c7a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:02 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:17 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 11/22] trailer: fix leaking strbufs when formatting trailers Message-ID: <82269e5d5be012f24f52504986a1eb043b9dc17a.1730786196.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 formatting trailer lines we iterate through each of the trailers and munge their respective token/value pairs according to the trailer options. When formatting a trailer that has its `item->token` pointer set we perform the munging in two local buffers. In the case where we figure out that the value is empty and `trim_empty` is set we just skip over the trailer item. But the buffers are local to the loop and we don't release their contents, leading to a memory leak. Plug this leak by lifting the buffers outside of the loop and releasing them on function return. This fixes the memory leaks, but also optimizes the loop as we don't have to reallocate the buffers on every single iteration. Signed-off-by: Patrick Steinhardt --- t/t7513-interpret-trailers.sh | 1 + trailer.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 0f7d8938d98..38d6ccaa001 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -5,6 +5,7 @@ test_description='git interpret-trailers' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # When we want one trailing space at the end of each line, let's use sed diff --git a/trailer.c b/trailer.c index 6bafe92b326..8ba350404d4 100644 --- a/trailer.c +++ b/trailer.c @@ -1111,6 +1111,8 @@ void format_trailers(const struct process_trailer_options *opts, struct list_head *trailers, struct strbuf *out) { + struct strbuf tok = STRBUF_INIT; + struct strbuf val = STRBUF_INIT; size_t origlen = out->len; struct list_head *pos; struct trailer_item *item; @@ -1118,9 +1120,9 @@ void format_trailers(const struct process_trailer_options *opts, list_for_each(pos, trailers) { item = list_entry(pos, struct trailer_item, list); if (item->token) { - struct strbuf tok = STRBUF_INIT; - struct strbuf val = STRBUF_INIT; + strbuf_reset(&tok); strbuf_addstr(&tok, item->token); + strbuf_reset(&val); strbuf_addstr(&val, item->value); /* @@ -1151,9 +1153,6 @@ void format_trailers(const struct process_trailer_options *opts, if (!opts->separator) strbuf_addch(out, '\n'); } - strbuf_release(&tok); - strbuf_release(&val); - } else if (!opts->only_trailers) { if (opts->separator && out->len != origlen) { strbuf_addbuf(out, opts->separator); @@ -1165,6 +1164,9 @@ void format_trailers(const struct process_trailer_options *opts, strbuf_addch(out, '\n'); } } + + strbuf_release(&tok); + strbuf_release(&val); } void format_trailers_from_commit(const struct process_trailer_options *opts, From patchwork Tue Nov 5 06:17:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862370 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BAAC1D5CEB for ; Tue, 5 Nov 2024 06:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787450; cv=none; b=Vq9jgxubCC7yjn2E08SOkFG0vhZlzKNzc7qFG6209V5O3Oo995TFNQfSDkyWy2fcl7Gl9gpPYxytU/2INTtxqTxKf3GRO1mrl+ebOy64jsU29lMPgd/V9jmlZq4014rMoytEGz9fGRZFSC5B8+PEhrchJcUiKx9m8T/m9h/bL/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787450; c=relaxed/simple; bh=Nx5BgxDdaWVvyV3eSH7cjiTUb9DtU6BSgRnLWE2sgQI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dztlBd7zgLz4ZYyavZOs7wkxJ5ZMn5wacBNnrZiVY292syDdGitDBoDaxJe2gXNkqxGtez20W7s4/sqFHsowQWxw6c8qZkwjwa6bYzWhwJRkgsGQJl6FDNgTASkBEpAS2p7fQN0T0WEIUqFJqHoAdsSNrvk7wV49JViTqZ/GdhU= 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=eJZoi6Cw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=L9X1vtRY; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="eJZoi6Cw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="L9X1vtRY" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 76BC32540076; Tue, 5 Nov 2024 01:17:28 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 05 Nov 2024 01:17:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787448; x=1730873848; bh=EYA2fFcw8O Hr6WykBKTaGxi2eJQNE+cRD46lbdQiA6Y=; b=eJZoi6CwIzmSIVY4ENmVlEsFv7 mPQo/NpgyR10lkz7P3ki6SqN8JBTBOPJ8h8XIXTCSrkIdGnEb1aiQPVJVeygRHgJ CnYZ+5QidtbA/av15SKCqFSatbwd9J9TBEgzmGRyfgDkip94RgJ57gu9I0K1ttP5 cbLAiNkeLLNn7QBk9DiDdM19xmKnuHleKfLyv1Q5Z8q6UxulekiNcduf6G4QJwuv 4cn8vFu8IQIPevq+ChmnDuRzItQc+qPZgJ3q+rc/jQv3vJBtAt41VMkEiFXE9EOf 2tfBMdf1jt/F8nSa0VmMMlPiH1qGuAsb3fwNQD1DaR4mgeoTuPhubjV0zYWg== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787448; x=1730873848; bh=EYA2fFcw8OHr6WykBKTaGxi2eJQNE+cRD46 lbdQiA6Y=; b=L9X1vtRY0eJ+alxYCfHMbS2SXuAzzjE81l1ApSZyytupUgrdz8N 4RO9lVHyZ/jVUvc8ftLTHKvun/lR7YZjzBRb1+JFwjwMHY8XoC+axAiU5f6simyv vrupsaPQkFhqhye5FS4P/6tc9KcjPeOoClLTIi91ZY+U4vlCWqnvG9Ty02zH+i4N eWNPQhSnjJo+2bQ+dm8A7dYGlGHpdw76sxxG+dAo1fRau/nhnDUHuGeUJK1YJ7qD ttDe49bV/wlbd3HNh6X7a3Drj5dkw2PjbxJ43JBHr5N2CjDFj+Nwpt/BFHaja3+o IOJdqYOv/8SqrmLQJWycd1u2Zt3FkDb3PDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhlrdgtohhmpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmvg esthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:27 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5100918c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:05 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:20 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 12/22] builtin/commit: fix leaking cleanup config 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 cleanup string set by the config is leaking when it is being overridden by an option. Fix this by tracking these via two separate variables such that we can free the old value. Signed-off-by: Patrick Steinhardt --- builtin/commit.c | 17 ++++++++++++----- t/t7502-commit-porcelain.sh | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 18a55bd1b91..71d674138c9 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -135,7 +135,7 @@ static struct strvec trailer_args = STRVEC_INIT; * is specified explicitly. */ static enum commit_msg_cleanup_mode cleanup_mode; -static char *cleanup_arg; +static char *cleanup_config; static enum commit_whence whence; static int use_editor = 1, include_status = 1; @@ -1387,8 +1387,6 @@ static int parse_and_validate_options(int argc, const char *argv[], if (0 <= edit_flag) use_editor = edit_flag; - cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor); - handle_untracked_files_arg(s); if (all && argc > 0) @@ -1636,8 +1634,10 @@ static int git_commit_config(const char *k, const char *v, include_status = git_config_bool(k, v); return 0; } - if (!strcmp(k, "commit.cleanup")) - return git_config_string(&cleanup_arg, k, v); + if (!strcmp(k, "commit.cleanup")) { + FREE_AND_NULL(cleanup_config); + return git_config_string(&cleanup_config, k, v); + } if (!strcmp(k, "commit.gpgsign")) { sign_commit = git_config_bool(k, v) ? "" : NULL; return 0; @@ -1658,6 +1658,7 @@ int cmd_commit(int argc, struct repository *repo UNUSED) { static struct wt_status s; + static const char *cleanup_arg = NULL; static struct option builtin_commit_options[] = { OPT__QUIET(&quiet, N_("suppress summary after successful commit")), OPT__VERBOSE(&verbose, N_("show diff in commit message template")), @@ -1757,6 +1758,12 @@ int cmd_commit(int argc, if (verbose == -1) verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose; + if (cleanup_arg) { + free(cleanup_config); + cleanup_config = xstrdup(cleanup_arg); + } + cleanup_mode = get_cleanup_mode(cleanup_config, use_editor); + if (dry_run) return dry_run_commit(argv, prefix, current_head, &s); index_file = prepare_index(argv, prefix, current_head, 0); diff --git a/t/t7502-commit-porcelain.sh b/t/t7502-commit-porcelain.sh index b37e2018a74..84f1ff52b67 100755 --- a/t/t7502-commit-porcelain.sh +++ b/t/t7502-commit-porcelain.sh @@ -5,6 +5,7 @@ test_description='git commit porcelain-ish' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh commit_msg_is () { From patchwork Tue Nov 5 06:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862371 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 008451D5CEB for ; Tue, 5 Nov 2024 06:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787454; cv=none; b=HXJ9WQS4/l5Fz0ZaU728ffrqGLzO4AUR5FVfGxvJR5mPHn0fGUh6iLmHuRIGEAeIbg9cHJFMVk4DIQwLAs6NWlg0KBLYvbSrlJCoZunI7oqr/+wlaH3wDAG+PFkl87Fzyax6pSEFL0sCYHLC4HI89qFJ08NFHclTcVGguF1AP9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787454; c=relaxed/simple; bh=SdVLCzoGuklJrhdqLawDpGY29twMT/f+hcGW4jVGk3w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lpFfwF2ipKxqpWPOL7cXRfPG4YtJM+cCjEmZuGZ5twYKBUrTGzOTVgT8t+PqYhVyQ5vsI9vMTA3x9RxbLTgyeQvqz9I8aRnR43BhN/2lZDrOTC+QrAv+zfo54j9BCQ/Nzsm+IU8Hoh43x4vMgTW5fkHD//qpuYuqePQKcW1UZaI= 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=cJQYxjwt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dGpMf9V6; arc=none smtp.client-ip=202.12.124.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="cJQYxjwt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dGpMf9V6" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 22FB3114016D; Tue, 5 Nov 2024 01:17:32 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 05 Nov 2024 01:17:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787451; x=1730873851; bh=jsjFLSH1yU 0DYORo3Rid/srSfZN27sVe527D/RN4REA=; b=cJQYxjwtP1UwL74uTo6sJXLx35 olQ2ciRmwvnkU3ruuntksHX+ZuLk7sUWSHzq5d35CQmRsyJm4YmbSAt8QUGWinGq CnQG6xkDsCFgYuMoKWiKEj5ipmMg9e/WLsXMggPELfLHf5nLA63cNjKfxTnLZF9N 6ASDJH+cocSEF1FRcw4YI63ggWgecTGBMiApX5capOt81RdXM6uXksLrkAYNlrTG Lu52e6Y30Q07qqP8PquFd6ULiZAC5EWo7nT4mZh67Vp7Z0vv9Z6wPtKsGoRmrcGW cAANqD/OFJ1/UTguNlyPnY8S2gMEKbxq6U/4JDR7XwtzG0otLam6C+ogXjSQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787451; x=1730873851; bh=jsjFLSH1yU0DYORo3Rid/srSfZN27sVe527 D/RN4REA=; b=dGpMf9V6rKGWs5KHq02ArZWhgNuJlehKC/v42YGqX3J28DvaDOI 5EhSlH04irX70K9nOHYu2HC1+89k5OP44hxqIN+W/QY/JUR9piYHQoQcW0LwxN1z BPjUwJgfpe0Yi3HUomuTdXXNDcS51a2vLKCRPx574fpfCv6Xl8D2y3k4xA6nFVuC OZ67s8uc5SNjCL+b1KDAUfJbD8BdTuLIX/tmGhHthTRbXBcWbBTstvQsmMtEAP7H 5btljMb3Q2Znz8xlsKa+Tmr9a45clllV0V9Ip2k2q3WBdRM0NnPpabSYFxKh3+/e M81l8CLwmimB8YIfNZsDDCPk/B+a9lKtnSA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgtphhtthhopehjlhhtohgslhgv rhesghhmrghilhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhmpd hrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:30 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 58268622 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:08 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:23 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 13/22] transport-helper: fix leaking import/export marks Message-ID: <40e0c2a2cacaf2e6879b262c43321728af25579e.1730786196.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 import and export marks for transport helpers. Signed-off-by: Patrick Steinhardt --- t/t5801-remote-helpers.sh | 1 + transport-helper.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index d21877150ed..d4882288a30 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -8,6 +8,7 @@ test_description='Test remote-helper import and export commands' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh diff --git a/transport-helper.c b/transport-helper.c index 013ec79dc9c..bc27653cdee 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -399,6 +399,8 @@ static int release_helper(struct transport *transport) int res = 0; struct helper_data *data = transport->data; refspec_clear(&data->rs); + free(data->import_marks); + free(data->export_marks); res = disconnect_helper(transport); free(transport->data); return res; From patchwork Tue Nov 5 06:17: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: 13862372 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D076B1DA62E for ; Tue, 5 Nov 2024 06:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787458; cv=none; b=AFmizGWZgFOoOyLmvJRQz/542dfYJi/DOcl7+RB78DpxsWeZhbXFY8l8Ith+1iHnh37GLGW11dgSol5r2mVNEsbTDPhChoCSLTZIjk3+MCTaQOkuJm4xXeqfZ0Jv0MetC0C0sN94efwiKKkhjTRyOiJjNdYbNWY0y90nPWVONnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787458; c=relaxed/simple; bh=MijheuAVZ5v+gMRF3XZQ3ZBAn/gQcpWejfjTeGCcYgA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dpNibri80AgFDUmNv5yrvSEqU7aDp/fpOWHZ/EaazkgsFVst1cpa0w6S9c0pfBMunOs1wxfZfaYOHZc+r8kd9xXb8iwD98Y4ixIGwjofpp6dqFP/KsB+Kr+OQ/NebBQCWqF3eP9yCS8qvSHrZBSP4UgQoTWTrEJqnK5LGXke6/4= 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=pbgva2NR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EizvqUHD; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="pbgva2NR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EizvqUHD" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id C989625401A8; Tue, 5 Nov 2024 01:17:34 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 05 Nov 2024 01:17:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787454; x=1730873854; bh=fRi5cI/FTz nLvpXmwUZpENUbnQFkYQuvD5MHZYxqPhE=; b=pbgva2NRpkKnwLTRgIk/y5Wf8r a0Q25Q1um6+NCI7K/DrB7bwlBE34L36t8WIdPy1ZVrJeGqO6PfbSgyn2YmWqEz7k xwAu8j6dcrRbfuTymscAohYCOcraDH4plafzsivuoUFkfliC2k6waEQfvKgZpcZp ddgVfEc0x/AQpFyxjxU712jDCYqOfg4yucmqbF3MGM7A1Vx6+XqIGqi7voBK8u0g cNB/m61o8bFmduRR/ErfhrJe/c4UgTeJ0Za290JNKtmYrmC/nWl3QmeGVJmCL8kd mS9SmEn7WEax6vw0WZYZwnqGN5/n5BmLDoHGwIia0CMd2yNNqW2Pm7fK5BCw== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787454; x=1730873854; bh=fRi5cI/FTznLvpXmwUZpENUbnQFkYQuvD5M HZYxqPhE=; b=EizvqUHDy2e8m8vcxE3j3dJIqzpJQQf4HX/oZnBpJQHIIHxS5zw cCm2DCNXq0uQnZ1/nCtpM5bTrCvTHXEClJPzrXKPQQUdhgTEon0iD8WzKR36qgu4 y7Yqbslu/DSIvjTKA68rqylDuRupdT9qBfjEubgNPmuhjy/0daV0FeA+idfspFZo hLFaXcelqJNEhmjxxX2TSauCcAw4PbT7P51fPaCix708p+BCYoGcnzOsGopnA1Bd Aj8kPGrT/rxKknK5wxhurIWSax9x7nv5XR5B+NbiozjLwxE1M8gpHCib+ZQBe2Go QHtM4YXBwAHaIPGYMquZZrnbr7CAIbTa2Xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfh grshhtmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmvg esthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:33 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8771e964 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:11 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:26 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 14/22] builtin/tag: fix leaking key ID on failure to sign Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We do not free the key ID when signing a tag fails. Do so by using the common exit path. Signed-off-by: Patrick Steinhardt --- builtin/tag.c | 2 +- t/t7004-tag.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/tag.c b/builtin/tag.c index 93d10d59157..c37c0a68fda 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -164,7 +164,7 @@ static int do_sign(struct strbuf *buffer, struct object_id **compat_oid, int ret = -1; if (sign_buffer(buffer, &sig, keyid)) - return -1; + goto out; if (compat) { const struct git_hash_algo *algo = the_repository->hash_algo; diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index b1316e62f46..42b3327e69b 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -10,6 +10,7 @@ Tests for operations with tags.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh . "$TEST_DIRECTORY"/lib-terminal.sh From patchwork Tue Nov 5 06:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862373 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B6A41DA62E for ; Tue, 5 Nov 2024 06:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787463; cv=none; b=LeecgoWLb+9Sh23Px5dNoykFpr/gl8nxF14DkOK5uNUr8k3u0AR/LF1kXMjkycHAKR/SEDqC7YqDCpfid3HL1LDsIoKRLJGgyO7nQnTGy2GhCSYthUGD+1w+blWth7XpzNphKDE5l+FGKpidQ0uKa7k+bnlrDbADWX5byohKHAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787463; c=relaxed/simple; bh=peNPAG5HXnOhjqQraobEJTx5uAd5/U588XKDVi1pDV8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ohrRGl02UQlKc/Tu2gO0CwP5QpyfE14o7e/XTkWtZELW1uTCiIJQ4OodLet6OVZeXk9gVTNgH0IhfIvqu8C/R5gqtoO6E3rBbyokWdjrzaHa5wT+WzapPEfJ9riGNxoUfri8yxsiN28uC8dM/t7qACRUc9PffUdJgr+auzyWpMo= 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=MDje9zD8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JwcFM9Bk; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="MDje9zD8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JwcFM9Bk" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id 8373A2540076; Tue, 5 Nov 2024 01:17:40 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Tue, 05 Nov 2024 01:17:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787460; x=1730873860; bh=ioWPSsncQo I64+VugMot5A/Azew+Sw1bWew3uDxc194=; b=MDje9zD87CQmCc0SlE4/9IBhmR QMt7LodPVyufoGye1LyjRf2mvj/LlmDnwPhHG1WFw0mbjC4/iUu0YUtak2p4gjEp CyoOPw930P8nxGBoos8H7XKrP1CXj56LdK9ltCapodE7p2NWobcbNiiAYrI5lXtk nXx6OlpQZLqH/6nm5gtx1FOjgGJA21Ph60iQMe1Ylo21QkgaWxWt4KWySyGPbvMH PvJans3DsIKHNA+vqW5b5efMcpQ0/DJaZPlUn0C+Dz57rUp+s6CrpuPFH927U3YA fV7BAQ7tigFpkZ+gP8J8cCwjrTDayXcT2hU8vPB8D8RmuROjIHjqD/ui65FQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787460; x=1730873860; bh=ioWPSsncQoI64+VugMot5A/Azew+Sw1bWew 3uDxc194=; b=JwcFM9Bk0LwN0KjwvkvTn46V1BOoVHQaR9wnH2ECguGWZtdwIyb OC25AFu9L4x1WI9n4SQr5qGd8XfwqZMO/q5uh5RQENJvH3Sw3AxM3GHqNoNfxViL EtxLAJUjZYBDMysn0nmSToTDsFir04jw1Utb+j9vRtjaDhWGAKOk4g8CfS098y+U Nhq2k4aWbzi7IvJ9rF5O368lFil4ds9uZhgDO2sx1OHM1L6NINPkJBz2JCP8ROWX HkpPg8BNwhxDlzx2H2cB8gb3pe+JjdWfjXyjWK4LfMhOQoW6mjNbTkPv4Yt4dnmW yLIDZBb5cCSkzzrvusnIaK4FdmKpAYWlEcg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehtohhonhesihho thgtlhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:39 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eb62ead1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:18 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:28 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 15/22] combine-diff: fix leaking lost lines Message-ID: <70dd0cb6933c31064f6084bb5a51794a7691b154.1730786196.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 `cnt` variable tracks the number of lines in a patch diff. It can happen though that there are no newlines, in which case we'd still end up allocating our array of `sline`s. In fact, we always allocate it with `cnt + 2` entries: one extra entry for the deletion hunk at the end, and another entry that we don't seem to ever populate at all but acts as a kind of sentinel value. When we loop through the array to clear it at the end of this function we only loop until `lno < cnt`, and thus we may not end up releasing whatever the two extra `sline`s contain. While that shouldn't matter for the sentinel value, it does matter for the extra deletion hunk sline. Regardless of that, plug this memory leak by releasing both extra entries, which makes the logic a bit easier to reason about. While at it, fix the formatting of a local comment, which incidentally also provides the necessary context for why we overallocate the `sline` array. Signed-off-by: Patrick Steinhardt --- combine-diff.c | 5 +++-- t/t4038-diff-combined.sh | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index f6b624dc288..33d0ed70975 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1185,7 +1185,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, result_file.ptr = result; result_file.size = result_size; - /* Even p_lno[cnt+1] is valid -- that is for the end line number + /* + * Even p_lno[cnt+1] is valid -- that is for the end line number * for deletion hunk at the end. */ CALLOC_ARRAY(sline[0].p_lno, st_mult(st_add(cnt, 2), num_parent)); @@ -1220,7 +1221,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, } free(result); - for (lno = 0; lno < cnt; lno++) { + for (lno = 0; lno < cnt + 2; lno++) { if (sline[lno].lost) { struct lline *ll = sline[lno].lost; while (ll) { diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index 2ce26e585c9..00190802d83 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -5,6 +5,7 @@ test_description='combined diff' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh From patchwork Tue Nov 5 06:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862374 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 359B01FE118 for ; Tue, 5 Nov 2024 06:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787466; cv=none; b=IAGmi2yROVND/WPy3XfThza2ONIMxJk9Jmu2wOPQrO90t9Fi+j4e9TPits5C5vtQrQrT6f3loZJHIUcE07hLt5wPdqiJMEPMhPHIbTuzub+FrhzOuE+6u4oiNVz779QDQhkPOxVunYLXgNGXUhAHoIeXkrsk4zs2mHGuT0P+PLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787466; c=relaxed/simple; bh=tER77zLkNHaVI4HSWc660FkHOZDjAHpmGyBsZHrshgQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Iqt1huDR1WOqBBIlsekHhTErFAnorYndjYP0gok+VHsvN1ROLWbiTO0h6tWRQUBlBOH0bGSShM/w2Kiy4+agyaLBJKdDQnx+QYldcboQ7yMFBZFZxWgTTR8mJ0rb2zf2eLbWmuyc5wW3VwDRHweWPnfS58Ba4WsPZ3gPPTRj5VQ= 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=kkAcpzss; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fjKHJxdG; arc=none smtp.client-ip=202.12.124.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="kkAcpzss"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fjKHJxdG" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 3DBC7114017D; Tue, 5 Nov 2024 01:17:44 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 05 Nov 2024 01:17:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787464; x=1730873864; bh=km8ATBXjjV OHbJUaz8htu9O26G7DlzbNp+s6KIB5i+Q=; b=kkAcpzssLtE7DRPQVbeHWw+jjL a6xXpfBvEk+wX5BrSz+ChDa9amd7XtfaoJGVdcm07Y8ZKyLxUQTNfov3+JK8iFrE 8kFU7Nk+mbsv3oG2qzQIx8Z7tOaiv5PQT61pygjObYBGxVsPHDMFqNGcKSCwygTA 98ovuFJ8D25AGcxb7Ox1cntw/R598l/Wbl9Be4ESHZXFVol1zAQr9hMrLCA3bYCr xxzVR9ITamIgjAiUcNf6rrKVnpBFyTkeD9/Ebs8mFvkcN3GF2Xtgwti6XiuIgKvS 2TmTUfDQAj3un4kzXbVwOthZ9imm4ixZxj/FVX8nL6o7YVNlTXhQvG1WrQig== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787464; x=1730873864; bh=km8ATBXjjVOHbJUaz8htu9O26G7DlzbNp+s 6KIB5i+Q=; b=fjKHJxdGNVqCPySWWgfu7WWUwj17Sltt1fdHH03QuG5q9aBmff/ /iYtju13vQPtUQ+Z5WI8pIsN2jVCBz3ZxDKS4N1SMvTb5c0Ky0Rr+IgACIXtCBdn ivItv47JLEquflr7vyVKeAa8SJDE24uwUBBhqZ5XnVoB7N1kYMlPJVvSqpCstaMm ZBRbT1f7oKeLVQ/JGy1gA0htbtv9xBgJmtOr5OS0Vyzo0GkpAuc7FJ4gzkiGnqzU 9H7A55Sqa4sUgtN2rs6YbOUq0+NTGSrxZPqlix7pC2Av9mDOite4T1COt7i4LW2f KF6sVhR9hq1chK4aIUEPFonsSRTrLWYp6Sg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhlrdgtohhmpdhr tghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhith esvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmvgesthhtrgihlhhorhhr rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:42 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3a9b622f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:20 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:35 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 16/22] dir: release untracked cache data Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are several cases where we invalidate untracked cache directory entries where we do not free the underlying data, but reset the number of entries. This causes us to leak memory because `free_untracked()` will not iterate over any potential entries which we still had in the array. Fix this issue by freeing old entries. The leak is exposed by t7519, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- dir.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dir.c b/dir.c index e3ddd5b5296..cb9782fa11f 100644 --- a/dir.c +++ b/dir.c @@ -1056,6 +1056,8 @@ static void do_invalidate_gitignore(struct untracked_cache_dir *dir) { int i; dir->valid = 0; + for (size_t i = 0; i < dir->untracked_nr; i++) + free(dir->untracked[i]); dir->untracked_nr = 0; for (i = 0; i < dir->dirs_nr; i++) do_invalidate_gitignore(dir->dirs[i]); @@ -1083,6 +1085,8 @@ static void invalidate_directory(struct untracked_cache *uc, uc->dir_invalidated++; dir->valid = 0; + for (size_t i = 0; i < dir->untracked_nr; i++) + free(dir->untracked[i]); dir->untracked_nr = 0; for (i = 0; i < dir->dirs_nr; i++) dir->dirs[i]->recurse = 0; @@ -3573,6 +3577,8 @@ static void write_one_dir(struct untracked_cache_dir *untracked, * for safety.. */ if (!untracked->valid) { + for (size_t i = 0; i < untracked->untracked_nr; i++) + free(untracked->untracked[i]); untracked->untracked_nr = 0; untracked->check_only = 0; } @@ -3905,6 +3911,8 @@ static void invalidate_one_directory(struct untracked_cache *uc, { uc->dir_invalidated++; ucd->valid = 0; + for (size_t i = 0; i < ucd->untracked_nr; i++) + free(ucd->untracked[i]); ucd->untracked_nr = 0; } From patchwork Tue Nov 5 06:17:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862375 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7E9F1FEFB9 for ; Tue, 5 Nov 2024 06:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787469; cv=none; b=b1OP6alpy0jXHoZX0CowEDyre32lTbHtXZge4F1rcDgszaYoSMaZ3/KLOSAo0OesvV6X7uKvotGwi9ui80UFHnNSBO6laH1+ACgEyT6Mli3sEY2etCDxe/ATV0vmXGYyTBlSd2eBdCxinovgsCGPs2zYa+y4+BDe4UXuWnjaEJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787469; c=relaxed/simple; bh=ZigeHW/kIhFdIJKfrttM7SPQU2kyjthKcAEmPcEkKN8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kVee3lVbXYHrZ5/N2yHUj1LarOHZSBAVeR6Qx8ZGR8n3DA0zmwTr2E8+I0RWuQN+pOr5l3w2eqEJ8rUqj3ol/6r0RgTOmS2hoyVPBYvB7fP/mEeenyrcev64isksv8Po0SvE3AaxAZRVD9bP6tu19fhbmHTf9Y65pvbd8CFb164= 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=BWncDmoy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fr+LkPgY; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="BWncDmoy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fr+LkPgY" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.stl.internal (Postfix) with ESMTP id E011925401A8; Tue, 5 Nov 2024 01:17:46 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 05 Nov 2024 01:17:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787466; x=1730873866; bh=JmdqMcNCGW uk0WLIaTV4HF3Idm+fg4Kj8jI0DPNFHg0=; b=BWncDmoyQs6RRrndd1kZ4qd/lW VyR14eWFrEa8cm5z6UqvI8Cp1e5SDEEkK1VK7YUvDejl//cvXhNLKVoL5RloFZZ1 m2il5NL/JmYlaShKUZ7Nj0pDEkMlNKZjpJGKTDNhOhIyEIwh1yIPKnyyjUQuoJeQ 19OP68CLNLE+WoQ2DzpG4KmuSrYYmFWWF0suwpXJwwIwcoi55b11aGwbIfSBe89+ ZLp4ZjO5fUvA29vN5DxgMsQ09FJiz0SKSN7ZgWu5b6GztrahoW9aj+Q2KYiz6Zwu 0xGdRJKeYXCXvvgMgFZE0k5hDt1YuUbVkA9WTHFixeCibZRPfKXZRS0tEpzQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787466; x=1730873866; bh=JmdqMcNCGWuk0WLIaTV4HF3Idm+fg4Kj8jI 0DPNFHg0=; b=fr+LkPgYt2CyyB2GagtQAeYCNEJGGsJ/zTgoMV39nOtbnNxqM6B heRA9wpisTbfgKFr5VHjSjZcMZxR1w7VGYZt5W6XfrDHo62lo2bzm2J8hIksVrE1 oZJJRqxW6kqQ/knfMSVkQKl3CW1FiGfRQQJLQkN7lZ2Ztq/kA4CfB71JS1BlT8v7 /yb7T2KnZV65sAG5UMRsN8Bbhdy+8vVr9H6gBgm8mLdrtXk2n2BQ8hlP7vddUZKD +sCpKpwvChc46bB/MBdmEhXf5EvRIUGZDwymtNb1EyjZgCrX762uzF8rKMKtMO3M gAn13UN2QkTVX8Nffzf4HljAP6t8jQRfdtQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehtohho nhesihhothgtlhdrtghomhdprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhmpd hrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:45 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1f123c5e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:23 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:38 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 17/22] sparse-index: correctly free EWAH contents Message-ID: <76e9a6d57927cb8e7363b3af20d9b194ab258b21.1730786196.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: While we free the `fsmonitor_dirty` member of `struct index_state`, we do not free the contents of that EWAH. Do so by using `ewah_free()` instead of `FREE_AND_NULL()`. This leak is exposed by t7519, but plugging it alone does not make the test suite pass. Signed-off-by: Patrick Steinhardt --- sparse-index.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sparse-index.c b/sparse-index.c index 3d7f2164e25..2107840bfc5 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -2,6 +2,7 @@ #include "git-compat-util.h" #include "environment.h" +#include "ewah/ewok.h" #include "gettext.h" #include "name-hash.h" #include "read-cache-ll.h" @@ -242,7 +243,8 @@ int convert_to_sparse(struct index_state *istate, int flags) cache_tree_update(istate, 0); istate->fsmonitor_has_run_once = 0; - FREE_AND_NULL(istate->fsmonitor_dirty); + ewah_free(istate->fsmonitor_dirty); + istate->fsmonitor_dirty = NULL; FREE_AND_NULL(istate->fsmonitor_last_update); istate->sparse_index = INDEX_COLLAPSED; @@ -438,7 +440,8 @@ void expand_index(struct index_state *istate, struct pattern_list *pl) istate->cache_nr = full->cache_nr; istate->cache_alloc = full->cache_alloc; istate->fsmonitor_has_run_once = 0; - FREE_AND_NULL(istate->fsmonitor_dirty); + ewah_free(istate->fsmonitor_dirty); + istate->fsmonitor_dirty = NULL; FREE_AND_NULL(istate->fsmonitor_last_update); strbuf_release(&base); From patchwork Tue Nov 5 06:17: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: 13862376 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 7864E1FEFC4 for ; Tue, 5 Nov 2024 06:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787471; cv=none; b=ALOMC/wjuCRwcXeGHYnXlemmh3u8IYkd1mvITlo7bk9hWEGHr7QUeh2+FHKU0wpdZt5AWsdIhPAGvK19Hkg7jBeomzGwIW4L33BpfR7C6ZC6RTtsWpTlIlhwJF0JYDVH6ZYh/uSMFDnnn0KQE/IDmmu40AwT+kESQOT5uaJqq1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787471; c=relaxed/simple; bh=9W+Pz6dnSsy23sDEAOr4cW8Osu48nJcCMbjFtpG8nFU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AcmUd7eK6kUZymBZHoueNauSPiReKGQZ/l0T719KjzpJbbLGC5+KFShF3BNgqCbsJ/7lsfDZNSs2OyhR8k/ElJRWCxRoWgnI/KG8h+bVT7R5J9N2sBQGZS8Q+xN5PTDvi//ehHp7x2VZF0jTaKBD3QyCMGe9v4nK5soSERzsfDM= 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=rpVpwMvv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iWOReNov; arc=none smtp.client-ip=202.12.124.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="rpVpwMvv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iWOReNov" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 8E898114018C; Tue, 5 Nov 2024 01:17:49 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 05 Nov 2024 01:17:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787469; x=1730873869; bh=5r31irX9YM rLTNDAIG8DiiB98K9BFZ66pjq//sCZSOk=; b=rpVpwMvvmJzMfAfgoaYYZo1UPb 4GV/EPu8JnkT3rztmmhbBCJYoutULO8bDXx+pwlMcjnyt2E2DF1L5QKMwzSBZC4Q yd5/mg7p8osVSL/J+bRYsAPmHDA+6pOfZbnR9MjzcGBPLpgLXyD+zTdG0w046U/R X3qzDeqAjWx6yXgrP6EVb8IjQZJ8vu0DT/VdeiJ52cTO0tdq1GnqnVUF4VLc/Pru kxbfiYciSNhdSGXtcXd5sprPBbOfzwQ4wJmdMiwE+2FfZs84fbnqsW55fLBPDadr cTwVEgyZuEa+5yha8c8FtONvY9sGzwtJJxjLRbaLzJsD2EebWAibE6FJNgqA== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787469; x=1730873869; bh=5r31irX9YMrLTNDAIG8DiiB98K9BFZ66pjq //sCZSOk=; b=iWOReNovvqi+ntP3XNV/Flupmz9nJK9k4FAyKr/Ai2hiY42nIKV XPnHAGJ7/6YGqa/VGpWZPgUNoZz6klJq6qS9jCeahHYFUub1H5+kNDwBlCk47e3r 4z7z5+S5AU+19fVuPe/PUbH0UxwzVAPT12S72C1tL+Ji8ZNWF7YxcZ95dVlPtttC 1nkNK8Cfu5s+zb8NrTcPsXFu8erB2+YkzA2tBlIB+SZl6h6ypOggerT7UAx3oeCJ eEyU/IqK/RkLb4sZpc7TFvF1IBSNeTelOPEl6TeF051NqllxQSQEXUTezVevS4rk OFljGwrG9WbmU5lR/gVrRPyS3ZklHbxVGfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfh grshhtmhgrihhlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehtoh honhesihhothgtlhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghl rdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:48 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d5c94d2e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:26 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:40 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 18/22] t/helper: stop re-initialization of `the_repository` Message-ID: <70f16486d77ec69874ee4f36cc1d89631deae3fd.1730786196.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: While "common-main.c" already initializes `the_repository` for us, we do so a second time in the "read-cache" test helper. This causes a memory leak because the old repository's contents isn't released. Stop calling `initialize_repository()` to plug this leak. Signed-off-by: Patrick Steinhardt --- t/helper/test-read-cache.c | 2 -- t/t7519-status-fsmonitor.sh | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index d285c656bd3..e277dde8e71 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -11,8 +11,6 @@ int cmd__read_cache(int argc, const char **argv) int i, cnt = 1; const char *name = NULL; - initialize_repository(the_repository); - if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) { argc--; argv++; diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 7ee69ecdd4a..0f88a58a819 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -2,6 +2,7 @@ test_description='git status with file system watcher' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Note, after "git reset --hard HEAD" no extensions exist other than 'TREE' From patchwork Tue Nov 5 06:17: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: 13862377 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 310301FEFD2 for ; Tue, 5 Nov 2024 06:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787474; cv=none; b=KJnvIXcAeQTlTKKrYVeXxko4BIh+1rP9AmgeRJain4wxSs47C1k2hNtTzf9aCdh1e5carmd6ONP76hSi9nYuX6BRb0+aLjKRH+zXHt0UB59y1R0PQpMJFdcRb6bicTLLPXPprbPcLPcybCrQUExbOeJp2S6Y2LLg22c4vbThglg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787474; c=relaxed/simple; bh=1usc/bLUuPOLq1lh2l1Ul04ntJ6LxjLoSM9OpQPZvUc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XwvaeGtgV0Dqyskc2T5Alx+4QBggHPEaeLgqCmwcZ1pE7vmr6LaQxVBGkEL1ldXfUXAuHUdJyilM78Fzhkvqaxa/15gyz44VjxR5FWqdJr98MxFIp+Q4kBHsn5zw0j3x9mSW3xqDBNvV4p+g9ROukY1EYcUswN4doZtgASky53U= 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=wVIfsgWw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ki6hNIHT; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="wVIfsgWw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ki6hNIHT" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 5208D254019B; Tue, 5 Nov 2024 01:17:52 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Tue, 05 Nov 2024 01:17:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787472; x=1730873872; bh=M6v69QYeSU +x9sjR7UAPPh3S/fZIlh+crMNI2TssvYo=; b=wVIfsgWwUTxq4dA6CmgS+dpmR8 ZtYaq9dJsmukMsKYxphp6UrWejsU/LPmPEDs3qcUAy+zZ6DSPl1caaBqRMb4o0uv rFcRdnjjV8NXD8jvRrJLFvhUW1QGWetGkvO4K0KkI9h5NuV6cNJxoPjCVpNp+qZk wFVcp02UCtL6IKmlZSMxflH1IloYzQ7AFNIit+Ni2i4bFSIJWzPCrcpdYijb4/XW aJaR3Yrt8O7gdERGhk7jm8rQRVRL9ljWPv5irYcl9sJmY9IRBi/umV5c21BbxGzo Y8aEqAczjOOpUt5lhD1+RszqGwMIEavND+1l41sCfp0oxYHiyZwiwmQgfCZA== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787472; x=1730873872; bh=M6v69QYeSU+x9sjR7UAPPh3S/fZIlh+crMN I2TssvYo=; b=Ki6hNIHTpdd6e6FP9y08rt+U0/tCOuU+ct/GjdgfW2x3X+hxoMF /1QGxLCRa2d+vSR/JW9zIUlNOSmi6ANkuAATLZqUIom9oEIA2zSjtsgGW6RRI871 PKDwsFZ5xGdbH0aGHaiaFGZmGPhn9rIY9Wdak3oWELha7++XJoeo6ObvReWc0cZI s54zLnyCrrM3im+JgAyJCZtsxVIEG4qN1vPco6NrxjMzt9FOmT0dM87t5dgP+1nK rd4SC2yrmitxfY+KN+hfOWewmz6eoRv+nEKsG6qlvDl2tgXEHLlrjd/EKUKSX145 Na4d8hclSHgGfd1DGnBeqHr12jL+cStilTg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgv rhhnvghlrdhorhhgpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkh esfhgrshhtmhgrihhlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:50 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4af61958 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:29 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:43 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 19/22] t/helper: fix leaking buffer in "dump-untracked-cache" Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We never release the local `struct strbuf base` buffer, thus leaking memory. Fix this leak. This leak is exposed by t7063, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- t/helper/test-dump-untracked-cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index 4f010d53249..b2e70837a90 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -68,5 +68,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED) printf("flags %08x\n", uc->dir_flags); if (uc->root) dump(uc->root, &base); + + strbuf_release(&base); return 0; } From patchwork Tue Nov 5 06:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862378 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 E0E0F1FEFD8 for ; Tue, 5 Nov 2024 06:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787477; cv=none; b=ut6RQcptf2dpTxugYNoFLRRpYpaChiv5XejtqXjMfEQtS4Px4ECHXdDphBhiio1VxXVgjzYilTjL+VVdSaZX8EKRwUGiOzJczaSt1k6qnyG/5XhfmXWaxoVP6ojv24T2wwhwTVlv/yX0MuIRoP/zCKm2aUrsNC+Fdd3ntxII4E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787477; c=relaxed/simple; bh=A0SZLAqdki/rAYZrLvUeU4q5usOSsZLvs+lux8pEUB0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eLDczuXsHbdI8ZPqTTIsb6eOEftrQvpc/Vu8kDBXdcNJHA9nue0yIzndpp2dmbtixwboEOzUk9rgsORW0JLpyJk7TzBif9QrSnAVWylBVufUf9dxXu57eBN/FKgA5mAMKs2nulES75l/1Zz1LY5Y0Y+XdGIacSZvInetYSUVTY4= 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=ORB0Z9Pf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iVNE9QOi; arc=none smtp.client-ip=202.12.124.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="ORB0Z9Pf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iVNE9QOi" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id 0ED19114018C; Tue, 5 Nov 2024 01:17:55 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 05 Nov 2024 01:17:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787474; x=1730873874; bh=znr72vC7qW 4uhoGtCgyCkuytqAkVC4l+Zx6cG6ciiBY=; b=ORB0Z9Pf15fwps8fQDo8lvtllt yUfq9mwVDYRjm6YqjZKvIByggkX1dLh8aNe3SzKVWYG3PSZ4hkRvs6WJdLmF2tJE oPN21NRzjDrb/UMwGnzUsVXpbYfj6WH+y5YevRkZH3Ymy9pUO9/cniwPeajOHclU 5taSht5f4CmLdycXBaoEvkPkvAvNZUXDUvwGbrGXmLjOick4I3OOf2AYc95XKmXs dd9WDtYdqDJNPBlKy6H0pZu6uudry/9p4gYB87LYTsQ/fh29BcGcNc3os0XOCaTO 5+IqinVmYm38lxqGjUooUq62KC/q1rei8dqzDnuV4LXXdwcNoy3yw9l1TESQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787474; x=1730873874; bh=znr72vC7qW4uhoGtCgyCkuytqAkVC4l+Zx6 cG6ciiBY=; b=iVNE9QOiCWIDvsKlG3Vcpqdh0Fyn74qn31M8EdqTsrbER7Ii5OX oLvwhPH5+ROLevYFDT3w9EDC1ISVkmmaHlaPlIjYaWWMIVCpYR0qjFfOuHTlpmFj j4kQ9UzK9lMcKS9we9k2oRzkoVNYTlis9ell2MHjbFpVYLa3WbYTyWFugy3ARH0J YrCMlUsVw10k7Jg3vCd0NKo67j5cIvj3B8WHiQXMYwJwPJvdbu4tc4Y/wW1pwks9 BdqR738K1T40ReAnUXBIUzsGTnC722QbjxWhRVe3DgMGMP6xSIuJXG+lxQJyZxPm W0JPHFGMgs2TTRNA/Jk6b49NftzenW8em6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhlrdgtohhmpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmvg esthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:53 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ba0e01c4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:32 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:46 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 20/22] dir: fix leak when parsing "status.showUntrackedFiles" Message-ID: <714c9286e7a466f5693cb9ab70177f46d51afe04.1730786196.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 use `repo_config_get_string()` to read "status.showUntrackedFiles" from the config subsystem. This function allocates the result, but we never free the result after parsing it. The value never leaves the scope of the calling function, so refactor it to instead use `repo_config_get_string_tmp()`, which does not hand over ownership to the caller. Signed-off-by: Patrick Steinhardt --- dir.c | 4 ++-- t/t7063-status-untracked-cache.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index cb9782fa11f..7f35a3e3175 100644 --- a/dir.c +++ b/dir.c @@ -2872,14 +2872,14 @@ static void set_untracked_ident(struct untracked_cache *uc) static unsigned new_untracked_cache_flags(struct index_state *istate) { struct repository *repo = istate->repo; - char *val; + const char *val; /* * This logic is coordinated with the setting of these flags in * wt-status.c#wt_status_collect_untracked(), and the evaluation * of the config setting in commit.c#git_status_config() */ - if (!repo_config_get_string(repo, "status.showuntrackedfiles", &val) && + if (!repo_config_get_string_tmp(repo, "status.showuntrackedfiles", &val) && !strcmp(val, "all")) return 0; diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh index 8929ef481f9..13fea7931cd 100755 --- a/t/t7063-status-untracked-cache.sh +++ b/t/t7063-status-untracked-cache.sh @@ -5,6 +5,7 @@ test_description='test untracked cache' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # On some filesystems (e.g. FreeBSD's ext2 and ufs) directory mtime From patchwork Tue Nov 5 06:17:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13862379 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 8A2B81FE0EE for ; Tue, 5 Nov 2024 06:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787483; cv=none; b=qXe6IEP4RtsZn9Qnmtw2r5ts+F4cDw5YUE2JnBccEp98AtXfVKCCg7SM3houRVqfpaijwQfQ2IhlcOd5HZB/RbmeHCuu7+ssi+59aOhPpuVhvUbKwb3rLj2Ps/QTML33WfEuU+3kxIXLf3TjOaZ58HDxNS/bw2/lowGzfrgN1ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787483; c=relaxed/simple; bh=nzBCfE0uQtHPTfedz8g0girMrHWUDV8clALDP9Ln6XE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ePHM/ITG2QecUmLKP1yRsRSIu0jCfsavPHvY/qz4XoOSiJD4GLZ7R8mI6+YW9J8Yb6+cXcTp4h/gg7grSu6h+acIlCOrqsb0u6stuSpqrKz4KqbpjbIPNMdDFTwfijbdDqm2Ie/FpscW9+1xqXtVVjuWnP2GMHxYI+UFKe+34IA= 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=01+lWVXa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PULjGNIT; arc=none smtp.client-ip=202.12.124.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="01+lWVXa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PULjGNIT" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.stl.internal (Postfix) with ESMTP id BD2F511401BD; Tue, 5 Nov 2024 01:18:00 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Tue, 05 Nov 2024 01:18:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787480; x=1730873880; bh=HHoBFb33Wz 5ywAmLAnRYaKiXTsJlEqx2TZ0vQR3gKg4=; b=01+lWVXaKNHIRXnQd/4afx2bMl 6MC1WCQhJpaY5ziagvUaEKsY74fH9/YXI8R4Rzhu37eoBuOwafSoCmPsyAqXKUDd GMcFT2cXfKQMF3HUlQ7ThO/qQhCINPX+FKMjvb20ljuLT3K7Jqs6T5CKD3om2jyy OFZALH0X0bXBfgEDZ/+xnwfuWFLO1A4+cf7E1oo4H8RgHuxAboTuAj6IsUH7jjnB TaYNSsNe5y+3HMiGLVGO61OMRSz6drCTng5NDiStZKkkzV3CKUAYjiJA7wHeuUqx pNNAUq/cQdK0VUFvalXu2/ZAzJTcwLcyxT34Ml538fgfalU2oW3aMFayTnrg== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787480; x=1730873880; bh=HHoBFb33Wz5ywAmLAnRYaKiXTsJlEqx2TZ0 vQR3gKg4=; b=PULjGNITNL46ze8/IhrVU083ECmHxzuKMXAnlAm6bddAG3hpTPw 1X1EhYZxOQ+H8zNGfn/8E2b5JrxILtYCk8mvb1VQETbyoXQ5jXkNY7nPNkQtJPqu 4ssh2Vz6iSQ/iEBosQ6H9+dBBYW0B9TzsjX3TLcI/F1+XKEFMkSC2Px0bLWFiptt QwP7T2WyfwYtDt/d5zeY46NomEEU3ko/YvbCdkvCDrACQnaPHCvKAEqmWffPY8G1 gyoQ8GncmWLPT+IAP7BcKDU751ZOE+xATRM7qKkXTEKteQ0Wn199AOxgl+0y/UjC p6fcYQ8lKtrgTBA3bk+fnKqEHAFdWTB/9bA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhmpdhrtghpthhtoh epmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehjlhhtohgslhgvrhesghhm rghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgshgsrghkkhesfhgrshhtmhgrihhl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:17:59 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5caf40be (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:37 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:49 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 21/22] builtin/merge: release output buffer after performing merge Message-ID: <0ff65c1213b7034c35d80796800d29de5ee74b52.1730786196.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 `obuf` member of `struct merge_options` is used to buffer output in some cases. In order to not discard its allocated memory we only release its contents in `merge_finalize()` when we're not currently recursing into a subtree. This results in some situations where we seemingly do not release the buffer reliably. We thus have calls to `strbuf_release()` for this buffer scattered across the codebase. But we're missing one callsite in git-merge(1), which causes a memory leak. We should ideally refactor this interface so that callers don't have to know about any such internals. But for now, paper over the issue by adding one more `strbuf_release()` call. Signed-off-by: Patrick Steinhardt --- builtin/merge.c | 1 + t/t6424-merge-unrelated-index-changes.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/builtin/merge.c b/builtin/merge.c index 84d0f3604bc..51038eaca84 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -754,6 +754,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, clean = merge_recursive(&o, head, remoteheads->item, reversed, &result); free_commit_list(reversed); + strbuf_release(&o.obuf); if (clean < 0) { rollback_lock_file(&lock); diff --git a/t/t6424-merge-unrelated-index-changes.sh b/t/t6424-merge-unrelated-index-changes.sh index 7677c5f08d0..a7ea8acb845 100755 --- a/t/t6424-merge-unrelated-index-changes.sh +++ b/t/t6424-merge-unrelated-index-changes.sh @@ -2,6 +2,7 @@ test_description="merges with unrelated index changes" +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Testcase for some simple merges From patchwork Tue Nov 5 06:17: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: 13862380 Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.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 25C121F708B for ; Tue, 5 Nov 2024 06:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787485; cv=none; b=OrIoyooF7cHGrfVFSmXYALJ2MC4cqICks7e0TKp1m5KPq7IEsKHD2ialBcHCu3ENANVYVBnKsSqNCJ86ZgqOWsaBL+skftsIk15PVlPbaUYLwB68QFhezYdJ847i4pJY5QnzndxZrWddApiFCNrs0Hf3FJDOLxOa8ughGW/4qVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730787485; c=relaxed/simple; bh=7ZM2cT7DjWer0j4yBhMpZUzZHNyKdBQ2zKPZMzPoUdQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RHJuUw9Gh3IzgGflIdQ6RCu+fi4pNk+60/RNC7K3bN3FYmmfY459IcMYLzLRJZbAtdzl3UUZ3ULEHChTqnhvWk/ZUDPspvLlmRm2ZyQc0Ikos1O9KxvTvAjNka1rdDZFkTVaqCOWlULgic2ZxK6MAnR3pYullqWCQy3euiwZBiA= 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=eJReO3nv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=culqB3Fe; arc=none smtp.client-ip=202.12.124.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="eJReO3nv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="culqB3Fe" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 72810114017D; Tue, 5 Nov 2024 01:18:03 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 05 Nov 2024 01:18:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730787483; x=1730873883; bh=P4f9MjiBqm ICtIdXDvdZS/UszsFcWc9lb8qB3huONGU=; b=eJReO3nv7xkzR83ZAYtyHnzHHC frP0L51s/ayro+HM8+PSuS74agBXY1Cr/jeVWQ2bSks7MtUgM9mcIDD2LC4xEp1i 9CMeoVewCanEiZLz7JVuH85teQ/B9JH2fnJEpPPrEVEFoSH/wRTWkBF5msCexAjr atset2OZ/Lfd4SlKKBieVVO3ORbLsAa/IlbAIy/Xn1xMF8C23dH/lUZWyL22EY2l 2ca2wF5XF5OtNMyh7NdWAQ++uKmS3Xo+GMiv9NxhOxDRUAUpWe+BH1yQX4JUS4jD OxUbrq1hq3lTvvC4L7ExZVd0Ijo/LJlQlNi4G097h9f/PcfX4LC1Rh482VwQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730787483; x=1730873883; bh=P4f9MjiBqmICtIdXDvdZS/UszsFcWc9lb8q B3huONGU=; b=culqB3Fe7CLBDU4CYVcL4N6POieDMIkbzdt4b8SUl208nflLD2D hIDvz77gHXwYoxecDfP3/3UgyOaGWAu9wEIBaF/ByvK3f+IDGBJ7Xj7bRUiKfVQi 559UmCPUOxfNB2zTgS4damr84pxjJyfc03EGh9Ld/zGB9fGK895RbFiGaLTz9dzK K11AGmLQ9s72puIdJ1cw4/2Q27kjITr1KZQ3V3IQgefmmcC5ArL5n7rgVNzKoMzy u9FWOiWv30J+CjJlOxPeEnbOWot8KPLqwpRhu2mQeRPdFd4ndseAYCwmGYLwj4JL SkqBO1YQht/trievCGOH0MxEXQuR993WmKw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehmvges thhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepkhhrihhsthhofhhfvghrhhgruhhgsh gsrghkkhesfhgrshhtmhgrihhlrdgtohhmpdhrtghpthhtohepthhoohhnsehiohhttghl rdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Nov 2024 01:18:02 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a673ccbc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 5 Nov 2024 06:17:40 +0000 (UTC) Date: Tue, 5 Nov 2024 07:17:54 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Toon Claes , Kristoffer Haugsbakk , Justin Tobler Subject: [PATCH v3 22/22] list-objects-filter-options: work around reported leak on error 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: This one is a little bit more curious. In t6112, we have a test that exercises the `git rev-list --filter` option with invalid filters. We execute git-rev-list(1) via `test_must_fail`, which means that we check for leaks even though Git exits with an error code. This causes the following leak: Direct leak of 27 byte(s) in 1 object(s) allocated from: #0 0x5555555e6946 in realloc.part.0 lsan_interceptors.cpp.o #1 0x5555558fb4b6 in xrealloc wrapper.c:137:8 #2 0x5555558b6e06 in strbuf_grow strbuf.c:112:2 #3 0x5555558b7550 in strbuf_add strbuf.c:311:2 #4 0x5555557c1a88 in strbuf_addstr strbuf.h:310:2 #5 0x5555557c1d4c in parse_list_objects_filter list-objects-filter-options.c:261:3 #6 0x555555885ead in handle_revision_pseudo_opt revision.c:2899:3 #7 0x555555884e20 in setup_revisions revision.c:3014:11 #8 0x5555556c4b42 in cmd_rev_list builtin/rev-list.c:588:9 #9 0x5555555ec5e3 in run_builtin git.c:483:11 #10 0x5555555eb1e4 in handle_builtin git.c:749:13 #11 0x5555555ec001 in run_argv git.c:819:4 #12 0x5555555eaf94 in cmd_main git.c:954:19 #13 0x5555556fd569 in main common-main.c:64:11 #14 0x7ffff7ca714d in __libc_start_call_main (.../lib/libc.so.6+0x2a14d) #15 0x7ffff7ca7208 in __libc_start_main@GLIBC_2.2.5 (.../libc.so.6+0x2a208) #16 0x5555555ad064 in _start (git+0x59064) This leak is valid, as we call `die()` and do not clean up the memory at all. But what's curious is that this is the only leak reported, because we don't clean up any other allocated memory, either, and I have no idea why the leak sanitizer treats this buffer specially. In any case, we can work around the leak by shuffling things around a bit. Instead of calling `gently_parse_list_objects_filter()` and dying after we have modified the filter spec, we simply do so beforehand. Like this we don't allocate the buffer in the error case, which makes the reported leak go away. It's not pretty, but it manages to make t6112 leak free. Signed-off-by: Patrick Steinhardt --- list-objects-filter-options.c | 17 +++++++---------- t/t6112-rev-list-filters-objects.sh | 1 + 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index 00611107d20..fa72e81e4ad 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -252,16 +252,14 @@ void parse_list_objects_filter( const char *arg) { struct strbuf errbuf = STRBUF_INIT; - int parse_error; if (!filter_options->filter_spec.buf) BUG("filter_options not properly initialized"); if (!filter_options->choice) { + if (gently_parse_list_objects_filter(filter_options, arg, &errbuf)) + die("%s", errbuf.buf); strbuf_addstr(&filter_options->filter_spec, arg); - - parse_error = gently_parse_list_objects_filter( - filter_options, arg, &errbuf); } else { struct list_objects_filter_options *sub; @@ -271,18 +269,17 @@ void parse_list_objects_filter( */ transform_to_combine_type(filter_options); - strbuf_addch(&filter_options->filter_spec, '+'); - filter_spec_append_urlencode(filter_options, arg); ALLOC_GROW_BY(filter_options->sub, filter_options->sub_nr, 1, filter_options->sub_alloc); sub = &filter_options->sub[filter_options->sub_nr - 1]; list_objects_filter_init(sub); - parse_error = gently_parse_list_objects_filter(sub, arg, - &errbuf); + if (gently_parse_list_objects_filter(sub, arg, &errbuf)) + die("%s", errbuf.buf); + + strbuf_addch(&filter_options->filter_spec, '+'); + filter_spec_append_urlencode(filter_options, arg); } - if (parse_error) - die("%s", errbuf.buf); } int opt_parse_list_objects_filter(const struct option *opt, diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh index 0387f35a326..71e38491fa8 100755 --- a/t/t6112-rev-list-filters-objects.sh +++ b/t/t6112-rev-list-filters-objects.sh @@ -5,6 +5,7 @@ test_description='git rev-list using object filtering' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test the blob:none filter.