From patchwork Tue Aug 6 08:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754572 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 2123B1BF329 for ; Tue, 6 Aug 2024 08:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934782; cv=none; b=Bgkr3mZ5CbUP+tGusEDXZB+ApmUeXbuvB2iU/lXX8dxUV8XEvO1ZZn/7OmzqrkvV+XAEuSBwkJWeF4MDGnjdBAcS0wugNCyYQ46dD3LXJcTeLvucqOkJkKESJtf/uGmRcHnhspYh0YqN2R3q85IiW5JsTV+jYKBbcxyEV5MzuR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934782; c=relaxed/simple; bh=naIFcnC3+pjdnXxowjpdQ2CDohadq0vhycJQxO5EnAk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EFuGWaXS+1vPzgbbARXqQWNgejyWCKFZTPsPsnC3VwFi6vvDy6OlwtOBBHsLKE/sIEYpUw58tYwfgaUOlr93XsmX6Pf4MSBVjrF2pZw38QNjX7sAZ94LGRhps0l6c/pMIo2tPGxfRueQ8IMBqJqDL8i0Fj5nTcDeHiSgdgsTMHU= 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=QlAaE5Df; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jBOCTjFS; arc=none smtp.client-ip=103.168.172.149 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="QlAaE5Df"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jBOCTjFS" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id 41DF9138FC93 for ; Tue, 6 Aug 2024 04:59:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 04:59:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934780; x=1723021180; bh=GLYSI9/9kn NsdzTwXIoh00+VYFUlWuDRBUhHDuCRvbg=; b=QlAaE5DfKsp90yWrx/4PnJGYeY gzoM+eCqFKLcQKy3BfhyhIzakVrk96B46Y29+aSSIE1rX3Kx6/tzz2opnGPqHkeG blHit2PlLZcR9GtZEzDFS38XhzO3NZZ7KN+TjujJAnZZRF3DIXPql2Gm8AisVI/N p4a/QUeUSeqtZLia4DEm6RSDFpjJwfly/4SHzmEB2Nff5eAXJt/XrTutLPZSsKvI eSFKlGNEyYboAVPqILYGEH/ZHT6NARjdByHc0LHE2ja1CK+uETUVvyMnMoCHUUdu lDC5tWYCohbO3oMkuqFv0GOs/cs52iXiuYyB/9fTUzXqIzpIi+85eWs6IIEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934780; x=1723021180; bh=GLYSI9/9knNsdzTwXIoh00+VYFUl WuDRBUhHDuCRvbg=; b=jBOCTjFS3/1SfrpwmbAgY9Vizv0/gu41ZpTceBOZY6rE 6Pk+KwZC4ftkQrEOrEVuH8MqMhRJ8cIUo0uhBtChpHbmHS1fYZ3jC9GssHndGAu5 sGsMo0O+RmYnI6xYisWx6F3Sip7ry+G2FXNVnFOrcN0bj3L0XMAq/Lt9WzLxmt6p Dqm80yjODT+OUV3rQhp1RwTrR5pqxp+alih5MpLbNlqjqp/Rjd1rJPHjx0jO0Yy3 s1w+uqgLVhZs6z2uZSQJMDwmyx74Rer/ZKrCMA9adBf078xHxfbcn3x6NH6Noopx xfDTasA6KtE0Sy+1GOoDsdbxUw1v2aP7nNv7lqm/yQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 04:59:39 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3d82ed45 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 08:59:37 +0000 (UTC) Date: Tue, 6 Aug 2024 10:59:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/22] remote: plug memory leak when aliasing URLs Message-ID: <6e2fcd85c7032a8f6ee0969ee230f3e319872e09.1722933642.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When we have a `url.*.insteadOf` configuration, then we end up aliasing URLs when populating remotes. One place where this happens is in `alias_all_urls()`, where we loop through all remotes and then alias each of their URLs. The actual aliasing logic is then contained in `alias_url()`, which returns an allocated string that contains the new URL. This URL replaces the old URL that we have in the strvec that contanis all remote URLs. We replace the remote URLs via `strvec_replace()`, which does not hand over ownership of the new string to the vector. Still, we didn't free the aliased URL and thus have a memory leak here. Fix it by freeing the aliased string. Signed-off-by: Patrick Steinhardt --- remote.c | 2 ++ t/t0210-trace2-normal.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/remote.c b/remote.c index f43cf5e7a4..3b898edd23 100644 --- a/remote.c +++ b/remote.c @@ -499,6 +499,7 @@ static void alias_all_urls(struct remote_state *remote_state) if (alias) strvec_replace(&remote_state->remotes[i]->pushurl, j, alias); + free(alias); } add_pushurl_aliases = remote_state->remotes[i]->pushurl.nr == 0; for (j = 0; j < remote_state->remotes[i]->url.nr; j++) { @@ -512,6 +513,7 @@ static void alias_all_urls(struct remote_state *remote_state) if (alias) strvec_replace(&remote_state->remotes[i]->url, j, alias); + free(alias); } } } diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh index c312657a12..b9adc94aab 100755 --- a/t/t0210-trace2-normal.sh +++ b/t/t0210-trace2-normal.sh @@ -2,7 +2,7 @@ test_description='test trace2 facility (normal target)' -TEST_PASSES_SANITIZE_LEAK=false +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Turn off any inherited trace2 settings for this test. From patchwork Tue Aug 6 08:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754573 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 F27361BD508 for ; Tue, 6 Aug 2024 08:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934788; cv=none; b=f0oLkXL7UrvGqWZVnPNglr9vEm22o4VDEb69cXA0brcRid5lIf8TffZRChPf5Wo4mGosNucMMxczKS9XHGm7nS1HqEY42fALObLMhDdxb9FWrIp1VlrI3K5adXdf95a0te8otTis5hyg4YnfwywSUNL6Y5r1JdABRK/M3/i8JQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934788; c=relaxed/simple; bh=XNHqBuZcwuXZ9C9SUm2otTPyC9P9mZiFszsstRihIi0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bc11axenXtAPBnDycmo23LETE1WZheQ984BC1UWKi1cxspsjcQRLZXKCYQaKb9Gx+VBY8X2oongi4LXRrUAr1Z/lTjHD9HH6eamvDshN//DoZq0ow9o2umEI3pwMYvUdBZKV8bts6YURWbMUS2ZN9S1lCTY879xxKVAsRoi8bzE= 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=DiCMl0/U; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XJAJ2fO9; arc=none smtp.client-ip=103.168.172.149 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="DiCMl0/U"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XJAJ2fO9" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 1DC4F138FCCA for ; Tue, 6 Aug 2024 04:59:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 06 Aug 2024 04:59:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934786; x=1723021186; bh=f71kXdzcDB u72qvYvk2BETMdoYrZixQpu96iCp8tu+I=; b=DiCMl0/UOK5Qa8wW4tLfKqDgws vyNeZhcnzAPy27c7L2uOBZhJuQQA/V0vFuZNOHLRgI+PRiEkVuCIRi9RsJXd33EJ 3REv18sWvd9qLYSKpoNJAuZd/lmuRw2IhvQT6Qk6eYrZudxrDMPvMxsmFJUoApNy T3WWewNLdsXbDN2tZF9A/wwDgr1JTNCIQGXyXPb2S7WJvJxJNwrKbPrjg0RDO/QP Pq432kydnscVJoiZIwD6lzvjgL09HDK1oRYnsXzlLONvNJrQlE7idMGkBnmjQV1k pR5erfQgPnig4aAJ3ARwmdTsTNGksqQ34qBp5D7UOBeRupQTsdbl0Ud40nVQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934786; x=1723021186; bh=f71kXdzcDBu72qvYvk2BETMdoYrZ ixQpu96iCp8tu+I=; b=XJAJ2fO9mPenqiOocYtjSFU7QbBIpUqA4jOI4fuFCg0+ X965qh3Im0hXd7DMStnSaB59OzTRuZulPfeN3WtYCxGSIdakiE2xLEBXtM85zWJZ F6LHKgzOt5ioMkbDz34bkhmfFL++S/S9KfdLf+ugFEhD2gTsJd8a4IVrPnjJqqiq eWdqAiiTaYS3RUMYVhLMTyus3cwuwNtIunIseU68nJ6651T4Tp2irWDE36/oMLI0 o+PyOSShYB9zSCU+Cv1qXLy7CFYZ7mWLIuVzGLss7qo/G8aUjmzNypmVVonWtZPa eLm3rf2w/C8KXiUCUJh5mqVLN+6maWRQMHBkDxlyyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 04:59:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f9c1e295 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 08:59:43 +0000 (UTC) Date: Tue, 6 Aug 2024 10:59:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/22] git: fix leaking system paths Message-ID: <9574995a246d96b90f03827bf0ba591593d6c4d9.1722933642.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Git has some flags to make it output system paths as they have been compiled into Git. This is done by calling `system_path()`, which returns an allocated string. This string isn't ever free'd though, creating a memory leak. Plug those leaks. While they are surfaced by t0211, there are more memory leaks looming exposed by that test suite and it thus does not yet pass with the memory leak checker enabled. Signed-off-by: Patrick Steinhardt --- git.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/git.c b/git.c index e35af9b0e5..5eab88b472 100644 --- a/git.c +++ b/git.c @@ -173,15 +173,21 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) exit(0); } } else if (!strcmp(cmd, "--html-path")) { - puts(system_path(GIT_HTML_PATH)); + char *path = system_path(GIT_HTML_PATH); + puts(path); + free(path); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "--man-path")) { - puts(system_path(GIT_MAN_PATH)); + char *path = system_path(GIT_MAN_PATH); + puts(path); + free(path); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "--info-path")) { - puts(system_path(GIT_INFO_PATH)); + char *path = system_path(GIT_INFO_PATH); + puts(path); + free(path); trace2_cmd_name("_query_"); exit(0); } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { From patchwork Tue Aug 6 08:59:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754574 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 D52C61BD508 for ; Tue, 6 Aug 2024 08:59:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934793; cv=none; b=Bq8YIFJ5o7cku1IQ79n2Eq51rvP7Xol9td04aqPfdjJZjCTp2v2WghwyR1m6W+pytkfWpoooTKO1pO1KNA5nS5xN+ill3dRSaVrILfvBmJ8VXO66KKpGFLne3kciJG2VYL1JaZcbuxmQ+4PgeOBd/Kg5AIvFM85672Pt+cXdrdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934793; c=relaxed/simple; bh=9sqiCUGKL4fFhY9YtyG1+ukPoTUqyDC2a4zI3I3G6b8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F/kdgZl5eoxnZWteIFcVK+3i2dcgrv1MTYSauhIIHszeNXGCu5an07hT1HFEeMrJVvtPOqjHTNBpHu8RPlpDLHfiWlSXHKUPYiLN0idqNb4xz+GjR5ySP3yOhWiUw4uD4wQxD573QEA/KV/hrDZnJ0s5UwnpemHskCxLp/4osA4= 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=NF+NsDYk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JesjnuRL; arc=none smtp.client-ip=103.168.172.154 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="NF+NsDYk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JesjnuRL" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id ECC141151B24 for ; Tue, 6 Aug 2024 04:59:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 06 Aug 2024 04:59:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934790; x=1723021190; bh=sEzBnOQkD1 VBZQkPq+W7w7U4JSuW4yETUtc224/tFvI=; b=NF+NsDYk1PDtmuzvEOTHMJ7LtK NvGDqcZAnBdfMXJ4DdNsI2OqCdOKTUpoLgVOgQ+AjzjPYBxfFs5E5Y+7YCiPUqH5 5Hyh6Nu2XGX9vz0jDUjIP8EoEBpb6QTDas4w4Q3O9pALR3vrC7iLEiVov9m9LdCr Ku0ieGILhcX9+r2KSus0JhTYKq+PaUK5BbMcLlOfKscS78NjMNJCYM3sKm9mhWPy EjP2Il7/ISI8FbljTkOBDs5a00dJKu7KItGL3KCh3N2Wa4tk50zru1C61kSLJQy/ nLXDjufw9wmbAon0jrtZBd0MgVKec0HZeuzqzjPQjpIi3xVV2Itj4lPBcA2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934790; x=1723021190; bh=sEzBnOQkD1VBZQkPq+W7w7U4JSuW 4yETUtc224/tFvI=; b=JesjnuRL3C52pOxuDDpvQABaAoFUTX0xH4T1tUTIvLvk QrM2jaP8dR4dvCr9Mq6x5eFM6lipRXUwXA+hTqWsmFUMWhWoUoFN0yWdTM0cpJYi CnDrk4rxHIhuD0qiVWM7G+8nFicSX/tO44uA231StDI/VHXwJbh79ftXyKqqwEwT 2zYE4LISNuX3zRbRfWMfJpYDX0PUxf8rN1S4PCRBlIovd085IHoQAX3Sbnl5j6qI 5agLns1S5f20UEHiAjjK5bTMFeJcoMvMYCbWAXtH0tR4mnf6fTRLO5c75uUtRDpJ FINJS37BV2dh6CaV9pUOkcrfoLTfeMoEmsGtBkEoNw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 04:59:50 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a3ebe71e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 08:59:47 +0000 (UTC) Date: Tue, 6 Aug 2024 10:59:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/22] object-file: fix memory leak when reading corrupted headers 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 reading corrupt object headers in `read_loose_object()`, then we bail out immediately. This causes a memory leak though because we would have already initialized the zstream in `unpack_loose_header()`, and it is the callers responsibility to finish the zstream even on error. While this feels weird, other callsites do it correctly already. Fix this leak by ending the zstream even on errors. We may want to revisit this interface in the future such that the callee handles this for us already when there was an error. Signed-off-by: Patrick Steinhardt --- object-file.c | 1 + t/t1450-fsck.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/object-file.c b/object-file.c index 065103be3e..7c65c435cd 100644 --- a/object-file.c +++ b/object-file.c @@ -2954,6 +2954,7 @@ int read_loose_object(const char *path, if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), NULL) != ULHR_OK) { error(_("unable to unpack header of %s"), path); + git_inflate_end(&stream); goto out; } diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 8a456b1142..280cbf3e03 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -6,6 +6,7 @@ test_description='git fsck random collection of tests * (main) A ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' From patchwork Tue Aug 6 08:59: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: 13754575 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 A66281BD508 for ; Tue, 6 Aug 2024 08:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934798; cv=none; b=XiuuhDczY/HUYF/ER6TNXfa2OrywKo45ANm8HROWQOBZekPHJixOSV91qTiURR5dtsUFeiCRzgBfZg3RpdZacJvRgC1na/rjm7x+2Usqhdab3pPAxB4BrdvdRPY2MdrInEst2QurUFslVTeg41U7TybBj+7d3L5stA4MsgV9Ef0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934798; c=relaxed/simple; bh=PQ6HvMuClx2Wms+Z4AqCrqvyF7OwIPHYeMMP5EDPvMw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q6TTiorN4+FqWiZfhlzEGWSk80iGhvI4fVDeifr6vb3CDhQTvgpevuc0dfAiCv/P8+62H0HikZs+frxH8qKRzfzD3uEP+5MX3f5uQojJ6I2BKNiqlT41QpRbRb8B4vQxBIcK+/dBHx2GdPxVv1cW+lvtoFRv+ZCcmPBBIbcVYxw= 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=bGKd6UWS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nHOKFmkF; arc=none smtp.client-ip=103.168.172.149 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="bGKd6UWS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nHOKFmkF" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id CD0DE138FC93 for ; Tue, 6 Aug 2024 04:59:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 06 Aug 2024 04:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934795; x=1723021195; bh=ap73Do47Aa 9PhER5/lZPg7qzD5Kw8GgpmY26owWVa6Y=; b=bGKd6UWSYw+JhDJ+d4kdhqLFvn Cp0+u74bYY7fMPS14HJiTgivBSfkC+vyeYzWu0tlpcC7DnxS38356L4Oia37lxTL vBtQ/yw5ln7+ovfapy7/0S4R8y0mRerLHsMmFxDQRuOq/2oUlki6pY5GUgE9kK09 RY/pmcHchK3331o+sRT1QYGmK4shsJ1cuFyQkZkqlL0MEcvDVrGInf0kBNQRLSaT MXWV5RpNVUfHzuNiYsPzldcKEbWS4sGbtq0FqKHzwhFMw5f/n/KF/Zzgofix1gXX CQEXApF6ay3CHP6TIes0M5VMf3gFS4uuYtAlqQfe5M6+N9KYb6w/mSYxqLbg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934795; x=1723021195; bh=ap73Do47Aa9PhER5/lZPg7qzD5Kw 8GgpmY26owWVa6Y=; b=nHOKFmkFXOfX1qE8Gn8d04oWaaqyoyaNw60JdOKwDunU rKS2nxl2Ef4RDVIQuCX+GJfmv20mbg6Ao96PiDKRJaMI8r6dEsRFXy0QpBZatZb/ ObHxZXvg4WLo5kOqBZdwC6/cVQ87J7V+2okVlw3otZMIQGDYi1QqPAejJRocjk1S Wzo8rkDNM0mmRGqaI39gz/UseP7YylKkFsJjhYqChzeRWF73VdS/60OprkCR+q6r 69OnopB/6mm19mX8AskInxZmj0IBnuaSlJDmVUXTSruXwDuZsiSayN4h6PxF/twD AixF3V5Kskg6JJX4n4VJalBhM5N4ltPc0ePFZ2jg7w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 04:59:55 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id abb9a06c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 08:59:52 +0000 (UTC) Date: Tue, 6 Aug 2024 10:59:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/22] object-name: fix leaking symlink paths in object context 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 object context may be populated with symlink contents when reading a symlink, but the associated strbuf doesn't ever get released when releasing the object context, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- object-name.c | 1 + t/t1006-cat-file.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/object-name.c b/object-name.c index 240a93e7ce..e39fa50e47 100644 --- a/object-name.c +++ b/object-name.c @@ -1765,6 +1765,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name) void object_context_release(struct object_context *ctx) { free(ctx->path); + strbuf_release(&ctx->symlink_path); } /* diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index ff9bf213aa..d36cd7c086 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -2,6 +2,7 @@ test_description='git cat-file' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_cmdmode_usage () { From patchwork Tue Aug 6 08:59:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754576 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 6D33A1BDAA6 for ; Tue, 6 Aug 2024 09:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934803; cv=none; b=V+jx8Yv1ihEM98bm5lybH8QYNi/3n47hp0LK+fagYMJqojUg6tP+KYThP+4yjbHmllhnmi7ktih3Qwr2aZyKAAz6wd9y9QS19paWWAR/EbJnnLwmVK54CIb8hEAVJHjNikkrlfAsCMf77MNzVWWtKNjXsS8EubylqBaI2e2kRjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934803; c=relaxed/simple; bh=6Nxllw8uVJwfNbh9C1HphZG0xVARTyyuqQcmTBBG32Q=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=givShShcOls4jj5MXlkUDMXF7rZtc6JBPo5ZBmtxYqioBZTSamtBBg7AkrGlW8+k6MJwR/cxod2LurPANWxt14NFWiWKJxbT29Aa9tXy2JGCWN3WT6cV/lCSAeASlFHwJ4c0MikcOzMA1fzj4IAIiXDREdmt5oh/h/Dp1BMIwAA= 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=fA0H5AR7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QmAPzzIY; arc=none smtp.client-ip=103.168.172.154 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="fA0H5AR7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QmAPzzIY" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A482E1151B49 for ; Tue, 6 Aug 2024 05:00:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 06 Aug 2024 05:00:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934800; x=1723021200; bh=GP9fctTnqb qMwZt4BwhZv9MGju5UdPodsG1Nk5WaDdc=; b=fA0H5AR7yMU/U6wo3gZwfK3fdX +0S/9zK2eJqoZnRksCgpDRyLiQubFETxvCNEVSQsUjBgSTFY4sP7qvZT/UZVBfgS OKAHaQoXuNPyTfiIZ/bu8ANVMF211i8yXg4OYmYQlWY23awrc43UBAUXtKQhSAzC KPlfrCg1yrzF8zV+h0QexB/EU+po7028OgoVYN780HEy8kLI/25lORlzXbc+KaoC yLzbtmtmp7stBJyq3GpJye8vg5+t5IYAL13bzKsyCi3+hx8y8rTu81JGIE/NDrf+ aC+RZfqFACbqmxu5BrP4wBXMUQQvtTN9mSEgMoYDJ2A00hZnRZY5iWmvzWIQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934800; x=1723021200; bh=GP9fctTnqbqMwZt4BwhZv9MGju5U dPodsG1Nk5WaDdc=; b=QmAPzzIYqCh2AJxQCvKIqstRGzqXJaoJvvVJSWF/SekC QjifOfVRyrxHjxp+8XZ4q2+6VHOP7XLkxBag1oqWvwcFcos0bV/ubz9uUrpPLaJ0 CmRSUTBcptQ5fKf3h5pbvrBUdoTYeuwUoTCVcz04ZFrAvxsjVdcdvATOwomwIJK+ P87QsRKcY5EjstEDn4U+r2VsUxQVyF2g7+YoebeE8fGvoDz/CjNUNmrWnLVMEuTE wwO3PonnMuBBnhbu8Vv3TgAv9HcUiQQruNI+98a+/s2F8rVygjEzyMb7yKHveuDH I/xow9/ljnjQtJv1PoqV4wI6uzjmt7MvlwE0e4GbeQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 04:59:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id cc667097 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 08:59:57 +0000 (UTC) Date: Tue, 6 Aug 2024 10:59:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/22] bulk-checkin: fix leaking state TODO Message-ID: <794af6610395add19abb359be5245e95a57681d0.1722933642.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When flushing a bulk-checking to disk we also reset the `struct bulk_checkin_packfile` state. But while we free some of its members, others aren't being free'd, leading to memory leaks: - The temporary packfile name is not getting freed. - The `struct hashfile` only gets freed in case we end up calling `finalize_hashfile()`. There are code paths though where that is not the case, namely when nothing has been written. For this, we need to make `free_hashfile()` public. Fix those leaks. Signed-off-by: Patrick Steinhardt --- bulk-checkin.c | 2 ++ csum-file.c | 2 +- csum-file.h | 10 ++++++++++ t/t1050-large.sh | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bulk-checkin.c b/bulk-checkin.c index da8673199b..9089c214fa 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -61,6 +61,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state) if (state->nr_written == 0) { close(state->f->fd); + free_hashfile(state->f); unlink(state->pack_tmp_name); goto clear_exit; } else if (state->nr_written == 1) { @@ -83,6 +84,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state) free(state->written[i]); clear_exit: + free(state->pack_tmp_name); free(state->written); memset(state, 0, sizeof(*state)); diff --git a/csum-file.c b/csum-file.c index 8abbf01325..7e0ece1305 100644 --- a/csum-file.c +++ b/csum-file.c @@ -56,7 +56,7 @@ void hashflush(struct hashfile *f) } } -static void free_hashfile(struct hashfile *f) +void free_hashfile(struct hashfile *f) { free(f->buffer); free(f->check_buffer); diff --git a/csum-file.h b/csum-file.h index 566e05cbd2..ca553eba17 100644 --- a/csum-file.h +++ b/csum-file.h @@ -46,6 +46,16 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *); struct hashfile *hashfd(int fd, const char *name); struct hashfile *hashfd_check(const char *name); struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp); + +/* + * Free the hashfile without flushing its contents to disk. This only + * needs to be called when not calling `finalize_hashfile()`. + */ +void free_hashfile(struct hashfile *f); + +/* + * Finalize the hashfile by flushing data to disk and free'ing it. + */ int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int); void hashwrite(struct hashfile *, const void *, unsigned int); void hashflush(struct hashfile *f); diff --git a/t/t1050-large.sh b/t/t1050-large.sh index c71932b024..ed638f6644 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -3,6 +3,7 @@ test_description='adding and checking out large blobs' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'core.bigFileThreshold must be non-negative' ' From patchwork Tue Aug 6 09:00:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754577 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 641031BDAAE for ; Tue, 6 Aug 2024 09:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934808; cv=none; b=Dv3xhStP/ZoOPvbJGcR4OjSYS7kAxt9Owo7HicinKFhTp/8NQIpu/xu0EJw+24iOLBiwrKPWo52v93aLs5oVV+6u2l66HCUfvDVmabTO1CLyqXK29Fl+oDQoPK7iQKUGVN7Z4tmEuDfXOa8AWNp24647J4+TFt7H3z0TOP/6kXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934808; c=relaxed/simple; bh=PjSWDfbxvArxxbn6qzEY2HwHRNE4WNNY/7PSwjE7BEw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XFfkp93dE7fpW3RwMlShNoXP817XuncBcBpSEPGt5GxjP7voC47pLXOZNss1DxtdYX2anTxouze/6KTz+5AO7aYVzC9yrOv7ouCNMVlC52H65RheMtLwZ4HUwQ4fogl129U/k9jEkqBQMMHIfbmcQAPinKyxv6LLN2hslCf3B/Y= 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=AYyodQKc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nGAfdMKE; arc=none smtp.client-ip=103.168.172.154 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="AYyodQKc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nGAfdMKE" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 78FCF1151B24 for ; Tue, 6 Aug 2024 05:00:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 06 Aug 2024 05:00:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934805; x=1723021205; bh=iQqR5G7Vp7 DRu71uih2u0yJQtxAimCKed0kMbFuE9XE=; b=AYyodQKcSfEY4G1zN7jMvfTTbi 1F5vyEcs9ScewuoNNIofgXCSvvBOuro/HDrF+M4pFxISUhqnE+TqbY8nDTNphHHV Y4X4gPybHC/B9uJRibjBDLbyXAt8ft2zadSf//skBjk/rt+/Oa4Cr2G7wFhBLknz crwfMe4/OLB5xpDE2I0srV/Tt+XuxokdhkuwxH8DYUuVtFd5P5isF8Dv5tjiKLUd f3XrTegCgN0Ij3+oz6f5+SJNznzZVgvAejFDJPuvy70YWdMe9xlyJWAg+IAQFyaj Dl+keamGe1twA/pEKsiVvgAi7JImH3PkmtEBxJgMJ32gXUl6V4yKR10gwc6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934805; x=1723021205; bh=iQqR5G7Vp7DRu71uih2u0yJQtxAi mCKed0kMbFuE9XE=; b=nGAfdMKE0mRx4t3IaW9pg6LRajaA/EGS17SXcQ4st4ld OV/xo1eoPKfGVK7WBlpRGX1k+iJCC8w6QOnniqBQcCJJwXnQBxJ5BGtXILheimhS /rkH2eFtnwBEn5Yvay/YoGA/Bl/a+IzB1HwlI154pHKb4Zg4/XRgmvW3fu27mjmU R8kBbUVSLsA8g7XZUEuZ9G+oDbsTbIxqDsrtEJ2PBjFAmzkilx4Z8RJKmI4QpUkk 5SJuzk4brWmF8Mwc2MoZL69Xkdlb/kwAZg21Xc4dIFr5Jhh7OKJ1wTHGSqH2ScNa YRJQPGyTWH9lFST1ihU5kzBNTw8DSyZ80IMENUiOfg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e6b788ce (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:02 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/22] read-cache: fix leaking hashfile when writing index fails Message-ID: <2810cada0af14c3331674a807b20d18e6c9af022.1722933642.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_write_index()`, we use a `struct hashfile` to write the index with a trailer hash. In case the write fails though, we never clean up the allocated `hashfile` state and thus leak memory. Refactor the code to have a common exit path where we can free this and other allocated memory. While at it, refactor our use of `strbuf`s such that we reuse the same buffer to avoid some unneeded allocations. Signed-off-by: Patrick Steinhardt --- read-cache.c | 97 ++++++++++++++++++------------ t/t1601-index-bogus.sh | 2 + t/t2107-update-index-basic.sh | 1 + t/t7008-filter-branch-null-sha1.sh | 1 + 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/read-cache.c b/read-cache.c index 48bf24f87c..36821fe5b5 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2840,8 +2840,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, int csum_fsync_flag; int ieot_entries = 1; struct index_entry_offset_table *ieot = NULL; - int nr, nr_threads; struct repository *r = istate->repo; + struct strbuf sb = STRBUF_INIT; + int nr, nr_threads, ret; f = hashfd(tempfile->fd, tempfile->filename.buf); @@ -2962,8 +2963,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, strbuf_release(&previous_name_buf); if (err) { - free(ieot); - return err; + ret = err; + goto out; } offset = hashfile_total(f); @@ -2985,20 +2986,20 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, * index. */ if (ieot) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_ieot_extension(&sb, ieot); err = write_index_ext_header(f, eoie_c, CACHE_EXT_INDEXENTRYOFFSETTABLE, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - free(ieot); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_SPLIT_INDEX_EXTENSION && istate->split_index) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); if (istate->sparse_index) die(_("cannot write split index for a sparse index")); @@ -3007,59 +3008,66 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, write_index_ext_header(f, eoie_c, CACHE_EXT_LINK, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_CACHE_TREE_EXTENSION && !drop_cache_tree && istate->cache_tree) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); cache_tree_write(&sb, istate->cache_tree); err = write_index_ext_header(f, eoie_c, CACHE_EXT_TREE, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_RESOLVE_UNDO_EXTENSION && istate->resolve_undo) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); resolve_undo_write(&sb, istate->resolve_undo); err = write_index_ext_header(f, eoie_c, CACHE_EXT_RESOLVE_UNDO, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_UNTRACKED_CACHE_EXTENSION && istate->untracked) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_untracked_extension(&sb, istate->untracked); err = write_index_ext_header(f, eoie_c, CACHE_EXT_UNTRACKED, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (write_extensions & WRITE_FSMONITOR_EXTENSION && istate->fsmonitor_last_update) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_fsmonitor_extension(&sb, istate); err = write_index_ext_header(f, eoie_c, CACHE_EXT_FSMONITOR, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } if (istate->sparse_index) { - if (write_index_ext_header(f, eoie_c, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0) - return -1; + if (write_index_ext_header(f, eoie_c, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0) { + ret = -1; + goto out; + } } /* @@ -3069,14 +3077,15 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, * when loading the shared index. */ if (eoie_c) { - struct strbuf sb = STRBUF_INIT; + strbuf_reset(&sb); write_eoie_extension(&sb, eoie_c, offset); err = write_index_ext_header(f, NULL, CACHE_EXT_ENDOFINDEXENTRIES, sb.len) < 0; hashwrite(f, sb.buf, sb.len); - strbuf_release(&sb); - if (err) - return -1; + if (err) { + ret = -1; + goto out; + } } csum_fsync_flag = 0; @@ -3085,13 +3094,16 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, finalize_hashfile(f, istate->oid.hash, FSYNC_COMPONENT_INDEX, CSUM_HASH_IN_STREAM | csum_fsync_flag); + f = NULL; if (close_tempfile_gently(tempfile)) { - error(_("could not close '%s'"), get_tempfile_path(tempfile)); - return -1; + ret = error(_("could not close '%s'"), get_tempfile_path(tempfile)); + goto out; + } + if (stat(get_tempfile_path(tempfile), &st)) { + ret = -1; + goto out; } - if (stat(get_tempfile_path(tempfile), &st)) - return -1; istate->timestamp.sec = (unsigned int)st.st_mtime; istate->timestamp.nsec = ST_MTIME_NSEC(st); trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed); @@ -3105,7 +3117,14 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, trace2_data_intmax("index", the_repository, "write/cache_nr", istate->cache_nr); - return 0; + ret = 0; + +out: + if (f) + free_hashfile(f); + strbuf_release(&sb); + free(ieot); + return ret; } void set_alternate_index_output(const char *name) diff --git a/t/t1601-index-bogus.sh b/t/t1601-index-bogus.sh index 4171f1e141..5dcc101882 100755 --- a/t/t1601-index-bogus.sh +++ b/t/t1601-index-bogus.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test handling of bogus index entries' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'create tree with null sha1' ' diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index cc72ead79f..f0eab13f96 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -5,6 +5,7 @@ test_description='basic update-index tests Tests for command-line parsing and basic operation. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'update-index --nonsense fails' ' diff --git a/t/t7008-filter-branch-null-sha1.sh b/t/t7008-filter-branch-null-sha1.sh index 93fbc92b8d..0ce8fd2c89 100755 --- a/t/t7008-filter-branch-null-sha1.sh +++ b/t/t7008-filter-branch-null-sha1.sh @@ -2,6 +2,7 @@ test_description='filter-branch removal of trees with null sha1' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup: base commits' ' From patchwork Tue Aug 6 09:00:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754578 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 209BA1BD027 for ; Tue, 6 Aug 2024 09:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934812; cv=none; b=SRnm4PWjm8eeCupCGoh+uSfLu7kwbSJJj/p4H3haQiVUsgT1xQUzH5iGVbGrft3MReq6Ym1R9btGa1c2Jg1lbqhJAjCm4+2YMSC6x3G9BFN3ZJIgAtEmfOfccvsJk6Z1KBtJqSDiXkN1zIVJ+vdaN5MSHZehHiljz6DMVyNwpQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934812; c=relaxed/simple; bh=6mkLbZox9A+qRx6jFBZAKgMCt8KW9FTmgq9C/3LGyE4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mDoiwLISwoG2vDwzrlNOwBmV6gzpuYH9H4Uzt7RJUDawZtQqzBMD/1uwR1oUGbzXDFM8yl64nqe7VtuiToVKCVUAxP8OepYeaNBktXfyNCfVYQZyFA7m7JTPJ4c0SmldwOAhz6LydF18nVZ39bIfwt0MpBabSUvYHpXM5LQXtlE= 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=NphNCTCr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DRi0M8Ww; arc=none smtp.client-ip=103.168.172.149 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="NphNCTCr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DRi0M8Ww" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 48A91138FCAD for ; Tue, 6 Aug 2024 05:00:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 06 Aug 2024 05:00:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934810; x=1723021210; bh=akMqEqfqyy H68qd/7gOFbzCgXhnrjiiTGmzEmrZXPhg=; b=NphNCTCrUXhg5ux7ogk5baZm2N kO7Lren4MKHT+6yLQ57pVEJbLaCgpC3zxJpPPEaA4kte5EZKN/e1dLl70Nclvcee y/wMlq6W79ltqtYz8oQdzhIbyoKaLT2c/XB6Tq+U1/E1SwatXuHLMdXFc/gAp36t bkTIRFsT6e1rvF1wZdYHEfwfWK7KA/heSIJ7+qTZ0DXOGZtE9p+QVevS55Lj4X0F jQnEZsEKh8zq6qUgg7RM04KeQ8odGjk1pEGYdMSHNwUaSXYBNCvfPelDrpNZLbHO +dalDRGs9rIu25gPpC77GrmxLvaw7NOCOYmrvgKYuffeCvqePO7NSwpwdbfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934810; x=1723021210; bh=akMqEqfqyyH68qd/7gOFbzCgXhnr jiiTGmzEmrZXPhg=; b=DRi0M8WwdKEvHIvZ1ywn7agMxla01xmO4JhlC7A8C08t 9kXsSCSJAG04MB1sWxYHI6R08Ws/RBllInQ1+Scl8l4J9EG1EPkamWXfbUcC3PRB PJuHurUA2CE5xFVvJzpPL4WERmZCi32QNjW9nUVhMF8rRo0d6odJmtG3M1Ufx8Ef bua6r6fVwkbhQHJGDnX6AbdyZseoILmDruwT2xtsibLRa0o4kspfJRRiN3Gg0+3f BqTBvz16dBsAk4cF45gB1qAy+YEp9skCdCn1FSgepm+39KwYwAALDFzD6Y773LgW 7mvJpHUxEdf0wvstK58EXAY5DPYUqIkCpB8wk3Mexg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bed1b99a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:06 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/22] submodule-config: fix leaking name enrty when traversing submodules Message-ID: <03f699cf39ebbbb2bc3ba9acaa72415efda4bbe3.1722933642.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We traverse through submodules in the tree via `tree_entry()`, passing to it a `struct name_entry` that it is supposed to populate with the tree entry's contents. We unnecessarily allocate this variable instead of passing a variable that is allocated on the stack, and the ultimately don't even free that variable. This is unnecessary and leaks memory. Convert the variable to instead be allocated on the stack to plug the memory leak. Signed-off-by: Patrick Steinhardt --- submodule-config.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/submodule-config.c b/submodule-config.c index 9b0bb0b9f4..c8f2bb2bdd 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -899,27 +899,25 @@ static void traverse_tree_submodules(struct repository *r, { struct tree_desc tree; struct submodule_tree_entry *st_entry; - struct name_entry *name_entry; + struct name_entry name_entry; char *tree_path = NULL; - name_entry = xmalloc(sizeof(*name_entry)); - fill_tree_descriptor(r, &tree, treeish_name); - while (tree_entry(&tree, name_entry)) { + while (tree_entry(&tree, &name_entry)) { if (prefix) tree_path = - mkpathdup("%s/%s", prefix, name_entry->path); + mkpathdup("%s/%s", prefix, name_entry.path); else - tree_path = xstrdup(name_entry->path); + tree_path = xstrdup(name_entry.path); - if (S_ISGITLINK(name_entry->mode) && + if (S_ISGITLINK(name_entry.mode) && is_tree_submodule_active(r, root_tree, tree_path)) { ALLOC_GROW(out->entries, out->entry_nr + 1, out->entry_alloc); st_entry = &out->entries[out->entry_nr++]; st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry)); - *st_entry->name_entry = *name_entry; + *st_entry->name_entry = name_entry; st_entry->submodule = submodule_from_path(r, root_tree, tree_path); st_entry->repo = xmalloc(sizeof(*st_entry->repo)); @@ -927,9 +925,9 @@ static void traverse_tree_submodules(struct repository *r, root_tree)) FREE_AND_NULL(st_entry->repo); - } else if (S_ISDIR(name_entry->mode)) + } else if (S_ISDIR(name_entry.mode)) traverse_tree_submodules(r, root_tree, tree_path, - &name_entry->oid, out); + &name_entry.oid, out); free(tree_path); } } From patchwork Tue Aug 6 09:00:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754579 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 CEAB01BE23B for ; Tue, 6 Aug 2024 09:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934817; cv=none; b=FhMgA6HuhsDp7jrbPesf996xV0K+p2X16Gb+GLDqd5XbcnKMe+1cWjdpg1kTkfeNhlWQmGtB+XGpE+w0JvRjh5ZosG+CRFicnffggPu+vBuQBXVtl+NCYCByAaRrbL7AGXTmsaflYqbUOFjuWin0tejy04A26xNkYJpefyw7XnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934817; c=relaxed/simple; bh=/CuDm0fMBKESj2WVUy7D76pFY++WmdGLl8waC+8ZWu8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UTcIqzuQ2RSnT1g+UCXrbheKMxX1KlRJTPlwW0azH8JfZbJI5J5zeE2oW/zJpsJQsjDq3/zQdNtqxLC2S8MoIZpKtAz45YlY8uCTQ2xowfjGiXC83XPTTbv5+8e9Xwnr2lgsVdN7ex2f9FW8HBOP8lK/n9ns3Fjkkmb8aB6c67A= 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=SOJyKR+L; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Xq7VgQYw; arc=none smtp.client-ip=103.168.172.149 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="SOJyKR+L"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Xq7VgQYw" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id 27609138FCEC for ; Tue, 6 Aug 2024 05:00:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 05:00:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934815; x=1723021215; bh=Jomw26Nr94 dVQjv0iuGByUVNSGpCfoQLGevmSXxHQkQ=; b=SOJyKR+Ltje9CmydTY2hgymKez /taSaFCAbjXRer06SRGhwxalCFF14OIBPShBWLeszYJtR17Pdwf9O5WhHqiVwV5q 97p4KYn69le1KYNA5LBHscQoeq3tj5EYVv5G4/kWRedLks6AMdvsH/GelWBMCbyF fFCfrqcD5KdFeDzNzOXuTATKmu6/L5f5ipkkZV9OV5ybsu0KTgvbc5gUog30by+o 60jvTh7ih03652q1zr38W5i3tuPQm8YOQf2WY18KOgcL1T9e3OtQwmxIikz9G4m8 BGEDHDov3PVXu64zp9bTXfcg833tqEiSIPsTb3TpUmHukY12cH5AMFpvAPYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934815; x=1723021215; bh=Jomw26Nr94dVQjv0iuGByUVNSGpC foQLGevmSXxHQkQ=; b=Xq7VgQYw4wt7l8e1slk3hiBZNa9TysTfRqdh/hDnPLrQ 8313jIwkuUZ+KUk2hhoHI6eeJY+8MLsTj6tHhPFhUeU838SHradgmzjRoktAmPAl BqFJqhF9jMHtbfAR/6/IQ6QbjOG7kOwEB4sA6lmR2lIuK0H4bBNdw0Ayg9NNPwIT hKIVQj7lqlzBmKrFqwWsjpSMn8V8aszPqKXmpCa8Gqbo3njcSkN4QBHxr5rTKP0G a5tBQs+Zuy2b0pPmtdawuFyZ1t96U2wi9vWldM8XCmGd77Zxy0MH/o2pjnSyHDpo S6J5ybUdhpPIy/mxKe+Y5COcdAdDenA9+/L8LrxUOQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:14 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a4930ed7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:11 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/22] config: fix leaking comment character 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: When the comment line character has been specified multiple times in the configuration, then `git_default_core_config()` will cause a memory leak because it unconditionally copies the string into `comment_line_str` without free'ing the previous value. In fact, it can't easily free the value in the first place because it may contain a string constant. Refactor the code so that we initialize the value with another array. This allows us to free the value in case the string is not pointing to that constant array anymore. This memory leak is being hit in t3404. As there are still other memory leaks in that file we cannot yet mark it as passing with leak checking enabled. Signed-off-by: Patrick Steinhardt --- config.c | 2 ++ environment.c | 3 ++- environment.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 6421894614..63e0211c7d 100644 --- a/config.c +++ b/config.c @@ -1596,6 +1596,8 @@ static int git_default_core_config(const char *var, const char *value, else if (value[0]) { if (strchr(value, '\n')) return error(_("%s cannot contain newline"), var); + if (comment_line_str != comment_line_str_default) + free((char *) comment_line_str); comment_line_str = xstrdup(value); auto_comment_line_char = 0; } else diff --git a/environment.c b/environment.c index 5cea2c9f54..8297c6e37b 100644 --- a/environment.c +++ b/environment.c @@ -113,7 +113,8 @@ int protect_ntfs = PROTECT_NTFS_DEFAULT; * The character that begins a commented line in user-editable file * that is subject to stripspace. */ -const char *comment_line_str = "#"; +const char comment_line_str_default[] = "#"; +const char *comment_line_str = comment_line_str_default; int auto_comment_line_char; /* Parallel index stat data preload? */ diff --git a/environment.h b/environment.h index e9f01d4d11..5e5d9a8045 100644 --- a/environment.h +++ b/environment.h @@ -8,6 +8,7 @@ struct strvec; * The character that begins a commented line in user-editable file * that is subject to stripspace. */ +extern const char comment_line_str_default[]; extern const char *comment_line_str; extern int auto_comment_line_char; From patchwork Tue Aug 6 09:00:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754580 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 D01A91BE23B for ; Tue, 6 Aug 2024 09:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934821; cv=none; b=cdoPFsQSV7HPA5okaop9m1kTGQ6vD86gf0brX8V0kTpnEpadECuSFWoRd/3TVtaolJU7Bq02iQGDntl4m+DgCXP1jvPY0J3I6LgkdauLoT6Da9Aud8NrJnlxEx91HbWjGH4jb3DLRDWdTem00MtTk0qrDbQ8FCVeLLqtDHAx/LE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934821; c=relaxed/simple; bh=RQRXrqpERnAif0kCcipd8LxXZj1eE1n1uzNB7UK5Eq8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E4pQFhYyUvSRh5Uro9E96Tsw0U/puwjOmPUp7IwbtNaBkJ7rCAlSq+QZQ1z5ehW/kIzbVxQq9NxmDMUUqyKstToGTvtlPX+Xy86yNodx2QU06GTOLj3afC+x7wzikwuB3P1iRKbw7NM9qq1fKVeJsQUc4+jHUQ7RObOmosBRpD8= 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=Ae0t0ZIo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ml466H41; arc=none smtp.client-ip=103.168.172.154 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="Ae0t0ZIo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ml466H41" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E71141151B2B for ; Tue, 6 Aug 2024 05:00:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 06 Aug 2024 05:00:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934818; x=1723021218; bh=/PJWPFn/g6 nEx0KDyCPtpwNhTmFlt4rK976wqaN6fd4=; b=Ae0t0ZIo4UKcye2mWsJYDY2SwU sZgANoZ98+AoOo5QTQ1+Vg9sS2J7n3KmyyKxKJwlezVQsTAU3xJdQ+SHYeOjTYzq E1QsnYeVpuhS+HlZEDjadUSzwkK0rpwzM9tm9ImIPXKgGDfSjhWTpqEhwXrkH2GA wAOY37OvK444brBjeaND0vX+NvpU3qwsvjb5AxDJeYCHI4j8Oq6qsyoFMSUZPfUu VRI0j3Bj1NMTT/7Ld+CbEK/M9hrS/ddZzkSgPqBB7Ar1ibAAVOTV5kvrB7By/cnr DoKZ3URxECOjCUFCPM6SQf47jNrx1JhzZlTWMv3Lg0b6KRbgCVCg8ewEeWIg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934818; x=1723021218; bh=/PJWPFn/g6nEx0KDyCPtpwNhTmFl t4rK976wqaN6fd4=; b=ml466H41Iiye1w6dZwnHQC+3Vcky0xXeOsE5wd/vP+tO T8pu9To8kONrEWvATKIQDtp7cP5r8bY8ehNqXiMKsfjQugxREvLlmqC8n32ddM5O Bs/8dfW5qE//tl45qM6TLuXgxOS5yRuUoIwCgFi6YxMN73+JetImfOecL5Tgu+fy 9fxZ7QaY8Yzh/vcTxynt5c3IjCXzZszOQaQokc21GQuLVJn51ChbhZbMAqhjjpdo DNMhhLaaJ9xoHA/h81fy633JMOrJj2bYbWfRmNJiH3tIu3CTw2RpeHW7OoCETThM 0Kj9BoOwsNF2Bk4QC5b6kmyW8/VXyGBjWouGsSTyAg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f7cb2d13 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:16 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/22] builtin/rebase: fix leaking `commit.gpgsign` value Message-ID: <05290fc1f14cae8229c42f2d0aafe6619c069e3a.1722933642.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 `get_replay_opts()`, we unconditionally override the `gpg_sign` field that already got populated by `sequencer_init_config()` in case the user has "commit.gpgsign" set in their config. It is kind of dubious whether this is the correct thing to do or a bug. What is clear though is that this creates a memory leak. Let's mark this assignment with a TODO comment to figure out whether this needs to be fixed or not. Meanwhile though, let's plug the memory leak. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 8 ++++++++ sequencer.c | 1 + t/t3404-rebase-interactive.sh | 1 + t/t3435-rebase-gpg-sign.sh | 1 + t/t7030-verify-tag.sh | 1 + 5 files changed, 12 insertions(+) diff --git a/builtin/rebase.c b/builtin/rebase.c index e3a8e74cfc..f65316a023 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -186,7 +186,15 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.committer_date_is_author_date = opts->committer_date_is_author_date; replay.ignore_date = opts->ignore_date; + + /* + * TODO: Is it really intentional that we unconditionally override + * `replay.gpg_sign` even if it has already been initialized via the + * configuration? + */ + free(replay.gpg_sign); replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); + replay.reflog_action = xstrdup(opts->reflog_action); if (opts->strategy) replay.strategy = xstrdup_or_null(opts->strategy); diff --git a/sequencer.c b/sequencer.c index 0291920f0b..cade9b0ca8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -303,6 +303,7 @@ static int git_sequencer_config(const char *k, const char *v, } if (!strcmp(k, "commit.gpgsign")) { + free(opts->gpg_sign); opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL; return 0; } diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index f92baad138..f171af3061 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -26,6 +26,7 @@ Initial setup: touch file "conflict". ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3435-rebase-gpg-sign.sh b/t/t3435-rebase-gpg-sign.sh index 6aa2aeb628..6e329fea7c 100755 --- a/t/t3435-rebase-gpg-sign.sh +++ b/t/t3435-rebase-gpg-sign.sh @@ -8,6 +8,7 @@ test_description='test rebase --[no-]gpg-sign' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-rebase.sh" . "$TEST_DIRECTORY/lib-gpg.sh" diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh index 6f526c37c2..effa826744 100755 --- a/t/t7030-verify-tag.sh +++ b/t/t7030-verify-tag.sh @@ -4,6 +4,7 @@ test_description='signed tag tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" From patchwork Tue Aug 6 09:00:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754581 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 706691BE250 for ; Tue, 6 Aug 2024 09:00:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934825; cv=none; b=TmLFw7J+080Tnkhn2+hzJnNinwQlX8vAZnKx/Nkld9R3F9qosraPRXiYMkFY4dX/8lOWpMHs1DUMcRRPhiEOKRpx95RU6075TBIYJ5NQ6CCglUZZv4y1rztYbAmHS2nYo5zKo8C/eLJqos8d8E7VOCtOEsfJFyjRhI3M3Qu5NRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934825; c=relaxed/simple; bh=Uma7j2iW77+YOunJ85U16KGJcFwWCqFol3Fy1hNWbYA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jDux2g73VYSBf248bZ1i/a9iGqtjUN+sZRmmKDO7UoxF3AYGUYE7c6+Y6IfvXKLsYLsmQhYJwEeFa91Ri2oits7IAMe20ApdrwUdK6llC3sxQDGEKQmk1c9RE58nxAyDjPaU4plAfK/paXgWbqeNQk2TbBaZTmlgee2jaBFEn5g= 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=VE7e66Eq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KIiIClV5; arc=none smtp.client-ip=103.168.172.149 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="VE7e66Eq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KIiIClV5" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id BB3E2138FCB9 for ; Tue, 6 Aug 2024 05:00:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 05:00:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934823; x=1723021223; bh=917GmYz5Ml f2BhUea/ZPfAZa3Hes4ea4dK2D+MvQES4=; b=VE7e66Eqpw4mQeVhf4PedZ9+n8 qwQYsocqzexbp657Ie1qIOB1M+fVkOs5PribIl8ONWDLcOs6Tdi01IHQhWAVXHMF MYCsVPfscMGXhnuB/+P0M89XtpYuZhWuGXfRYGt688hEG4uRN+H0uacBe8Xl7W8A 5gN+g/lmahuOY/j6+QD4OSpIX+p6+jXo0uwKWOOy7tDDd3TVBv2hXeM780WwM61A jt7oHP1i267/FGjLNkIa91fAPJaJIikVKJWxXlElvtB5TId3A/o9X6/Ddei9CyyU GXZjJRlYsO+ajIibUL3KOmG96XOd8HTqIJoRn035pcgqYbFJlDNiF1N9MMxQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934823; x=1723021223; bh=917GmYz5Mlf2BhUea/ZPfAZa3Hes 4ea4dK2D+MvQES4=; b=KIiIClV57o6Gs2xyjcPWRdJoGsN0M+dUmfPRETuwLPJA SPzLwAqO4FXwFUlfY+EbEqLyU3XoonkmEIa3gidqhPp+wM8L0LTYGejfNIAijpHe 7elbQSrV9VhWzalyHG0J9ob9xCQeW9Olf6UE0u38vR3og/0SMRL+9LrTJmEFh5a2 KPqX1S2L2y8ZnitjMKFVjkUtVg2DYJcueqt8Mb0QbG7+qKDrtMxm3N98zJSZC3K0 INle/KumXhK/Ff5nVxZTDimcrxfSfDPfuVVIdnpIGlzgq6uU1FM2JgjdsCy8OF/L 7BjDgL/M1Ty6bcx1XBvkRbQ6YDiJ8CtceCOPBcWYRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:23 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d9dd962d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:20 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/22] builtin/notes: fix leaking `struct notes_tree` when merging notes Message-ID: <4f5d49007484e8c201f62f84ffec101da00548ae.1722933642.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 allocate a `struct notes_tree` in `merge_commit()` which we then initialize via `init_notes()`. It's not really necessary to allocate the structure though given that we never pass ownership to the caller. Furthermore, the allocation leads to a memory leak because despite its name, `free_notes()` doesn't free the `notes_tree` but only clears it. Fix this issue by converting the code to use an on-stack variable. Signed-off-by: Patrick Steinhardt --- builtin/notes.c | 9 ++++----- t/t3310-notes-merge-manual-resolve.sh | 1 + t/t3311-notes-merge-fanout.sh | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index d9c356e354..81cbaeec6b 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -807,7 +807,7 @@ static int merge_commit(struct notes_merge_options *o) { struct strbuf msg = STRBUF_INIT; struct object_id oid, parent_oid; - struct notes_tree *t; + struct notes_tree t = {0}; struct commit *partial; struct pretty_print_context pretty_ctx; void *local_ref_to_free; @@ -830,8 +830,7 @@ static int merge_commit(struct notes_merge_options *o) else oidclr(&parent_oid, the_repository->hash_algo); - CALLOC_ARRAY(t, 1); - init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); + init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); o->local_ref = local_ref_to_free = refs_resolve_refdup(get_main_ref_store(the_repository), @@ -839,7 +838,7 @@ static int merge_commit(struct notes_merge_options *o) if (!o->local_ref) die(_("failed to resolve NOTES_MERGE_REF")); - if (notes_merge_commit(o, t, partial, &oid)) + if (notes_merge_commit(o, &t, partial, &oid)) die(_("failed to finalize notes merge")); /* Reuse existing commit message in reflog message */ @@ -853,7 +852,7 @@ static int merge_commit(struct notes_merge_options *o) is_null_oid(&parent_oid) ? NULL : &parent_oid, 0, UPDATE_REFS_DIE_ON_ERR); - free_notes(t); + free_notes(&t); strbuf_release(&msg); ret = merge_abort(o); free(local_ref_to_free); diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh index 597df5ebc0..04866b89be 100755 --- a/t/t3310-notes-merge-manual-resolve.sh +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -5,6 +5,7 @@ test_description='Test notes merging with manual conflict resolution' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Set up a notes merge scenario with different kinds of conflicts diff --git a/t/t3311-notes-merge-fanout.sh b/t/t3311-notes-merge-fanout.sh index 5b675417e9..ce4144db0f 100755 --- a/t/t3311-notes-merge-fanout.sh +++ b/t/t3311-notes-merge-fanout.sh @@ -5,6 +5,7 @@ test_description='Test notes merging at various fanout levels' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh verify_notes () { From patchwork Tue Aug 6 09:00:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754582 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 384041BE25A for ; Tue, 6 Aug 2024 09:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934830; cv=none; b=YO0uPPN1nqlHSzQhkmy4u7XJv7fkCpx0uFpcIg2jp3fVxdnsXCL9zDwq2svgoswBD7+8Z+DkEC8JFEbMMKhr4497yMACkGMgYa+EjdK78JZS+dzaqPDPSZ1m+EPACQlAV45KJzPSkfcqawjop6+KQHbY+FMnxG1BqIcV/gFajzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934830; c=relaxed/simple; bh=SFw2Lg+tF31XpzMyYmsibU+95n9RSrl9WfPeKUj/yXo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nhVVSSH21y7CDxW72b83SwYpDuwEPaSQqBW2Kpf7X/b0nyrK5WdIL7E/9zDh8t/hmtzNObguWLwlZPOHKn8pp1cspIYGApq0a799bJojhrTcgSZ0bZIIi/oSt16wQvYOr+Uzw9ca7fav/xCXy058AgKDEWurBnrhSYDBR/j+eEA= 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=N+M9n8A/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SOrk/ika; arc=none smtp.client-ip=103.168.172.149 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="N+M9n8A/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SOrk/ika" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 8F9CA138FCEC for ; Tue, 6 Aug 2024 05:00:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Aug 2024 05:00:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934828; x=1723021228; bh=/IZQyuUT8t wv1esv5tr0ZkVdZGUo4d6U/9KU/lUaEAU=; b=N+M9n8A/TiYrGA2S18JwBP7LvX DG9sVm4WasQnf0ZmqD1Fp+/O9dk0JltpVtAkMZz81feIRNii+OA2IDaieE5bLYiT BZXr11q+ZkghbaHg3ElV8yq+qwo/oypZ5LmBGsq4iOuadTKOgLirPj9NDfSKBBjO C2YM4YLsWzggVFlW0UKFMTmYo8NgUrKch9agVCZqG9AhyCydpFpxZb3+zUlkpAu3 CgDodwOG3Vom7n41w6fka+cwjj4UavG/3yYj6dACwunndZc9sbNgZVezjvGRfR92 8lChoz01nVai6e5TM6WgthgeVDeB4yj1K9VvbCXiJm2u4739+/3/2yyLaspA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934828; x=1723021228; bh=/IZQyuUT8twv1esv5tr0ZkVdZGUo 4d6U/9KU/lUaEAU=; b=SOrk/ikajdR/v8J736rYcnHhAb8yp089VlWJ9yX2aHVw 0GWqwNMReBUsXQPxprA+3u8Ym/xjgbz5Xl4s39OuXdwrmcUMx/nRdmHH9fOlWNeI LpLgdZ+SqKMQyJ1etR/MFME5eZ7LIXu7xByVeyvYlMcSRO7cEIgEJap3lYm78qze fxPy/mMyUly5eiF8nWLDOWu9cn55K7Q+NvPouarlghiQwMGnjK88xvYhEkc7qAF8 wJeexEivXkH6b7Mtp+kcDCStM6rlcuJ6XTPq5E0KlK4wvqdgj82bf6hI4o4pbILx HiRvS7Sk5VE1MlUnHZiVje9Gh8qNUe/w3nshRy1bGQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f97f2203 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:25 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/22] builtin/fast-import: plug trivial memory leaks Message-ID: <798b911f775a8d565f5c05605e257071d9f8a00a.1722933642.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: Plug some trivial memory leaks in git-fast-import(1). Signed-off-by: Patrick Steinhardt --- builtin/fast-import.c | 8 ++++++-- t/t9300-fast-import.sh | 1 + t/t9304-fast-import-marks.sh | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index d21c4053a7..6dfeb01665 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -206,8 +206,8 @@ static unsigned int object_entry_alloc = 5000; static struct object_entry_pool *blocks; static struct hashmap object_table; static struct mark_set *marks; -static const char *export_marks_file; -static const char *import_marks_file; +static char *export_marks_file; +static char *import_marks_file; static int import_marks_file_from_stream; static int import_marks_file_ignore_missing; static int import_marks_file_done; @@ -3274,6 +3274,7 @@ static void option_import_marks(const char *marks, read_marks(); } + free(import_marks_file); import_marks_file = make_fast_import_path(marks); import_marks_file_from_stream = from_stream; import_marks_file_ignore_missing = ignore_missing; @@ -3316,6 +3317,7 @@ static void option_active_branches(const char *branches) static void option_export_marks(const char *marks) { + free(export_marks_file); export_marks_file = make_fast_import_path(marks); } @@ -3357,6 +3359,8 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list) free(f); string_list_insert(list, s)->util = ms; + + free(s); } static int parse_one_option(const char *option) diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 1e68426852..3b3c371740 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -7,6 +7,7 @@ test_description='test git fast-import utility' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash diff --git a/t/t9304-fast-import-marks.sh b/t/t9304-fast-import-marks.sh index 410a871c52..1f776a80f3 100755 --- a/t/t9304-fast-import-marks.sh +++ b/t/t9304-fast-import-marks.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test exotic situations with marks' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup dump of basic history' ' From patchwork Tue Aug 6 09:00:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754583 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 3E8C51BE853 for ; Tue, 6 Aug 2024 09:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934835; cv=none; b=G4w6TJFzs2gx0wBsgo08jgK3f1OwaEjudb4BIUvfHzEFWTOCQVCEateE7FqIs/AGkfBQR6R+7OMOGQjZG3VaY6Uat12kIjf482wzwhTUV/1RFtgyUZsaS8tSAyu/NSzVUVNVqNIoT4ZTrbcDnhQLm3ARnr1tBxfpD/kZcMZJnmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934835; c=relaxed/simple; bh=JTdSLCgQ//ks1dpUuOslSZA1e03m4el1V90HTW/48hY=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iw4yqcNahu41g1WvKVd6aEvDulFPTmqRpN+z6YWnYe73llD39t2Tc1cLjXdD5HYjKbAlSLAy5a/IDgo/9b7d6g3aI2n6RVthXp11mJwPMc1PHCH/I50124CzPV7AuCyDbiotW2tYAbb/8wKPLkhlHTg800OODzAovMxWKe4N0jM= 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=b10l00y2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PAK9Adyn; arc=none smtp.client-ip=103.168.172.149 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="b10l00y2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PAK9Adyn" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 6A405138FCE9 for ; Tue, 6 Aug 2024 05:00:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 06 Aug 2024 05:00:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934833; x=1723021233; bh=m5CHUumm0g uyk1sSBkis4+zw6/KlvQxZ1fJTE5lI1dY=; b=b10l00y2kOkhEE7G2kHaZWU5Qo yoqtH1G6YnawNgerYIbOH7+YJbJinCUsB04M5eH04Z8DUEsFF6+Hb1KBNRT+Sn+J gCDKFtHGhShFWp3GT8jbucHzEsoX2ZW16EhX7UI8wThM4SBWVrzVxQz8YRRf6Pmt fKb9XpKcs2NQWh3g0QOpJvugiFGCQxD96f3gGhF4J8m/kReI/gIs2Ms21G15pVsQ OjpKURGtxWiq8pMDkC0MrcDW28pzsHlOFe9p9/0e0cN7JedejSMjFSiG7UMJy4EK UvJ9nkWCb9Jx49Wr0Wms5PMAdtGM2YuK0n3JELoqas5Fg0RCTLpDgMoC2SXw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934833; x=1723021233; bh=m5CHUumm0guyk1sSBkis4+zw6/Kl vQxZ1fJTE5lI1dY=; b=PAK9AdynVmlr46OoWk9R+eDpO0fc2Hz051cVQMLjgIm7 ErERUrquN7mBNk5oyjbeTrb/X6V10AqhW/KhoitXmiyRj8pIGDAv7ZMcYhlNILyG SX4aeLdDs6uYZL9/BNrLJ8rJSKejZ0wLb5SLuQ9xMCNQEhU6IdB7X3NwmLHqaGj+ tk9jwFd767JfIFv7Um6KaR9syF6+g0Euw5/Zljuvdkj19E3Pu+ZeJQ6jyjk2BwKE qxwlcHiVhU6PGZ/QOdDBFgU1BQoglBd49LQ42dEsx3yuMKOhURcQL3C6Lm4Q0bEz qh7pDdgPVUjtY5XEiBzgB8PmqU1psANkM3nOgjNisQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeeiiefhtedukefhieeukeejueeivdekudfhfe elhedvfeetgedtfeevgfeutdetfeenucffohhmrghinhepughifhhfohhpthdrnhhonecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimhdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7648cb3d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:30 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/22] builtin/fast-export: fix leaking diff options Message-ID: <660732d29df8be6253f205fbbad2cdcafb0a0bbd.1722933642.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: Before caling `handle_commit()` in a loop, we set `diffopt.no_free` such that its contents aren't getting freed inside of `handle_commit()`. We never unset that flag though, which means that it'll ultimately leak when calling `release_revisions()`. Fix this by unsetting the flag after the loop. Signed-off-by: Patrick Steinhardt --- builtin/fast-export.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 4b6e8c6832..fe92d2436c 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -1278,9 +1278,11 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) revs.diffopt.format_callback = show_filemodify; revs.diffopt.format_callback_data = &paths_of_changed_objects; revs.diffopt.flags.recursive = 1; + revs.diffopt.no_free = 1; while ((commit = get_revision(&revs))) handle_commit(commit, &revs, &paths_of_changed_objects); + revs.diffopt.no_free = 0; handle_tags_and_duplicates(&extra_refs); handle_tags_and_duplicates(&tag_refs); From patchwork Tue Aug 6 09:00: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: 13754584 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 E815D1BE867 for ; Tue, 6 Aug 2024 09:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934840; cv=none; b=IRCbqj60x04wgKi/151mds8YVrFngt2U0HQagEdhd5eBnO+6zp7eieXkVhdw8N+Curze7Je8ufCM4guRjDRE2c1S50TApaBX8Id2Ulq3/40WvZr7awvNOiltrVIinvNRvoT5vnW9fgqoPJxeGIiUWrG/H9dB4wcEbLXFH4RcpHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934840; c=relaxed/simple; bh=MVaAzJOgESC+nGmqLRLYtbs25qcNwR4AKLy54dyZqkM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SF+UAs84apBahy/Bihzzwx8O1PSSRkQYkMHPglJi0jLAOXeQEmeH5AdffJuMJ7Q6uo2d0MsIFcrp+dZAEnrXwenZ4b6Mc0baawbfnoTn/1FagWx8VF+mNn87oIaXCaiMZig/bc0B/dIf95lfq/Xc/bpzZkVgTxWIfnEdNTMd4jc= 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=qEcTEyp4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Tg8B8FoC; arc=none smtp.client-ip=103.168.172.154 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="qEcTEyp4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Tg8B8FoC" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 492971151B52 for ; Tue, 6 Aug 2024 05:00:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 06 Aug 2024 05:00:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934838; x=1723021238; bh=fE1gftK/xM 5FqlBk6hc8IXFYw5cK4AOgE+njagGsHKU=; b=qEcTEyp4zvHCKcFmUk1Sc7K0ym dYguatRvOARUhgXAdq3a3rBPAzFQkwzmL3NGp5BZ2on3CnUhOS6WfVv+4nFjtQ5a S/ilXUofPgA5k0hSS5+0rroQHKVxmNN9txsB1ScjIl9i7ucn1RQvxjW6huJ3xIgG LO5jUqSKZ1UvEuOWuY5u3IQSCRdbFebvs+xZ1fPpelLGAAa7RCyHNfXdrrxyrVWu dHQKAY3yvDdrpEpQUeOsDLS9kbNqYEFQRy0XwViQPZgpMutjZyHSnXuibjaVrw4a JDGorxj1FoWHsYfvnEqdxGcT/FRM1K9ippRV5bdrwyzbz9VsA/HZ2yJPbLvg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934838; x=1723021238; bh=fE1gftK/xM5FqlBk6hc8IXFYw5cK 4AOgE+njagGsHKU=; b=Tg8B8FoCjOkNWRDm+mkzGXubRzD5AG9ma8Bgj8ipwP8N 2FtxIgJlcGYu8ZPhVOU2IZvuQe50/eGUDDrDKsnJqeBnbZi1y7sfaJ1BmpDBPyBQ 8GlmgKBPdKK/G39sJ4ICW4PjDP5HMHcGWpBCYbzhQralUp7T/nWWygn04z2xY9Px 9Jb4BVzSyQdqn0v8k2Zu2KP5JSRjOI26dek5SuhKEHqV0GdCitDq6vxq501OiZq9 Rtzt5GYwfr46utX/7RH+h4zp/VCuM343KJ5xkACHsKqy6TbX5n/Rigv/C2x21+hF jqZIxnUK4U1WykJUQuvFSvXheg55E0PJrjhHi59nTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 62f3e5b0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:35 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 13/22] builtin/fast-export: plug leaking tag names Message-ID: <64366155dee25209ab9c434016c5918d47d7e1d5.1722933642.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 resolving revisions in `get_tags_and_duplicates()`, we only partially manage the lifetime of `full_name`. In fact, managing its lifetime properly is almost impossible because we put direct pointers to that variable into multiple lists without duplicating the string. The consequence is that these strings will ultimately leak. Refactor the code to make the lists we put those names into duplicate the memory. This allows us to properly free the string as required and thus plugs the memory leak. While this requires us to allocate more data overall, it shouldn't be all that bad given that the number of allocations corresponds with the number of command line parameters, which typically aren't all that many. Signed-off-by: Patrick Steinhardt --- builtin/fast-export.c | 17 ++++++++++++----- t/t9351-fast-export-anonymize.sh | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index fe92d2436c..f253b79322 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -42,8 +42,8 @@ static int full_tree; static int reference_excluded_commits; static int show_original_ids; static int mark_tags; -static struct string_list extra_refs = STRING_LIST_INIT_NODUP; -static struct string_list tag_refs = STRING_LIST_INIT_NODUP; +static struct string_list extra_refs = STRING_LIST_INIT_DUP; +static struct string_list tag_refs = STRING_LIST_INIT_DUP; static struct refspec refspecs = REFSPEC_INIT_FETCH; static int anonymize; static struct hashmap anonymized_seeds; @@ -901,7 +901,7 @@ static void handle_tag(const char *name, struct tag *tag) free(buf); } -static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name) +static struct commit *get_commit(struct rev_cmdline_entry *e, const char *full_name) { switch (e->item->type) { case OBJ_COMMIT: @@ -932,14 +932,16 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) struct rev_cmdline_entry *e = info->rev + i; struct object_id oid; struct commit *commit; - char *full_name; + char *full_name = NULL; if (e->flags & UNINTERESTING) continue; if (repo_dwim_ref(the_repository, e->name, strlen(e->name), - &oid, &full_name, 0) != 1) + &oid, &full_name, 0) != 1) { + free(full_name); continue; + } if (refspecs.nr) { char *private; @@ -955,6 +957,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) warning("%s: Unexpected object of type %s, skipping.", e->name, type_name(e->item->type)); + free(full_name); continue; } @@ -963,10 +966,12 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) break; case OBJ_BLOB: export_blob(&commit->object.oid); + free(full_name); continue; default: /* OBJ_TAG (nested tags) is already handled */ warning("Tag points to object of unexpected type %s, skipping.", type_name(commit->object.type)); + free(full_name); continue; } @@ -979,6 +984,8 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (!*revision_sources_at(&revision_sources, commit)) *revision_sources_at(&revision_sources, commit) = full_name; + else + free(full_name); } string_list_sort(&extra_refs); diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh index 156a647484..c0d9d7be75 100755 --- a/t/t9351-fast-export-anonymize.sh +++ b/t/t9351-fast-export-anonymize.sh @@ -4,6 +4,7 @@ test_description='basic tests for fast-export --anonymize' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup simple repo' ' From patchwork Tue Aug 6 09:00: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: 13754585 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 DE85B1BF305 for ; Tue, 6 Aug 2024 09:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934845; cv=none; b=I+q48Gax50zRnjif63ril7fQf0antJn8opXdw3atF4ek4Q2lCbt0Zac0GxJlsKbn5CeVHFJ1ND/PR3W4h9hkZUt7bOWzv7zbxu9UX3r1IZaRAvPkvG6StxaZM5cQVaNMdw+7G4FIyu7eGciSX/hCK5zQuMEY2Y/YbWhhfK1GRYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934845; c=relaxed/simple; bh=ak2R/qyznL2jU9m543xsmPd9GUWv0m8JbKoezK1ueqk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ujBal5s9OI0PqLhU7M7qF/Gmo5fVB5qVGSg2VVjl8QWrItYQg07EfoSEWOmf0t1a68OYTByGqrfgJEH2hHe/2Lxm5E03NVO+BexOLTe4di5/MxDalahyuSMzdYOnqC3QXLQ/AecA2sZ/6ocGJ4h38Py/meNfTAyvqrlxvnd1NSw= 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=RxdvvHHH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WRp5QnHF; arc=none smtp.client-ip=103.168.172.149 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="RxdvvHHH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WRp5QnHF" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id 294AF138FCB9 for ; Tue, 6 Aug 2024 05:00:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 05:00:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934843; x=1723021243; bh=QNJ1ZBJn8v n+qGL9nXmsoWfnYR49HOpLLRz1pw5XMfs=; b=RxdvvHHH+T7/iIfUmLGACjVv7w b4qyQgcwohJR06SqJG3WGWhxSLA7VQh3qskX8Y0/DxsEZVBZoLj46ZYsPLCteVfp 61KZrxtFU6/Bb4oMpvz5RIh6SPmhbb6ZwFcvY4aIU1LvWr7prh8Qw4HcNcV5X73Q WC6GtmUCit6GJyKhfbT1xszlO0pek94SzBuHQWatrB3hkyJ+DyBeppLLyakFwGEK MVUnnhXM+lYKKexkgQKZpYSFRZW/82ky04OR8YXw0b42GDqPfMPq/Ysm50IQK737 u7wZj93fQIhz/sGr21d0x47arc7ykIP+DVpcWwZ7TUFBYjRgKq7teQEsQv4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934843; x=1723021243; bh=QNJ1ZBJn8vn+qGL9nXmsoWfnYR49 HOpLLRz1pw5XMfs=; b=WRp5QnHFRZ99b6fJ0V7CtEfytjZA7mKgF80cN+hK+Vlz uF/AvK0aeY4VntgC0fGZjCpS7j/YBWJFCKahtyCc24iBGkbSOSYJg/FgIlBnxiKF Bo7iSk+ybDP8LfO2p7xJKrXgvyMdKZ03fR42iZcqViB+OzW4Z6E5BCHj1rApySRa MhJPmf4cz4BknhTM8DlRvbC06qkIySktb767J6pM5fVYJbQB0semj0iqYH7uF4Ha oZZBb8ahmsAqSYgeRK7dXeDsYTwtQr88o1SPtc4NdPvtRTHvOqCBKTzpqHFtgJxe rC+EyAImwhJ/0B7FYZRgFumK+geXz3psOdYPvzCJVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:42 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 72718d15 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:40 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 14/22] merge-ort: unconditionally release attributes index 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 conditionally release the index used for reading gitattributes in merge-ort based on whether or the index has been populated. This check uses `cache_nr` as a condition. This isn't sufficient though, as the variable may be zero even when some other parts of the index have been populated. This leads to memory leaks when sparse checkouts are in use, as we may not end up releasing the sparse checkout patterns. Fix this issue by unconditionally releasing the index. Signed-off-by: Patrick Steinhardt --- merge-ort.c | 3 +-- t/t3507-cherry-pick-conflict.sh | 1 + t/t6421-merge-partial-clone.sh | 1 + t/t6428-merge-conflicts-sparse.sh | 1 + t/t7817-grep-sparse-checkout.sh | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index e9d01ac7f7..3752c7e595 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -689,8 +689,7 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti, */ strmap_clear_func(&opti->conflicted, 0); - if (opti->attr_index.cache_nr) /* true iff opt->renormalize */ - discard_index(&opti->attr_index); + discard_index(&opti->attr_index); /* Free memory used by various renames maps */ for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) { diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index f3947b400a..10e9c91dbb 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -13,6 +13,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh pristine_detach () { diff --git a/t/t6421-merge-partial-clone.sh b/t/t6421-merge-partial-clone.sh index 711b709e75..020375c805 100755 --- a/t/t6421-merge-partial-clone.sh +++ b/t/t6421-merge-partial-clone.sh @@ -26,6 +26,7 @@ test_description="limiting blob downloads when merging with partial clones" # underscore notation is to differentiate different # files that might be renamed into each other's paths.) +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh diff --git a/t/t6428-merge-conflicts-sparse.sh b/t/t6428-merge-conflicts-sparse.sh index 9919c3fa7c..8a79bc2e92 100755 --- a/t/t6428-merge-conflicts-sparse.sh +++ b/t/t6428-merge-conflicts-sparse.sh @@ -22,6 +22,7 @@ test_description="merge cases" # underscore notation is to differentiate different # files that might be renamed into each other's paths.) +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh index eb59564565..0ba7817fb7 100755 --- a/t/t7817-grep-sparse-checkout.sh +++ b/t/t7817-grep-sparse-checkout.sh @@ -33,6 +33,7 @@ should leave the following structure in the working tree: But note that sub2 should have the SKIP_WORKTREE bit set. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Tue Aug 6 09:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754586 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 D66DF1BE854 for ; Tue, 6 Aug 2024 09:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934850; cv=none; b=LXxphcL1dw/1PYldGcPj3x0rX+BoMCnjQaP0pleJSRBp8QhaNPj5LNk/4pdqRf3f76qAGH0nKqIjn8ckJqGcY5852RRM6wEGsBViZvt+E1F2HrbKGsh51fuNLbVkxoh6opsmOiplKDTZZVWDjxKkG1Mfx7W3L2FlVl+pY4zx4Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934850; c=relaxed/simple; bh=nzk2RiS8u1qBsN5nCPOxYjvyQtSvOskr4XfYrizsUeI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sf8oJz3NSm+/3Q2DTksV7j0JPfWdUYdyA/xA157SlsN9AlwvpjhpfzXXGG3hHLyVJi4nF9BsHNm0fl0j4WPxCnhK5OpI5kOO3YJGAjr5u0GOirO6dkDwOhCw2sdl+opMZ+vRFszvinTovp51/PowtIDvOyjea1emns8fxmpRvjM= 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=irV2ywdZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Hoi5fRsp; arc=none smtp.client-ip=103.168.172.149 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="irV2ywdZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Hoi5fRsp" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 085EE138FCDD for ; Tue, 6 Aug 2024 05:00:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Aug 2024 05:00:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934848; x=1723021248; bh=Eq0cyJuu8U vIyB9X8wceYMJ3HCI8dHkzygZhagXyonI=; b=irV2ywdZI3Z+LVrtxXDHoSHOYg cZ2qllluwPuuUliDqT51QmYanKi9cQHOIn3E3KrQ8xk7Nr+OMXDWOusEdQUyYEtF QLsVe+hh1f6WimZvTzJuH/Sn6vOFp+kPS+pMRYoglHybhB9dA9+19bGRFjr/f7uz buuO0ucr3oxz6f+3KL/OwSLXLMwA7BIdoQtqZtZPZC/NvmmH+lOMtxss72GkAPCB KUnisY6YD8gpDVs47JGGCJscgpfRhviVF7+1ooZ7ElL4m+nW/SVafCK3d72wzDQz Pj/Bqxc1xtfeo9dodkgpbkJRfR6QSmXltNZSqNjaa4lp5ll4mPh3l1NCRJEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934848; x=1723021248; bh=Eq0cyJuu8UvIyB9X8wceYMJ3HCI8 dHkzygZhagXyonI=; b=Hoi5fRspVyUsmZZKR2E9TJQcUDNj4zUMYJZuAIdwRTtU 3/4NfJVpX0Mh6LLs1QZ/siCzZNt9V6GRRMisWLdogUM3wWwMjBhsS6DDeuF7X4so MJk1AkUDj91wja6/Qu4gvSK/7s/kPmlltun16hdDKy+BXOqxYcLo2uXo0AxFuBDr iwaEbkXxFAXM9gqJQE+LTDI+ECieNRtHrcRFnkxiCOWAFFy9Ti3nSOOrmRSg3S2s bGsPgv0VgvaIFJP4Kzwa8lGnMFxvp2nOWEIJaQnV0QKDpqsAsROSvB+mD+UkVEMO HNTNWF3eGzYi4Wudg0keP0hTpfLmQ61/qoVr1ida/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:47 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8342e974 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:44 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 15/22] sequencer: release todo list on error paths Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're not releasing the `todo_list` in `sequencer_pick_revisions()` when hitting an error path. Restructure the function to have a common exit path such that we can easily clean up the list and thus plug this memory leak. Signed-off-by: Patrick Steinhardt --- sequencer.c | 64 +++++++++++++++++++++++---------- t/t3510-cherry-pick-sequence.sh | 1 + 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/sequencer.c b/sequencer.c index cade9b0ca8..fec3c5e846 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5490,8 +5490,10 @@ int sequencer_pick_revisions(struct repository *r, int i, res; assert(opts->revs); - if (read_and_refresh_cache(r, opts)) - return -1; + if (read_and_refresh_cache(r, opts)) { + res = -1; + goto out; + } for (i = 0; i < opts->revs->pending.nr; i++) { struct object_id oid; @@ -5506,11 +5508,14 @@ int sequencer_pick_revisions(struct repository *r, enum object_type type = oid_object_info(r, &oid, NULL); - return error(_("%s: can't cherry-pick a %s"), + res = error(_("%s: can't cherry-pick a %s"), name, type_name(type)); + goto out; } - } else - return error(_("%s: bad revision"), name); + } else { + res = error(_("%s: bad revision"), name); + goto out; + } } /* @@ -5525,14 +5530,23 @@ int sequencer_pick_revisions(struct repository *r, opts->revs->no_walk && !opts->revs->cmdline.rev->flags) { struct commit *cmit; - if (prepare_revision_walk(opts->revs)) - return error(_("revision walk setup failed")); + + if (prepare_revision_walk(opts->revs)) { + res = error(_("revision walk setup failed")); + goto out; + } + cmit = get_revision(opts->revs); - if (!cmit) - return error(_("empty commit set passed")); + if (!cmit) { + res = error(_("empty commit set passed")); + goto out; + } + if (get_revision(opts->revs)) BUG("unexpected extra commit from walk"); - return single_pick(r, cmit, opts); + + res = single_pick(r, cmit, opts); + goto out; } /* @@ -5542,16 +5556,30 @@ int sequencer_pick_revisions(struct repository *r, */ if (walk_revs_populate_todo(&todo_list, opts) || - create_seq_dir(r) < 0) - return -1; - if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) - return error(_("can't revert as initial commit")); - if (save_head(oid_to_hex(&oid))) - return -1; - if (save_opts(opts)) - return -1; + create_seq_dir(r) < 0) { + res = -1; + goto out; + } + + if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) { + res = error(_("can't revert as initial commit")); + goto out; + } + + if (save_head(oid_to_hex(&oid))) { + res = -1; + goto out; + } + + if (save_opts(opts)) { + res = -1; + goto out; + } + update_abort_safety_file(); res = pick_commits(r, &todo_list, opts); + +out: todo_list_release(&todo_list); return res; } diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 7eb52b12ed..93c725bac3 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -12,6 +12,7 @@ test_description='Test cherry-pick continuation features ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Repeat first match 10 times From patchwork Tue Aug 6 09:00: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: 13754587 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 DFACB1BD50E for ; Tue, 6 Aug 2024 09:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934855; cv=none; b=WxQxUs6eRoan+3FCwOdxgkib2FOoqS+cLP5qwUQgZKNgqBKOp2qkdXdHt+WJpvXGo15TEwZK2YkmbCp5cj50wruszYM+I4wUXAoWQChgRpiZHpk2rv9vdzQQFAYObtL+WfsLfxI51h8VKFn+EBis8Nmy+bo8t8DUvzD3kDAcSXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934855; c=relaxed/simple; bh=gKLwYZSkELKU+tnijwxsdRSOfKdj7UQTzsM/uLATG7M=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OMISUxIEcwrJkYI3DiIXjedmdPE/g+I4y4DfGGKVEjrOt1JOEjZxyTi5oCfcznQwRcC6NmkhrTJKUXGWHo0knrmM2hZH/s88S79M0x8kAJ1NlNJafif37ToUrc55iCEmoHQhIsPY5FQS3FyWHOj7NGge/gvtHWsLqpNmskT1L7Y= 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=nd+VmA9f; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U4waNSEI; arc=none smtp.client-ip=103.168.172.149 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="nd+VmA9f"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U4waNSEI" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id E6E77138FCB9 for ; Tue, 6 Aug 2024 05:00:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 05:00:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934852; x=1723021252; bh=EtPZGOlke/ IbqPMbOKin9UQ7Xy0Beew9/4awibZAz1E=; b=nd+VmA9fo9jdxP4jPQ4nN+j4Tf Zs3aliZ9G1leLk6v8XYBgcw0GwyfX4N7nr1KYIPC90vSARwo3nDJkjRFJ2Qnz3a8 U8nZPbpgNZNgclqv+XYRtEPSomAMs8AJ7DeklFqGgAOcXHGyd5+unSw3ZKccjy1w TAX+gpCynHj/pS0BJ7ku9MiaCNKdOwTKFknHITUZascjEf4oh1vQJiC/6O6SFghg Qt91TinUd61ceIJq40TsqF70Wa6WVv1+q8nCAXw7Hvbf/uBt8HhFGXGJcAgfsCH6 HvWMy/41cQbW10vsZ9azpoq4Zf0mUbS8eXo02egypGOAXQfZehEunPBZCy6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934852; x=1723021252; bh=EtPZGOlke/IbqPMbOKin9UQ7Xy0B eew9/4awibZAz1E=; b=U4waNSEIM4+Bxta6E+NWD2zzYhGiZ3Glt811yenhpF72 onKeazAmAUR2KQuZhD28yu8nrt3LRtyilRtSGOWsNpPlkmmYJnVy1lnfwyS25nff SSeQT0RV7DNoudKJW7a58BNgAq9gOVEaSw2ldiZL3ruCbF6BVFKJaztxo2DbGnZd 5sU6SaG246iqneYg5J4U0IKvv6MldTHorlfIF6a0Vom+EAZajc4osVtk3zShGIZR 6vCBQSvM1lQ1+D7D3pNTqvW1zGleCf/J2NsgwfECPvvuAJdcr1WZubG9ZfN2GfEd dHwCovflIhCIG8lor888vVdAXVyWFu03wkVBzoZf3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id dd1dcc40 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:49 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 16/22] unpack-trees: clear index when not propagating it Message-ID: <1f8553fd4343c10a9d2ed2f9bb54937c1cc407c0.1722933642.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When provided a pointer to a destination index, then `unpack_trees()` will end up copying its `o->internal.result` index into the provided pointer. In those cases it is thus not necessary to free the index, as we have transferred ownership of it. There are cases though where we do not end up transferring ownership of the memory, but `clear_unpack_trees_porcelain()` will never discard the index in that case and thus cause a memory leak. And right now it cannot do so in the first place because we have no indicator of whether we did or didn't transfer ownership of the index. Adapt the code to zero out the index in case we transfer its ownership. Like this, we can now unconditionally discard the index when being asked to clear the `unpack_trees_options`. Signed-off-by: Patrick Steinhardt --- t/t3705-add-sparse-checkout.sh | 1 + unpack-trees.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 2bade9e804..6ae45a788d 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -2,6 +2,7 @@ test_description='git add in sparse checked out working trees' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SPARSE_ENTRY_BLOB="" diff --git a/unpack-trees.c b/unpack-trees.c index 7dc884fafd..9a55cb6204 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -210,6 +210,7 @@ void clear_unpack_trees_porcelain(struct unpack_trees_options *opts) { strvec_clear(&opts->internal.msgs_to_free); memset(opts->internal.msgs, 0, sizeof(opts->internal.msgs)); + discard_index(&opts->internal.result); } static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, @@ -2082,6 +2083,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options o->internal.result.updated_workdir = 1; discard_index(o->dst_index); *o->dst_index = o->internal.result; + memset(&o->internal.result, 0, sizeof(o->internal.result)); } else { discard_index(&o->internal.result); } From patchwork Tue Aug 6 09:00: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: 13754588 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 8E1711BD50E for ; Tue, 6 Aug 2024 09:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934859; cv=none; b=m4jmREr0NVnomeMNuZnq73GaBq/layv8wD3gEADanbXWyB6K2L/o+gAOgmelJ+Zz8F7i4r3Mfx0PbW7u5mUf7GkH6TJqDHBe3QIDJ2tZOSk7JoHJdcoMiZRO6NWgmbfN+qUO+sna9xXFGwW/a8Q7Hgz9Bb7zxerhDx2K/vh8KLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934859; c=relaxed/simple; bh=cjH81uPF44ZA/Z7apOCOmJ7XDFYulO2y/ZxmHIFw6Ew=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KwtTjq0Mjn26uhRtHzPdUJb9LWsaGLw4iusZn2ojPsPiWIueEy63Uxf7NCtECpe5le939w3BvuzBhiJnj2RzOmX0th+6fkcf+V+O1d6yRa71K/zu0A6itpi3tmyPkJi/xfbSggBN1mGi9CaqOA3l9cKI6KWiaPx8AreZgRBVUqk= 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=C/plcnC4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=aNzz07e6; arc=none smtp.client-ip=103.168.172.154 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="C/plcnC4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="aNzz07e6" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C5D0C1151B49 for ; Tue, 6 Aug 2024 05:00:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Aug 2024 05:00:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934857; x=1723021257; bh=KedPxlBv+I Hm/Hc6kcL9fpPraYVC7Z93lWRaSb4x8IM=; b=C/plcnC4l82U6q3w0bZjERs8KM T06k862NJwpJNa79uxJtC4nh4jh6cSxiiBfObryFrhvtagB21PQVDnAMsw5zTqKk wZao9Ii1d4ITFo5G6fMtjOs25em/Y6p9tgUaI/WZ/TecvVp9rnNgqwqdNDmc33XS ME1gRkpa2yIx6b4IzC9FkXdvCHQp1orWQgadk2fwnyEczeZPyHCAf8ebb5JEIqgS lk+Rkh1sJkwKsLb5TXj5AWq+ftpW4cKhdKs4x0LM0csAcg6la65I3VD3NUUKfhbl FZ97piFs0NlcckTW0PgC7BMm3d9yNaBYsUQP+CAXsTZOYZ0XQbalicYAydZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934857; x=1723021257; bh=KedPxlBv+IHm/Hc6kcL9fpPraYVC 7Z93lWRaSb4x8IM=; b=aNzz07e6z4gCyI3K00b4XSlqFGXthb4RQfXEyVCQqyPb dbyrej7XFF34MNlB7SqnOsNbL9s+p5pktJ5xRiLdSBPDxtphlSKTHQ6Hld2H3b2t 6A5wXeOZZ6gCsC20wzKkDZfl6d2xeX+5gJNWnT568MZMwR5EYY5cn59SbT1PHdDz kxSX8yilZ2uwXXtbrNG4c6v/pnwGOuj6qTTWoBMqpQsfZWJ+aiNRRy1A0rdAqkkl AMEWOsJCKMjtqF12xNHMtDIiBrqn2Mit0NqpppFAHs7BLxIvYxlpDMEKXb0BnVLh t47SjVlB0O76lB0WylfOm2pvOXrfSLjYIbW/ocrWew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bed146b5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:54 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 17/22] diff: fix leak when parsing invalid ignore regex option Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When parsing invalid ignore regexes passed via the `-I` option we don't free already-allocated memory, leading to a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- diff.c | 6 +++++- t/t4013-diff-various.sh | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index ebb7538e04..9251c47b72 100644 --- a/diff.c +++ b/diff.c @@ -5464,9 +5464,13 @@ static int diff_opt_ignore_regex(const struct option *opt, regex_t *regex; BUG_ON_OPT_NEG(unset); + regex = xmalloc(sizeof(*regex)); - if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) + if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) { + free(regex); return error(_("invalid regex given to -I: '%s'"), arg); + } + ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1, options->ignore_regex_alloc); options->ignore_regex[options->ignore_regex_nr++] = regex; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3855d68dbc..87d248d034 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -8,6 +8,7 @@ test_description='Various diff formatting options' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh From patchwork Tue Aug 6 09:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754589 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 8B3461BD50E for ; Tue, 6 Aug 2024 09:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934865; cv=none; b=rlCP4hZBwxspRSZDNSxY/4WuUoUyD+1LyOOduZ+mHJXPv7Urcz3ag915TVxQ7yIoS3YT3fUYuWdRVa5YnyuIjORpa6U2Ga8IYMEKVjoccTND+XmUd/NtkhKyvmtSc7qqjLr1Y23/gxGqEyy5aZ+j3Xqd9M9i0wqP3oD6YBLAu10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934865; c=relaxed/simple; bh=LsXwKNb/SkPL9zjesth63lH7u1ReIYAqi3Y0jL4C9jc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ecx4LK8QdSSWAkN+8ClJfrl+JYk07jDa7HLumLYCnqNU0ZapA2iMt+DzzGhXVdiAsX0a77tsLnbxaqvNM/q3/I0BNnr3qJnQ+mKhltt/boo8UfpY4G6mhFwnAqoyeIRt6C2jfl4g5SbfEXaGX7CcACe1vqN73p4QpDoI0ftbvQg= 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=hHnAn6/J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kBQo+7Ur; arc=none smtp.client-ip=103.168.172.154 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="hHnAn6/J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kBQo+7Ur" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A26E51151B53 for ; Tue, 6 Aug 2024 05:01:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 05:01:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934862; x=1723021262; bh=/Ep0ODalja yQuNxbjEheYxjWLMvAW8HsJVL2FPltV10=; b=hHnAn6/JiTTYMp9emu6Ra0/RIu F9E23IR2WDRxZJm4UqF1sJx3rsJ4ktmiBmWSwt9BWDJRmhQXB5AXKvJaRLm6HsKm eH+ZLvP08v7QOW+ZNGPrKZ/1xU1HEt77o2YIFTbtZ9swM11jfPX04ukZY6anqT2S AhGJU8R8lvKkE46JQpQOzS2nU+qYVxe/9LkzBKepqwYlYn+1XPGNWyDBlldxCrAW yL0bBAIreOyPH7U4GlCC8HnNIeiIgT2nAZVY4ZWHkZq1qZR+ojnQsqYKeWBAf4WT DNTAE6ifkn5saVv7NbmAf0gMnCB78C4AuC2thV7nnAEIijVlj8Bbp8eLl59A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934862; x=1723021262; bh=/Ep0ODaljayQuNxbjEheYxjWLMvA W8HsJVL2FPltV10=; b=kBQo+7UrtAjaVm41NF/Vd7RQA/IhgpNxETZQX3/bm9XK ub2F4BqIBp04rDX12PxfipBS/L+QTxh5Xajzar/wtYtPODeT9tJcdYeqkATJR8Ou vDP+wTg7hJMXxUrja2PGcdo6AUGjdzlYyab3VJqAKxA1t/EGVIAw4auNctgmsTNn EVAF3SYvG+h2Dbv7F8C/bIQLuzNK8v2ai97i5MRKh7Gj7cL4CmbkBVJgwpn6b6US zc5Oix755lJy1hnfrLTBdowElDDZE51QQbYwoxS5lmrRxGHD5nSpV8SbMsO8iraq fGuOo2HI6xStosCs8bJyxOaaF9Is3vK33p+Kj3L0vA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeeiiefhtedukefhieeukeejueeivdekudfhfe elhedvfeetgedtfeevgfeutdetfeenucffohhmrghinhepughifhhfohhpthdrnhhonecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimhdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:01:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 483e40bd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:59 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 18/22] builtin/format-patch: fix various trivial memory leaks Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are various memory leaks hit by git-format-patch(1). Basically all of them are trivial, except that un-setting `diffopt.no_free` requires us to unset the `diffopt.file` because we manually close it already. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 12 +++++++++--- t/t4014-format-patch.sh | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index a73a767606..ff997a0d0e 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1833,6 +1833,7 @@ static struct commit *get_base_commit(const struct format_config *cfg, } rev[i] = merge_base->item; + free_commit_list(merge_base); } if (rev_nr % 2) @@ -2023,6 +2024,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) const char *rfc = NULL; int creation_factor = -1; const char *signature = git_version_string; + char *signature_to_free = NULL; char *signature_file_arg = NULL; struct keep_callback_data keep_callback_data = { .cfg = &cfg, @@ -2443,7 +2445,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (strbuf_read_file(&buf, signature_file, 128) < 0) die_errno(_("unable to read signature file '%s'"), signature_file); - signature = strbuf_detach(&buf, NULL); + signature = signature_to_free = strbuf_detach(&buf, NULL); } else if (cfg.signature) { signature = cfg.signature; } @@ -2548,12 +2550,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) else print_signature(signature, rev.diffopt.file); } - if (output_directory) + if (output_directory) { fclose(rev.diffopt.file); + rev.diffopt.file = NULL; + } } stop_progress(&progress); free(list); - free(branch_name); if (ignore_if_in_upstream) free_patch_ids(&ids); @@ -2565,11 +2568,14 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) strbuf_release(&rdiff_title); free(description_file); free(signature_file_arg); + free(signature_to_free); + free(branch_name); free(to_free); free(rev.message_id); if (rev.ref_message_ids) string_list_clear(rev.ref_message_ids, 0); free(rev.ref_message_ids); + rev.diffopt.no_free = 0; release_revisions(&rev); format_config_release(&cfg); return 0; diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 884f83fb8a..1c46e963e4 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -8,6 +8,7 @@ test_description='various format-patch tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh From patchwork Tue Aug 6 09:01: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: 13754590 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 5AA331BD50E for ; Tue, 6 Aug 2024 09:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934869; cv=none; b=P+wJbW5FGXPg7YqOvc5pEIA4X5fRFsMP40bPj4K6PSwIXxEHoC4lCYg/Dwl0OLnTCTgEVI9Lw8CcZu7h1dfyO7VWAg5pq76HWyutrUKqnDJWZJUUERefUop6Y2LaQX9fDN6zD1VaUvAUph2C3QTDh71EVz4TlAo/iVMdK1Qw1ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934869; c=relaxed/simple; bh=2HM5uoZE+hYzHA2LYT563SlfBbfBlo9NtasIElQmNTw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hNdF3zDwWHUey7lLAkrqKqrLaJay4+585Jdscdp9zEyIaoDhFVWSxlPuXWfEV0FQxhphL8KLhNY8lG9Pl/HEUt7gU6QWtH+Ge2cUjm73JGVSBw2M7o3IH5W4ucGs0s2zPQ688Tmtt0vfKz9GMYaIn1QrEPXyk87X8U+AAohJUuA= 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=GjcVXf60; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VhulsTNu; arc=none smtp.client-ip=103.168.172.149 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="GjcVXf60"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VhulsTNu" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 75B0B138FCE2 for ; Tue, 6 Aug 2024 05:01:06 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Aug 2024 05:01:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934866; x=1723021266; bh=0U4X7CCiWf +2XtXjj9VrO0P3GYgUMFVDtHoPPOoMviw=; b=GjcVXf607JrpKX5NvHlRaVzNj2 sjDz9QWLS/deXunvjbwQKp6JGb0xmm7MfMbf5mO5Mumi2JuCMnjJC8WI3/wg/d2C HAje+Y6Si8RkaylsAfYHU068+VlZ9G2HPWyM4IepedJb1WBODpaIUinGsyWHrjRV tY8k5NCaiGf8ijlfF96MQVMYqfAXn+lTHQISG4iLv47go8oVZN2obcKGDPfi+xtU CA/sNI+fOLsRZUxGjAw1tPZaBYyQPskVHoYm2ih55ZKQV8PBfBFQ/wQQNVE5J0ZC 759YMSu85CRd2rvrsUhVxtp2IyleUpnTwf4S1/mMPtFiqiMtJKSdf/HEfDFg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934866; x=1723021266; bh=0U4X7CCiWf+2XtXjj9VrO0P3GYgU MFVDtHoPPOoMviw=; b=VhulsTNuQ4yWBVThhvS/3OFsfbyuRsnwFzbYFyBh46zk +vmMfgTlRyuObkBxaeyyRwFRPvGblU+TgL4lCZlgrqXQipl0DFKcQVMptkC45daI 7qvvCOPcJiEjoZuD5Wwjm9MLqrSZCpy0it/yRFpum777/YA4lra1OMX+Vy3PgKkJ NExV/qBzMjhUM22KiEYQW4sBE4KIEB0KiWV8IAOln2w5w8h/h45RKglLmDj297os DWBsWBAD/pcpLXQmLIRcTGCYbkqYQDDQG/eqfoeiA3AOLLf/vsMq1xCWFEjDS6O1 /g7e2N4Linieri9zzXZ9uX2eN4cqm9SsEjzMomuQwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:01:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5b85175f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:01:03 +0000 (UTC) Date: Tue, 6 Aug 2024 11:01:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 19/22] userdiff: fix leaking memory for configured diff drivers Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The userdiff structures may be initialized either statically on the stack or dynamically via configuration keys. In the latter case we end up leaking memory because we didn't have any infrastructure to discern those strings which have been allocated statically and those which have been allocated dynamically. Refactor the code such that we have two pointers for each of these strings: one that holds the value as accessed by other subsystems, and one that points to the same string in case it has been allocated. Like this, we can safely free the second pointer and thus plug those memory leaks. Signed-off-by: Patrick Steinhardt --- range-diff.c | 6 +++-- t/t4018-diff-funcname.sh | 1 + t/t4042-diff-textconv-caching.sh | 2 ++ t/t4048-diff-combined-binary.sh | 1 + t/t4209-log-pickaxe.sh | 2 ++ userdiff.c | 38 ++++++++++++++++++++++++-------- userdiff.h | 4 ++++ 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/range-diff.c b/range-diff.c index 5f01605550..bbb0952264 100644 --- a/range-diff.c +++ b/range-diff.c @@ -450,8 +450,10 @@ static void output_pair_header(struct diff_options *diffopt, } static struct userdiff_driver section_headers = { - .funcname = { "^ ## (.*) ##$\n" - "^.?@@ (.*)$", REG_EXTENDED } + .funcname = { + .pattern = "^ ## (.*) ##$\n^.?@@ (.*)$", + .cflags = REG_EXTENDED, + }, }; static struct diff_filespec *get_filespec(const char *name, const char *p) diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index e026fac1f4..8128c30e7f 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -5,6 +5,7 @@ test_description='Test custom diff function name patterns' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4042-diff-textconv-caching.sh b/t/t4042-diff-textconv-caching.sh index 8ebfa3c1be..a179205394 100755 --- a/t/t4042-diff-textconv-caching.sh +++ b/t/t4042-diff-textconv-caching.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test textconv caching' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >helper <<'EOF' diff --git a/t/t4048-diff-combined-binary.sh b/t/t4048-diff-combined-binary.sh index 0260cf64f5..f399484bce 100755 --- a/t/t4048-diff-combined-binary.sh +++ b/t/t4048-diff-combined-binary.sh @@ -4,6 +4,7 @@ test_description='combined and merge diff handle binary files and textconv' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup binary merge conflict' ' diff --git a/t/t4209-log-pickaxe.sh b/t/t4209-log-pickaxe.sh index 64e1623733..b42fdc54fc 100755 --- a/t/t4209-log-pickaxe.sh +++ b/t/t4209-log-pickaxe.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='log --grep/--author/--regexp-ignore-case/-S/-G' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_log () { diff --git a/userdiff.c b/userdiff.c index c4ebb9ff73..989629149f 100644 --- a/userdiff.c +++ b/userdiff.c @@ -399,8 +399,11 @@ static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t static int parse_funcname(struct userdiff_funcname *f, const char *k, const char *v, int cflags) { - if (git_config_string((char **) &f->pattern, k, v) < 0) + f->pattern = NULL; + FREE_AND_NULL(f->pattern_owned); + if (git_config_string(&f->pattern_owned, k, v) < 0) return -1; + f->pattern = f->pattern_owned; f->cflags = cflags; return 0; } @@ -444,20 +447,37 @@ int userdiff_config(const char *k, const char *v) return parse_funcname(&drv->funcname, k, v, REG_EXTENDED); if (!strcmp(type, "binary")) return parse_tristate(&drv->binary, k, v); - if (!strcmp(type, "command")) - return git_config_string((char **) &drv->external.cmd, k, v); + if (!strcmp(type, "command")) { + FREE_AND_NULL(drv->external.cmd); + return git_config_string(&drv->external.cmd, k, v); + } if (!strcmp(type, "trustexitcode")) { drv->external.trust_exit_code = git_config_bool(k, v); return 0; } - if (!strcmp(type, "textconv")) - return git_config_string((char **) &drv->textconv, k, v); + if (!strcmp(type, "textconv")) { + int ret; + FREE_AND_NULL(drv->textconv_owned); + ret = git_config_string(&drv->textconv_owned, k, v); + drv->textconv = drv->textconv_owned; + return ret; + } if (!strcmp(type, "cachetextconv")) return parse_bool(&drv->textconv_want_cache, k, v); - if (!strcmp(type, "wordregex")) - return git_config_string((char **) &drv->word_regex, k, v); - if (!strcmp(type, "algorithm")) - return git_config_string((char **) &drv->algorithm, k, v); + if (!strcmp(type, "wordregex")) { + int ret; + FREE_AND_NULL(drv->word_regex_owned); + ret = git_config_string(&drv->word_regex_owned, k, v); + drv->word_regex = drv->word_regex_owned; + return ret; + } + if (!strcmp(type, "algorithm")) { + int ret; + FREE_AND_NULL(drv->algorithm_owned); + ret = git_config_string(&drv->algorithm_owned, k, v); + drv->algorithm = drv->algorithm_owned; + return ret; + } return 0; } diff --git a/userdiff.h b/userdiff.h index 7565930337..827361b0bc 100644 --- a/userdiff.h +++ b/userdiff.h @@ -8,6 +8,7 @@ struct repository; struct userdiff_funcname { const char *pattern; + char *pattern_owned; int cflags; }; @@ -20,11 +21,14 @@ struct userdiff_driver { const char *name; struct external_diff external; const char *algorithm; + char *algorithm_owned; int binary; struct userdiff_funcname funcname; const char *word_regex; + char *word_regex_owned; const char *word_regex_multi_byte; const char *textconv; + char *textconv_owned; struct notes_cache *textconv_cache; int textconv_want_cache; }; From patchwork Tue Aug 6 09:01:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754591 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 4E9C61BDAA7 for ; Tue, 6 Aug 2024 09:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934874; cv=none; b=sQiOFC5BsPxdVULfihp4wWwuP+e9uezCwcmDdVO63OErSNBJGwBtl+5L4ABcf382YvJJXy6dxHrEvV2v+g3NA3GubLiLuzELVpKOsAVOWaWgpUXNmjGLFCZ66+RnStCnT5uIR1tjn2fBwVTvDdrAUr3we7CyCIPnFi0BpqI9LSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934874; c=relaxed/simple; bh=4H8UBhpOWSDL2aQdBLb0wXFW1TjrgUGOyFb6HYLr7y0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YqjIWxU7WzahLNNrfcTuWPCQ2mnM3bOb/Qvjhm60mZa4KVQ346dj1Yn9vB+xHcyAKZppOyGovVHabynlMdm46JZaIxKlgJ7swVOa4VkNd1ky5iZzqiUBesHr2C+4Ggr+C9Uhbh5xI0mwKplTIpib32RHA3OgQiWC6Mx6KSyH+MQ= 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=af7taoAL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PBDQXXCm; arc=none smtp.client-ip=103.168.172.154 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="af7taoAL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PBDQXXCm" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 654771151B49 for ; Tue, 6 Aug 2024 05:01:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 06 Aug 2024 05:01:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934872; x=1723021272; bh=P62sWqzSl3 z5Y5q2PlI3IcI4ailrNCxWax2ZR527ySY=; b=af7taoALPltDngEPM2pelSH8Oa 2Js+G7wQrndPOmTcpSxLqGF9TpEAQHAYLVoSoCZhjGjiLfH6rL01Tj7BPlimUJOn oF0BRl6E7DQigAly0FXqY97G8wkn68jZV693v9SkdvMMTYcHfjy/kq+dZEYiPFet upZeBqvh+bx00hsgfGlzB2SvnnwinP305+PH8v8oYC9pURzoXob+6V7ThRwjcUEi K1DJpXmVLb1jFyXLn0vvBxoOx7kBisixYTUktLuufnMVqUs5BamKjo6zx2W/NOm+ FxNZCpewvlplKGdjfDFII4PZHdyoNsXrozg80MO/TxUjKGPAgy5vd3+GQcnA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934872; x=1723021272; bh=P62sWqzSl3z5Y5q2PlI3IcI4ailr NCxWax2ZR527ySY=; b=PBDQXXCmKa3PBpcP+Cv7Htk24nvu7pbdIQDprYpbA5uW LLx8wUupzLMMHGKAzQkcArkAh4a1xb5Vrr3h+FGd7UQc1dejLHouSoetA81HkEiu 9ztz2nM6dMxJWE1KUUka5M02Cn+u1Qw9QC9bx4p8kJaLSbGY3qBWyazS3SUzxpQY jbuV2vNLkuqZUzs3V5RNMcvqPNWty2iYhqBGuzY3LNGwqfbmEYjv3/hV0hAZDVVV U4pofVEyTJ4yhP1cMJaBdI7+1ANTlQvw/RsN39fc3FzkCP6O9H2hHwAmO1k3WuAq hCVK1c/BKsxYQEIqPh3iCdgUSpzHFwff5m/2N5xg9A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:01:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id cb9c8056 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:01:08 +0000 (UTC) Date: Tue, 6 Aug 2024 11:01:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 20/22] builtin/log: fix leak when showing converted blob 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: In `show_blob_object()`, we proactively call `textconv_object()`. In case we have a textconv driver for this blob we will end up showing the converted contents, otherwise we'll show the un-converted contents of it instead. When the object has been converted we never free the buffer containing the converted contents. Fix this to plug this memory leak. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 1 + t/t4030-diff-textconv.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index ff997a0d0e..1a684b68f2 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -707,6 +707,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c write_or_die(1, buf, size); object_context_release(&obj_context); + free(buf); return 0; } diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index a39a626664..29f6d610c2 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='diff.*.textconv tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh find_diff() { From patchwork Tue Aug 6 09:01:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754592 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 142A515F409 for ; Tue, 6 Aug 2024 09:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934878; cv=none; b=rxSI+RwCEPGnBSuwpetnTsPdQi/Mx7wF/jOMauCbmfNVPbn23JxRI9DaIW1mYeRbr1MFfN2XIa8lvP+33slrmzrKfL4RV0m/sGPLAqhjoWP8oSIuZqSJHIXMEcFE7minm0fr4sKNi5UwTZZIE0ztz1l6qMY/m5910E1p7ZCDwK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934878; c=relaxed/simple; bh=+Z1/Un/qWq/yY3MzCUrqELTGcS/ZhrBHLmrjtLY8Y/Q=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RsLGVN6ZzIKRoTb9e10ITipC1pzcUNzEmnZ5SuVzFP/J7RIiYWaSKeNHIPZL6e/WGA4P1ivRSEGzD7vbEkuAejwuxk4ZZHbD/wZ1aVdB4TcVDnNOtXhQQxO3ob+ePpcXzAbyajOq1A6Bzj8fsreqREIx/FBJc7DxuQquk37aC4Y= 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=eg8royJw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eW7igtmC; arc=none smtp.client-ip=103.168.172.149 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="eg8royJw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eW7igtmC" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id 3B49F138FCB9 for ; Tue, 6 Aug 2024 05:01:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Tue, 06 Aug 2024 05:01:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934876; x=1723021276; bh=RWNd7SS+Wc MyL7Wn/s3EMCGlw9FhIRXCsH2fN1yMvUA=; b=eg8royJw1aOVNIlInUkLOO24Fa 6w3cwskesP/dXeZhTkLV8brtIuokVOAoaez7FTrGNGFtn7rlsDXACofaz4By3Cyj htCiQ9V1MhhMCbQn6A4w+r5mQLRfgl4fiTlLiHXoPMpx4fbSnh46s8HDMt8UuR05 a0ucdozGhVeuFZLBap7J5/scH9Qy9YVMowUhmBodtjOcYX9ov2LaUZX4bNtyH3T3 i0vIfCXqVuYWic36r42BJVwPoPPI9FSF3XpgN5bvcvxTYvfiIuwN0ZLjZkczUuKd Yza5O132nL7HKAzovW0mgcVRnoHaExVuP3Xh64Z/MAUohnpDf2t0PU5Bp3SA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934876; x=1723021276; bh=RWNd7SS+WcMyL7Wn/s3EMCGlw9Fh IRXCsH2fN1yMvUA=; b=eW7igtmCP97ky5Y+DOtWrRcdLoG92PSUTxMBP6QsWTv5 dZykoOj/n8hWCpidSKMhCto5k+ZtGseS3xJ8VVr12+qCU/owF3VwCTzmG8fqV9n0 QpkbZRpuSs6D4UT9wfSkALRjlKLRXS0zOzBLmBSrwc6pUtq93Yb4ssOPI0KnuYRa cDpeZ8kxz0YtOCm8OpARsg3G6r9XcsxwIgs9jXQTSGY2psuOAB8legpKCbW1Qi+0 P4kpDXWccXfjDDHsje/K0C6dZBf9+YcmuRur/Ab43JMzezqdVfrB84yahjugfuh/ NdDRCzf7EE6HWROdYCgQTC+u5jYzVQk0F7eKvK1EOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:01:15 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id dd1e3e92 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:01:13 +0000 (UTC) Date: Tue, 6 Aug 2024 11:01:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 21/22] diff: free state populated via 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 `objfind` and `anchors` members of `struct diff_options` are populated via option parsing, but are never freed in `diff_free()`. Fix this to plug those memory leaks. Signed-off-by: Patrick Steinhardt --- diff.c | 10 ++++++++++ t/t4064-diff-oidfind.sh | 2 ++ t/t4065-diff-anchored.sh | 1 + t/t4069-remerge-diff.sh | 1 + 4 files changed, 14 insertions(+) diff --git a/diff.c b/diff.c index 9251c47b72..4035a9374d 100644 --- a/diff.c +++ b/diff.c @@ -6717,6 +6717,16 @@ void diff_free(struct diff_options *options) if (options->no_free) return; + if (options->objfind) { + oidset_clear(options->objfind); + FREE_AND_NULL(options->objfind); + } + + for (size_t i = 0; i < options->anchors_nr; i++) + free(options->anchors[i]); + FREE_AND_NULL(options->anchors); + options->anchors_nr = options->anchors_alloc = 0; + diff_free_file(options); diff_free_ignore_regex(options); clear_pathspec(&options->pathspec); diff --git a/t/t4064-diff-oidfind.sh b/t/t4064-diff-oidfind.sh index 6d8c8986fc..846f285f77 100755 --- a/t/t4064-diff-oidfind.sh +++ b/t/t4064-diff-oidfind.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test finding specific blobs in the revision walking' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup ' ' diff --git a/t/t4065-diff-anchored.sh b/t/t4065-diff-anchored.sh index b3f510f040..647537c12e 100755 --- a/t/t4065-diff-anchored.sh +++ b/t/t4065-diff-anchored.sh @@ -2,6 +2,7 @@ test_description='anchored diff algorithm' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success '--anchored' ' diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh index 07323ebafe..888714bbd3 100755 --- a/t/t4069-remerge-diff.sh +++ b/t/t4069-remerge-diff.sh @@ -2,6 +2,7 @@ test_description='remerge-diff handling' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This test is ort-specific From patchwork Tue Aug 6 09:01:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754593 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 B8C311BDAB8 for ; Tue, 6 Aug 2024 09:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934883; cv=none; b=s5SMxJU19CdEVJA36VEVG1vse8eY8dkAvPmoxbfZ9RjiJ731fU5kMDrDppXNZID5zXL9tT6E1/0t8T0BpSWnWmO6lzt/xgl/XWQOGA+8R+mKLpgGdzCMiXFH2E2dzz7WGhLPSqEHLMDoTuqEVgbezE0v8j4ISWWtTzXz5lvePow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934883; c=relaxed/simple; bh=ZclYzd3Xp/pucf7u+yZFATP6xc1Arw/qfGliChDq4hs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GrL6uB0jhQqP8QD+gJhDefXCa+47fGpG33hxny8vlRXddoYrj1F5bihw1VXaMdbI46yPVlUmiK8qvG6nurh4H12kGY++TmuHjMcVmksRaVhJMp2ZMrfrVrkZ0aTOoadFRi75pyDsAvMw1A6ezJJXlmrsx83iB1m3KSMfspi6rlE= 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=NQGKRrYt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=t+UIuJyj; arc=none smtp.client-ip=103.168.172.154 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="NQGKRrYt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="t+UIuJyj" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1B3B2114FBD9 for ; Tue, 6 Aug 2024 05:01:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 06 Aug 2024 05:01:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934881; x=1723021281; bh=q+xAjQuWj0 /Loedc3EqR7JDNyoDS8duca2E+AAj1z5A=; b=NQGKRrYt7+M7W2cDev5/F4rx5E IYtilMItyYMaF9YhSdm1dVRfn8rRi2xkXcBoNnjlqPZQoL8rGro05bNubFjr41rU fYcEmIpQTNpTTJwA8Q330tcZZTANBNhNZAYl/ruOpbSK/EeC4W9etdoE3wXU0Osr 8+xLUwcV7Zvb888Xs+cVu2emMUsU9SSjUbhx4HmrFrIqEsPENac4qp9h90527e5c FwmKfU39FUn9F9edqeWB7/SHovKXfBt8Zl1tTF0Dg2dSrK4ED5DUh+nbWKrw/0ue wBSuU2stDgcCnt47fTWghL+lZu3a9WNObemC/9shRgrR/cCIGHoIaRFwYdEg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934881; x=1723021281; bh=q+xAjQuWj0/Loedc3EqR7JDNyoDS 8duca2E+AAj1z5A=; b=t+UIuJyjxfilvtcCFqNeRTxyNnbPgPK9dVGUaBNshwoJ wz0e0B0rMSrYzbcmtTbfgv7J7eJ8HEVOkWhAnL+mMpv8Uk1d7UOesbQ3tJygZ0CL 8fSjD0Q4TyzJESafjlQ1LA39dFcG1SvI5k9/DoLneWP46/jtBMkiZZ/xngURob+2 AIJSQFcN2G9Mt4JS5JqwG69OB8i67pzXaL3NR6bBrXQmbHo0Ebf3GYAGi/kjBrJl cvR7dKcrICyB0iTAfiocVnfWmkmOLMxAz6lCyXC8sUABpwpgF41oLILOJkTKZWUN pqmEUIQ7Cc0ccT+Nh311KYcXE0nL90IEjbe33+tKaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:01:20 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f0362ebd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:01:18 +0000 (UTC) Date: Tue, 6 Aug 2024 11:01:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 22/22] builtin/diff: free symmetric diff members 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 populate a `struct symdiff` in case the user has requested a symmetric diff. Part of this is to populate a `skip` bitmap that indicates whihc commits shall be ignored in the diff. But while this bitmap is dynamically allocated, we never free it. Fix this by introducing and calling a new `symdiff_release()` function that does this for us. Signed-off-by: Patrick Steinhardt --- builtin/diff.c | 10 +++++++++- t/t4068-diff-symmetric-merge-base.sh | 1 + t/t4108-apply-threeway.sh | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/diff.c b/builtin/diff.c index 9b6cdabe15..f87f68a5bc 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -388,6 +388,13 @@ static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym) sym->skip = map; } +static void symdiff_release(struct symdiff *sdiff) +{ + if (!sdiff) + return; + bitmap_free(sdiff->skip); +} + int cmd_diff(int argc, const char **argv, const char *prefix) { int i; @@ -398,7 +405,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) struct object_array_entry *blob[2]; int nongit = 0, no_index = 0; int result; - struct symdiff sdiff; + struct symdiff sdiff = {0}; /* * We could get N tree-ish in the rev.pending_objects list. @@ -619,6 +626,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) refresh_index_quietly(); release_revisions(&rev); object_array_clear(&ent); + symdiff_release(&sdiff); UNLEAK(blob); return result; } diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh index eff63c16b0..4d6565e728 100755 --- a/t/t4068-diff-symmetric-merge-base.sh +++ b/t/t4068-diff-symmetric-merge-base.sh @@ -5,6 +5,7 @@ test_description='behavior of diff with symmetric-diff setups and --merge-base' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # build these situations: diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index c558282bc0..3211e1e65f 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -5,6 +5,7 @@ test_description='git apply --3way' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh print_sanitized_conflicted_diff () {