From patchwork Mon Sep 30 09:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815664 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 A4E8417A5A4 for ; Mon, 30 Sep 2024 09:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687596; cv=none; b=jomzpk459AYbTsYWzx3tlCga3lGGV7UuvPRKOffD4zomqJLA+nMIx1LkkQkJ0DFuNqvpLPz62qLlJINIoQAEGc4rawLITqEvOZQD2cNnln8n7CCK+Mv42GAFWjfPKNhVe98922b08CCXbU4za8WKIC1r6wvrGCi40513/A9kYzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687596; c=relaxed/simple; bh=NAuKVxJVIqwyH9FbAQoE2sJvXDVgn9OTPaRjSYRaYKs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=utIjyz45EovF7opHSJgXkAbyrHJO8hjIU2EOYJVFX/Y7V+xq122F0LcLl4Kk/Unp8q77WftFaNYbFYadVIb+adc13prkYGAUnhGm7fZ4sq8Ta6PZ9QS9spewlREhI2DHGca3G+dc+olkJqFBciWI+/qlrqXRr+iPD8G3gewT6xc= 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=q3Jb6qIE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=K8p15ENa; arc=none smtp.client-ip=103.168.172.159 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="q3Jb6qIE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K8p15ENa" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id BA1AE11401C0 for ; Mon, 30 Sep 2024 05:13:13 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 05:13:13 -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=fm2; t=1727687593; x=1727773993; bh=/+iEFVksHw 3ckGIFAJFBIeZD3j5d4/LzbVzZaO3IbPg=; b=q3Jb6qIE5O3YuIZ5PhfGUMqRMN BN30A9Pyh5t2TiZalVGUgBvR6HiAVhBAiY2btrlHfO2oGJbzKUODySqwI7cop28v 07OOPs4JbV45VJ/j4uGdYMcjZV8qB3+K3M2qalCFBJ5G8SMy6MDcovRdQGpCA/BQ /PotaDK2W0RYKd+tnQ1E95PO+fcZOUY/xmwZarEU29PnUocn8yntWRSmGeQXOjou 6saBAyI7CQmK7RlSWHOZJEH+emd3spxxmy0MitFae30uA1BqA4Bsjdc7uljjHygL ENPfUwKS+wyEz4ZNN+bUw7gBRErAa5+Ivi6StJIGjQ0xPe/Ma/Rb2nyvyR4Q== 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= fm2; t=1727687593; x=1727773993; bh=/+iEFVksHw3ckGIFAJFBIeZD3j5d 4/LzbVzZaO3IbPg=; b=K8p15ENaQjxW7Yr/tM1neQcShi1lvdqiYk20BLm8QRxm 1710srIC1QjsAhuQWLcZNWXIVb/29RnN7Gl9ngJZuFucs4Asf8Dr43q91ikbCvAg u+FpbrYv0RTi5opLZam1yxPu8zsx2XTStT3dugwxzD9Naru3zQBJKjsn0brc7Kz/ 0lOqEnfdyCfWXoXtGh80hJKAJa28Wf5BhjqKTPAgD1mNbAq+M5W4bt3g1pqvE2Oc iwRiBmu3wCFBF/HJ6iZhhioFdNKWKxNvM41CqnUzDVO48CSQb0QPuVfZHNVXGXYS E9PGylZySsFqdMdVuzksFKZ2QSbIDEbV6wau6dQQPw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 986ab7de (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:27 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/23] builtin/annotate: fix leaking args vector Message-ID: <0a2a2085159e3817100fb639f2c9908fa7ee2f8b.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're leaking the args vector in git-annotate(1) because we never clear it. Fixing it isn't as easy as calling `strvec_clear()` though because calling `cmd_blame()` will cause the underlying array to be modified. Instead, we also need to pass a shallow copy of the argv array to the function. Do so to plug the memory leaks. Signed-off-by: Patrick Steinhardt --- builtin/annotate.c | 20 +++++++++++++++----- t/t8001-annotate.sh | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/builtin/annotate.c b/builtin/annotate.c index a99179fe4d..03413c7df8 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -15,13 +15,23 @@ int cmd_annotate(int argc, struct repository *repo UNUSED) { struct strvec args = STRVEC_INIT; - int i; + const char **args_copy; + int ret; strvec_pushl(&args, "annotate", "-c", NULL); - - for (i = 1; i < argc; i++) { + for (int i = 1; i < argc; i++) strvec_push(&args, argv[i]); - } - return cmd_blame(args.nr, args.v, prefix, the_repository); + /* + * `cmd_blame()` ends up modifying the array, which causes memory leaks + * if we didn't copy the array here. + */ + CALLOC_ARRAY(args_copy, args.nr + 1); + COPY_ARRAY(args_copy, args.v, args.nr); + + ret = cmd_blame(args.nr, args_copy, prefix, the_repository); + + strvec_clear(&args); + free(args_copy); + return ret; } diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh index d7167f5539..d434698919 100755 --- a/t/t8001-annotate.sh +++ b/t/t8001-annotate.sh @@ -5,6 +5,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 PROG='git annotate' From patchwork Mon Sep 30 09:13: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: 13815666 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 7F5F715F3F9 for ; Mon, 30 Sep 2024 09:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687605; cv=none; b=Bkt7XHSSAjSHWw7gyEu4x5QDiEO5UT+dvTmvCKw/5M/hONKq3APfaigpaqw2owhH/nb54hSQHd4KT8WoALU2/oY+C260mfrtiCCSNMjxXZY8rg4c1xQ8tNTcceQPQYgcGAetLRuSPCPMwBgSsqpOONVQu5vFURgHTLG5OgzCh/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687605; c=relaxed/simple; bh=2asujhDmKhqlVunaQCiEbX3bSnk3u1s8d7hseHgnI/Y=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hu925s3DZDRlQAbLOoAFXFDmeJfr2jBY4bc4CRHUrMYLQgRj9bgPpQAKL2vmNpQNUH55V8YM636+RVFKN4hYqUAe1tYpamzio3cGmdVCd8iy2AfAsU6yOA3q7R6utw+0LvInThqRVxPEtAy5UUw+ZELaSfEnuJIOEY5UJXQ/1S0= 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=SG8XOPV8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ANfpak1/; arc=none smtp.client-ip=103.168.172.145 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="SG8XOPV8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ANfpak1/" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 9E25313803A6 for ; Mon, 30 Sep 2024 05:13:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:13:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727687602; x=1727774002; bh=1aDGElKW5+ WFN+qlvr8WBZwSKex88jYWnf4PI7P9Vzk=; b=SG8XOPV8gNcGGKSOikIjcgMSnS BWFdXKBxYZyth8CnzeKSqvtXz4zgZiLLSehlVIpUJeukN/3TH21YiV/J6Ru+r8zB rC3SsGdsOlf9N9i6logaMyZiTZJH4M7PuOL4odpzwHlmAQPmgjebYXPq0Fo7t7Iq AsXgoGJonrJ9Igt2fGOudQl9bdVRisoqTHMRDSjR9hP4I9WknMdR4Pd2xtIEFRFa p/sndJ5CnwFUqoRbDe9DC+l0kvEFklU9ruqzi/GMa3vmptMiI6EU+QGYOEMxzIXi h4bkh9uI0Hbv1PvwBkYRYT3Ug/Wo4D2OtXtq+FuEgC979BS7XF0xN81L+NSg== 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= fm2; t=1727687602; x=1727774002; bh=1aDGElKW5+WFN+qlvr8WBZwSKex8 8jYWnf4PI7P9Vzk=; b=ANfpak1/dlDAzR8d2YkOXNpVJNIz2LM+Eu8GJA3HRHkU P1MUgqDubcWG15wtJvVMf3R0tCcSPhVqW3s2CX4/pZ2NnrOxUTsOIxTyQPwnz/86 3yLzI+OKlkvqeqQ7286aOOZurKisRwujQfun/9uQpe7tTm6hA0I9aI11cX9E4EGG pUxmd7+/9z/oHE5do3wqN2wYS5k2IhOEi6NTKKfZJjF1Q3epJ/VdI7vBXCZHlvv1 S327fphvB41PwcSodLsRR5wrR4EjEI3s7UiTXlUO33yzjWHjbkVAV/qluThNZw3F VmB5JzD5EGqU8IejpsXkI6gCXEl8R8mXlEA7ElHhqw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7742350e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:30 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/23] read-cache: fix leaking hash context in `do_write_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: When writing an index with the EOIE extension we allocate a separate hash context. We never free that context though, causing a memory leak. Plug it. This leak is exposed by t9210, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- read-cache.c | 1 + 1 file changed, 1 insertion(+) diff --git a/read-cache.c b/read-cache.c index 764fdfec46..0fb5e0d372 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3124,6 +3124,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, if (f) free_hashfile(f); strbuf_release(&sb); + free(eoie_c); free(ieot); return ret; } From patchwork Mon Sep 30 09:13:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815667 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 7D24717A5A4 for ; Mon, 30 Sep 2024 09:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687606; cv=none; b=lvPHU+1aVLXTDlDZexCTEOTjoUI/xnLzVYJvDNGmKHwpWvP4J8hGjRTxDH77HUTisMiwHtHpIHO6f/73LX/ZCgSfQj6UCimq5CjMXB6vLanb3poddllYEpOfKzWVJGDrU8yPcuNsv9mtU0rJfbO3A/9Ksl7DTAbzJGKQZuJwdhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687606; c=relaxed/simple; bh=W9psKAvuz74AsfRxjWpJZbr/JtwTbFs+uy3iQ6niIXk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C9M+45s4ubT6gpcU05nwG94WfQjbkScr9k6kyUqZ0IuAyWnEKNNd5o8jDfTo91QKPmHkoz1mv7Wh/rt4vmYIMLmCH8x1J9SRz46xXSw45ZrZKYFlJ4WmYRdgQrctSIWT/BRUhjvA71jBNslFbZLbZGSemEk6MUX7RFqYR+Wd9f4= 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+S5IxXb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FbUjC4ho; arc=none smtp.client-ip=103.168.172.145 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+S5IxXb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FbUjC4ho" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 8144C13800E7 for ; Mon, 30 Sep 2024 05:13:23 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 05:13: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=fm2; t=1727687603; x=1727774003; bh=Mr5lakhXG6 HKUlD9w81t+IlvQWmoV5y8xTZB6taOt0M=; b=N+S5IxXbTe/oTgSDhnEYGeSwZj 1vmDfO0kv+wmpRL1lzdskzPuvd54FRIpUkm6mViUw5tT8ywTq/gTN03b3EGrebDV U8N6mXmrMW4nfX5vrjQG/dERwgxZuXS5CSWFnXOoQEZHnw8Xek+rIXU1C+eJpo42 yYAorSoJYsY0YgzYw6m8F4W78VEdJmR8LYviPvH2qr8rOX5mQfYM+DZw20Dh/QWz MQ1VUJ0z/6glXy7O+V6l8eOdgCgBrldrjWGCfOKfzE56UxfCw/odHGMT5Y3bwH7t E+mge2gkFq4H8OsWQ4sjNLxgIxn4yf05mRaMB8CRkgJkbkftcMpJvLeHhFPQ== 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= fm2; t=1727687603; x=1727774003; bh=Mr5lakhXG6HKUlD9w81t+IlvQWmo V5y8xTZB6taOt0M=; b=FbUjC4hoihvSCrNv2Pe1BsciXEUDZj6YKRCwHPcGS5zQ T2BfAhbhz9mWHzNl0bu591e9no7iCIXwdd15McvCT1hGWVNkREFXHuzxqF2rLUnz 74tonD4/0+MAlZL5Tq0vxPRksKBvV/qivaWhKg1p/CWdXKy48h5agpo3ZvxOEiiH G7utC2WFtMINHrAPFF5fTioVav08VZEbbH6EoWAXcoq4hcXcMxIAtuONu/7mOAtO QZZtcrjxgdMjP/oXUhg/CQGp1vAGtuFrORCy/LQjydcMki8WSfm5WWb3MyI2wmyX cCq4pd4ExYilVv/hAnHgJYVorT4jMx1xmO1X7aBB/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:22 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 40d378ac (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:36 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/23] scalar: fix leaking repositories 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 the scalar code we iterate through multiple repositories, initializing each of them. We never clear them though, causing memory leaks. Plug them. Signed-off-by: Patrick Steinhardt --- scalar.c | 1 + t/t9210-scalar.sh | 1 + t/t9211-scalar-clone.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/scalar.c b/scalar.c index 09560aeab5..ede616ad4f 100644 --- a/scalar.c +++ b/scalar.c @@ -732,6 +732,7 @@ static int cmd_reconfigure(int argc, const char **argv) succeeded = 1; the_repository = old_repo; + repo_clear(&r); loop_end: if (!succeeded) { diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index e8613990e1..a131a6c029 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -2,6 +2,7 @@ test_description='test the `scalar` command' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true" diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh index 7869f45ee6..c16ea67c1d 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -2,6 +2,7 @@ test_description='test the `scalar clone` subcommand' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "${TEST_DIRECTORY}/lib-terminal.sh" From patchwork Mon Sep 30 09:13:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815668 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 2E8C9186E39 for ; Mon, 30 Sep 2024 09:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687607; cv=none; b=dxphx9t0W3kgJYyzY+KyTSy+VipjoNiJ1oP+jWSYVXICSvrfIuCTz52lIItaDXQ82hHjJ4+5X8CRcAQy8pPMXt4wBXKTRpYU+Js/DURRySVXoUyoujWTd8FqAWwTSvqOMv18BjhXLQwSJdJMe0PLWnxIVE4LJulYtWUd+pQ5iGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687607; c=relaxed/simple; bh=xFp9RHwLy+SCLaa924+hOoWuhhArpaQZmgyY97voFOA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bh2ZdJFLP3AhxOSaVFT/rUaIsGJ/GAbARsgjmHiX0Qc5EVjgSUS1TVCMtEgLut+LdaWDyd6qpUQH5qypAK0WIfVAxCQS5sek+PZX+WvHKyyhl8EUxZUKsW/CtAl+qu4HlvGWFYEIWVhhjYFKjqbhnogOMC9M0onmL77GEojWZD8= 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=L1+DG61c; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jkCNhS43; arc=none smtp.client-ip=103.168.172.159 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="L1+DG61c"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jkCNhS43" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 6F68C114025A for ; Mon, 30 Sep 2024 05:13:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 30 Sep 2024 05:13:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727687605; x=1727774005; bh=qRsvD3Mtth ug8xvsdJ9xkljxj03Rz5uwS5ArjocElXU=; b=L1+DG61cCUIMy6A8vDikPUNAmY S/IvXaDgln9gjDa/fM5Xx1NMQ+e7Nmz2IGQpZfAti/g4WJVk07N4kBtkoBfYW/hQ a9d3l4NHA+d72ldYY5HcqPp2y3taIKZRNTr9NbvlUZChjUimnRkOzjKYT3ESVCKx mBgyH+GVWRVqTR1lFQubR1jwgF0dPDJvSEUjcTGJMpzOfTnGEhFJ/E/vZ1LDjxiC 8yByQFoGzILmaCh/toQPpm3rI9uyLL9lR2CZ0zuI+PSayHWINaW2k1zoJKfoUCKR 0mvMoD26yh6izYo6AcXs02vApNfdPDq/nYXVN2r2WW43Lq/+zSCez+3oQcQA== 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= fm2; t=1727687605; x=1727774005; bh=qRsvD3Mtthug8xvsdJ9xkljxj03R z5uwS5ArjocElXU=; b=jkCNhS43pBpEYOxtDckPZBlOBlhGaRf/oBFFRY8XuaQi PtVTOq04IngvIONcVzWIwbYPlcyrTVJc6hKlhL1ZCSivhP51jZRN2fBLb0fsqURF gIl38i1TuNsW+TLNke7fr/zvQejbaqfq6itzjGS/04d10yeRhgbVvcfxeHirN8bj B2UdVIhklyOaTQGzw3QS/TzaXldrvrs7S1lHQVXasfxcQOBRsp0fy9VouBp/39tn xL+SmpUHsZoRJwIwACvzf8935mE8RSwmuVFb3dA7kmDN7Ysj2/66P8Np6XtBiCJN mqC5dNyEskQMcTVjnSG6FxhnjNZZ+ABeKr8lVC8NhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 17ae639f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:39 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/23] shell: fix leaking strings Message-ID: <0fbe431b508c78ab2a12107af0bc00eb5573a392.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are two memory leaks in "shell.c". The first one in `run_shell()` is trivial and fixed without further explanation. The second one in `cmd_main()` happens because we overwrite the `prog` variable, which contains an allocated string. In fact though, the memory pointed to by that variable is still in use because we use `split_cmdline()`, which may create pointers into the middle of that string. But as we do not have a direct pointer to the head of the allocated string anymore, we get a complaint by the leak checker. Address this by not overwriting the `prog` pointer. Signed-off-by: Patrick Steinhardt --- shell.c | 6 +++--- t/t9400-git-cvsserver-server.sh | 1 + t/t9850-shell.sh | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/shell.c b/shell.c index 2ece8b16e2..76333c8068 100644 --- a/shell.c +++ b/shell.c @@ -143,6 +143,7 @@ static void run_shell(void) } free(argv); + free(split_args); free(rawargs); } while (!done); } @@ -216,9 +217,8 @@ int cmd_main(int argc, const char **argv) count = split_cmdline(prog, &user_argv); if (count >= 0) { if (is_valid_cmd_name(user_argv[0])) { - prog = make_cmd(user_argv[0]); - user_argv[0] = prog; - execv(user_argv[0], (char *const *) user_argv); + char *cmd = make_cmd(user_argv[0]); + execv(cmd, (char *const *) user_argv); } free(prog); free(user_argv); diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index e499c7f955..6da7440e73 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -11,6 +11,7 @@ cvs CLI client via git-cvsserver server' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh if ! test_have_prereq PERL; then diff --git a/t/t9850-shell.sh b/t/t9850-shell.sh index cfc71c3bd4..f503f16d1b 100755 --- a/t/t9850-shell.sh +++ b/t/t9850-shell.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git shell tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'shell allows upload-pack' ' From patchwork Mon Sep 30 09:13:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815669 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 1913C18858D for ; Mon, 30 Sep 2024 09:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687610; cv=none; b=ceF4YOmAtCBos2RkSQd9InVAqTscn+YcqHa5vyL5h76fQo6mgXPoHQL/+9+dY5asxjO/bRZDmK11zcjgl3lJr2Yoj7gMCtvMW0R05xubSlW14qWIq1EtutJtcOodukFw+JYEToeqBJGTcEkEdMN0cgwaFG+8kEnDzWMYgaQ5vgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687610; c=relaxed/simple; bh=iQPwM65CoBe3fymROaL6km5B2te5VTVja2vT5AKFdLw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=brQuhGwjRIUVmIPMZ2Tetqz5Y9o+XFBDcXBYsrYvp9PnNfvTtDYhmixyJULhbZXjbgoDP/I7k2C/O9/XMR3i72ohPCJ2HM6jlPB+Z1W5LzS9yZEsZtRrH5MTJl3HKBRc5tDi/JYpquP40T3oSnSLl/Av7PqOOeTivWYasmPB3Ik= 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=IVdwgDt2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=pYgHv9sg; arc=none smtp.client-ip=103.168.172.159 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="IVdwgDt2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pYgHv9sg" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5700C11400B7 for ; Mon, 30 Sep 2024 05:13:28 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:13: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=fm2; t=1727687608; x=1727774008; bh=mvjPC5KKjQ UnuK7GCn8/Jr/zeybuo/nbGbajliZmT4Y=; b=IVdwgDt2rxaYVNqByUJ3kOZ9X+ 8nRJywkG9c57QVnDoRVaUWl7r5di+Jo99N4/RfEsdoaJv8Mb+ts67/64vGhp827E 1mtSdKL0LzeKsBV7Y1O4eysne/KNQaXtvVxYdMdHmbi3IFp3+9YpKFSeKsKohyiw 4qwH1iYN4YSZIlrwdFDJ6FqNnL4e4+XkKhVwjBxh5S/rEYqqAtTyL2gXrLXhOXFL aJ+vi8BhxnQbg3npBwy0t48Dj/wypnKSxor1dbMFe92j3pyJIwe2odcsnfwoHcTa XX2WouydV/z18yzm9OkuCipiUcZ5UC7Xo99hDw99Sv6BrLaeUM4+X2v7Mv3g== 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= fm2; t=1727687608; x=1727774008; bh=mvjPC5KKjQUnuK7GCn8/Jr/zeybu o/nbGbajliZmT4Y=; b=pYgHv9sguCzuDVjaDT0KB23ivHC822ay1LoXzGIK68NI dJL8E2S6yBNKXKLws2JB7bAzMypXHnlorajbGAX1tbjyjtnafTyytpN0NmP1AsbE qC4NuRlq4Czw7u5C0AnS1tGsln0nTcps0CQoCdyHdZnGtH4Q+gopgzwFYm96TfoO DATROG5bYLHDWlYeTU8yrHhQICeE+Cd+UiRxPK7eT92CbDGgB60fJgCg6ztOOdKf 7NAuVnCTshxj+RMPSNmDClAVLNZUN0itIfXjq7DZABE5DvaMI5JGh6FbxuhvUNDR OCsZV0lTZVQIn3fbQc7DPOuZ/Q3v679Eqp0YIEh8ew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 907e9062 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:41 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/23] wt-status: fix leaking buffer with sparse directories Message-ID: <4196fea159a98ff9a25ca0f65a9c669f45155a7b.1727687410.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 hitting a sparse directory in `wt_status_collect_changes_initial()` we use a `struct strbuf` to assemble the directory's name. We never free that buffer though, causing a memory leak. Fix the leak by releasing the buffer. While at it, move the buffer outside of the loop and reset it to save on some wasteful allocations. Signed-off-by: Patrick Steinhardt --- t/t1092-sparse-checkout-compatibility.sh | 1 + wt-status.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index eb32da2a7f..55efafe4e0 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -5,6 +5,7 @@ test_description='compare full workdir to sparse workdir' GIT_TEST_SPLIT_INDEX=0 GIT_TEST_SPARSE_INDEX= +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/wt-status.c b/wt-status.c index 6a6397ca8f..6a8c05d1cf 100644 --- a/wt-status.c +++ b/wt-status.c @@ -717,6 +717,7 @@ static int add_file_to_list(const struct object_id *oid, static void wt_status_collect_changes_initial(struct wt_status *s) { struct index_state *istate = s->repo->index; + struct strbuf base = STRBUF_INIT; int i; for (i = 0; i < istate->cache_nr; i++) { @@ -735,7 +736,6 @@ static void wt_status_collect_changes_initial(struct wt_status *s) * expanding the trees to find the elements that are new in this * tree and marking them with DIFF_STATUS_ADDED. */ - struct strbuf base = STRBUF_INIT; struct pathspec ps = { 0 }; struct tree *tree = lookup_tree(istate->repo, &ce->oid); @@ -743,9 +743,11 @@ static void wt_status_collect_changes_initial(struct wt_status *s) ps.has_wildcard = 1; ps.max_depth = -1; + strbuf_reset(&base); strbuf_add(&base, ce->name, ce->ce_namelen); read_tree_at(istate->repo, tree, &base, 0, &ps, add_file_to_list, s); + continue; } @@ -772,6 +774,8 @@ static void wt_status_collect_changes_initial(struct wt_status *s) s->committable = 1; } } + + strbuf_release(&base); } static void wt_status_collect_untracked(struct wt_status *s) From patchwork Mon Sep 30 09:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815670 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 22D00185B76 for ; Mon, 30 Sep 2024 09:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687614; cv=none; b=om0K1QK5Nx1USOKy9cgNuBLpMPhVIgdhvUaxLZ/VaA4hjDEe61KC+66CZ6DwxoEaHnSOg3+x41hMCIMDjnRYsy68V9JrbTXy9fLykhhpAWzQbaSKONCDzoFdTappdAE1qCcfQOWBUU5cJe9/VtFP3EYwtVZv8qWaesX5RMMLJGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687614; c=relaxed/simple; bh=ioHGAxCfNZwc2w2Kk2FZRE8YlBScfUxhRBJqJ6C4/W8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DsX03iS+vEglqJm4IEEtSeJWRUQ303f92743Ja3WiFDtqtDRrSG8PmXco9lUEhh9uw9GdATDZcDHUUcL+ZCZzg4FhJO8FiSwVw9q/S2xM3EDuoKX1b4JlgBZlT1jb0C2wKyY4ZfQqWFjIbxR+28oq4B5Cg+yfE4b4WLeJF3URz0= 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=bS9L+3m5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LP3hmKwP; arc=none smtp.client-ip=103.168.172.145 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="bS9L+3m5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LP3hmKwP" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 35E0A1380459 for ; Mon, 30 Sep 2024 05:13:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 30 Sep 2024 05:13:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727687611; x=1727774011; bh=QAGQG/pVp4 OPTpBYnfwNgwaQjCmH/Je2DlDtoTCQ/So=; b=bS9L+3m50MrWT7kQ05nwnOf78v eESytOvNLHVIFCT9g9CQPDKWogp8UQQqz7rLSl9rTQXkSww5G2Z84iiS1Br+2ZxW 9oZIVfQqIyGGP4GOljkWia2ZgIDdVDPX0pYVfL6UU/wDp/lcgT+OdqYrE5nIZq14 bfH/F8k545DfuSqJC/eO2eDUFvWeH33B81PeBVr1vh8hX+N7jpJ5OqyCWvg0b8O3 VzMEwrRmUwhUf1p/36pIx1YU30VKW+fSAiIur9FPuzV1JejVzeNQYsDTnqXp1cYz gIv3bUKk5nDjd9IyVM6OTXJXSTQDfoa9m3BgHnmCMSGxMUUzW3E2fagEoKuA== 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= fm2; t=1727687611; x=1727774011; bh=QAGQG/pVp4OPTpBYnfwNgwaQjCmH /Je2DlDtoTCQ/So=; b=LP3hmKwPERBsMphM/o8w4GfC00BZsdGwy7nhqZeaZ3yy opEazU0Iuj1iNX92HssePPFEHHduxS6R+FJIVQVHgNFMZ5ZDSPEITtGnknZuTLiq 9O6tFZ7uZOnsXe85OEFJydwpVyji0/DKDPEvDtIKf8XU+Cr5b6eYUYu4KfpdhSFF 9sICLmLVPWSij6ksMeUTWptgbIwmOwDVPjT+aBTrdoXvmktnHAJ1Cn9SAE4wdP0u F4D8XBcrwAqyPNxYdut/zAOSf1fe+lIEbrmQjrvlOVgor1S6dRzYrc7+ZkyxWzip e+cMpMDuOaKy3DUUFngBFQuX8f/duDYoPrkSqscxNg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3f14d376 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:44 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:27 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/23] submodule: fix leaking submodule entry list Message-ID: <7781d7644e9f76a6638cabc0412d583ad703905d.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The submodule entry list returned by `submodules_of_tree()` is never completely free'd by its only caller. Introduce a new function that free's the list for us and call it. While at it, also fix the leaking `branch_point` string. Signed-off-by: Patrick Steinhardt --- branch.c | 8 ++++++-- submodule-config.c | 15 ++++++++++++++- submodule-config.h | 3 +++ t/t3207-branch-submodule.sh | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/branch.c b/branch.c index 08fa4094d2..44977ad0aa 100644 --- a/branch.c +++ b/branch.c @@ -738,6 +738,7 @@ static int submodule_create_branch(struct repository *r, strbuf_release(&child_err); strbuf_release(&out_buf); + free(out_prefix); return ret; } @@ -794,7 +795,7 @@ void create_branches_recursively(struct repository *r, const char *name, create_branch(r, name, start_committish, force, 0, reflog, quiet, BRANCH_TRACK_NEVER, dry_run); if (dry_run) - return; + goto out; /* * NEEDSWORK If tracking was set up in the superproject but not the * submodule, users might expect "git branch --recurse-submodules" to @@ -815,8 +816,11 @@ void create_branches_recursively(struct repository *r, const char *name, die(_("submodule '%s': cannot create branch '%s'"), submodule_entry_list.entries[i].submodule->name, name); - repo_clear(submodule_entry_list.entries[i].repo); } + +out: + submodule_entry_list_release(&submodule_entry_list); + free(branch_point); } void remove_merge_branch_state(struct repository *r) diff --git a/submodule-config.c b/submodule-config.c index 471637a725..9c8c37b259 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -901,8 +901,9 @@ static void traverse_tree_submodules(struct repository *r, struct submodule_tree_entry *st_entry; struct name_entry name_entry; char *tree_path = NULL; + char *tree_buf; - fill_tree_descriptor(r, &tree, treeish_name); + tree_buf = fill_tree_descriptor(r, &tree, treeish_name); while (tree_entry(&tree, &name_entry)) { if (prefix) tree_path = @@ -930,6 +931,8 @@ static void traverse_tree_submodules(struct repository *r, &name_entry.oid, out); free(tree_path); } + + free(tree_buf); } void submodules_of_tree(struct repository *r, @@ -943,6 +946,16 @@ void submodules_of_tree(struct repository *r, traverse_tree_submodules(r, treeish_name, NULL, treeish_name, out); } +void submodule_entry_list_release(struct submodule_entry_list *list) +{ + for (size_t i = 0; i < list->entry_nr; i++) { + free(list->entries[i].name_entry); + repo_clear(list->entries[i].repo); + free(list->entries[i].repo); + } + free(list->entries); +} + void submodule_free(struct repository *r) { if (r->submodule_cache) diff --git a/submodule-config.h b/submodule-config.h index b6133af71b..f55d4e3b61 100644 --- a/submodule-config.h +++ b/submodule-config.h @@ -136,4 +136,7 @@ struct submodule_entry_list { void submodules_of_tree(struct repository *r, const struct object_id *treeish_name, struct submodule_entry_list *ret); + +void submodule_entry_list_release(struct submodule_entry_list *list); + #endif /* SUBMODULE_CONFIG_H */ diff --git a/t/t3207-branch-submodule.sh b/t/t3207-branch-submodule.sh index fe72b24716..904eea7df5 100755 --- a/t/t3207-branch-submodule.sh +++ b/t/t3207-branch-submodule.sh @@ -5,6 +5,7 @@ test_description='git branch submodule 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-rebase.sh From patchwork Mon Sep 30 09:13: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: 13815671 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 EBC921865F1 for ; Mon, 30 Sep 2024 09:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687616; cv=none; b=gJ5Io2ZWjjCXNsoq/Jy9YFXbvJH4Zxq3ewMbhlD+Ze4+AQiD6DXdaQmJ1WcG7mJaBZDhanJDdDlt2tZSAQC0sWR5ZnZo3a2W/fM7cCmMSQklv7/VNfQRjTmHbwsVbmnXrbzAZU819grU4cI7/k48otYXgtFlfHbvc+60JvlxqrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687616; c=relaxed/simple; bh=pUtyUXSwBO/O9xKZFTcC9U9FtfsVV96uRzsdmVBSNaE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uN7N0yt0oUJu5Ytl2JMetYWBYo2QqnxDk+u0SsSdj4dVRbDbuW5QQ95HSvP+SBbP6fXIY5xkJ8mzJccRDAMcsbqdjndmMcUQgWvze320xDnHxfhnM55Knr7gkiMYX8nSkRjDPxzdhCWVhi+hUn++gvb6D/R9MEFzTtgMk6y0mBM= 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=bvatDJp3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dj0s7swj; arc=none smtp.client-ip=103.168.172.159 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="bvatDJp3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dj0s7swj" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 13EAF1140259 for ; Mon, 30 Sep 2024 05:13:34 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:13:34 -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=fm2; t=1727687614; x=1727774014; bh=eAcIhZ9wuj UMulSpKeP2qqrvOCmSHsmPVmyMgipp9Dw=; b=bvatDJp3haeYOGoXo299ri/fIl cEh3CMm3XIlU+TmeHMhDGInLu+SeKvsU9gxRVtc+Z5XhDEL1z78gvHnRh+iXrSwH 0DBBBOI7HvwXJreWTV00uPvet5zQfsg0pmaDK/biFY9m85+UimqVPrsi3Ry/rIcO Z0h+T04vbce5QXxqEyFziD7xWrZ6uI4QyQlwhoeKs6nPsysCt1Aeyqz7VY8/nolg iQtUwYQNcojQiOABiz6gSuDMgiu16fEOfvKEJPk2sjqxKIffdcpKvg5KLVpRLxDJ 5z2BrgYhr67s8TV+KGFZ+bkSUyS0yxa9Xy5ocZFv70kXTEI/A8XMMBxNK7xw== 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= fm2; t=1727687614; x=1727774014; bh=eAcIhZ9wujUMulSpKeP2qqrvOCmS HsmPVmyMgipp9Dw=; b=dj0s7swjbdL/cy6EC6CdVySROOGtBfJ1SkdP4tT+iuKa zrs5XvmaIQULdrUME1niX62p7YizlaNzYN3dFkoMgUNEDOKB3qab+R1bWjqarEFQ 5TJF/DFmc3Dme9COL1zos+XqhJcDdcC+WhfzOZxG80Evrhv4zjb2R/wluOSt1pNs Dd9a3BVtDzDHMyGUcVCP1iSL0FVqfMoQ+t43vIYeciqGy5JOZbJAv9qzl6nlVd2k CMZ2xB9MRp1OkrZIXjCgt4UQrgproatf+HrfQaL1rAXTqigO60Fm9SErJyJWN/gQ axIqISZSLXZT2PU2vyP50UBgaZU37bX1EQr28CFozA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:33 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id da82c674 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:47 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/23] builtin/stash: fix leaking `pathspec_from_file` Message-ID: <38b58f5b7470d3fb07396d62cecda3799d0b944c.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `OPT_PATHSPEC_FROM_FILE()` option maps to `OPT_FILENAME()`, which we know will always allocate memory when passed. We never free the memory though, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- builtin/stash.c | 4 +++- t/t3909-stash-pathspec-file.sh | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/stash.c b/builtin/stash.c index f1acc918d0..1399a1bbe2 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1759,7 +1759,7 @@ static int push_stash(int argc, const char **argv, const char *prefix, int quiet = 0; int pathspec_file_nul = 0; const char *stash_msg = NULL; - const char *pathspec_from_file = NULL; + char *pathspec_from_file = NULL; struct pathspec ps; struct option options[] = { OPT_BOOL('k', "keep-index", &keep_index, @@ -1821,7 +1821,9 @@ static int push_stash(int argc, const char **argv, const char *prefix, ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode, include_untracked, only_staged); + clear_pathspec(&ps); + free(pathspec_from_file); return ret; } diff --git a/t/t3909-stash-pathspec-file.sh b/t/t3909-stash-pathspec-file.sh index 73f2dbdeb0..83269d0eb4 100755 --- a/t/t3909-stash-pathspec-file.sh +++ b/t/t3909-stash-pathspec-file.sh @@ -2,6 +2,7 @@ test_description='stash --pathspec-from-file' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_tick From patchwork Mon Sep 30 09:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815672 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 BFE811885A1 for ; Mon, 30 Sep 2024 09:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687618; cv=none; b=irnIk+rnfNkL3IId8/kv8iW+dNy8f/NcPplzHtXGm+TobpAEXdKVTiblJnjnejYvmS5GqJmx5adze9tAW2KM2iykUvy/4knvkzzvJeV2YLOK4nV531WbyKw/Dq5GLFMzhroOv8IH5cIWohtX1D2X0eef16SuZjke5zQqGS/eCAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687618; c=relaxed/simple; bh=TK+u8+yPb8EYWHEpNbrAS4ap8pVP21kSGZE97EtiiEA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TgUSsOlOpkQSzhP2UPQFAsmjsQ2sQenD3dzDK7iX/GwHGk1QtXL7O+ZLKK4IUm3LFgmp9dUGiQeUeiIhNv4r96JFdSwi7uYq1hxL1V0cMRWbA6p3vYLVeSObl5JBsMvLV3eSAnMU+e+g9I8Z6MrbE7tLH+ypnX0F8rCk57QBDco= 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=rfUinpnw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WLsWB8zI; arc=none smtp.client-ip=103.168.172.159 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="rfUinpnw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WLsWB8zI" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id E24C31140266 for ; Mon, 30 Sep 2024 05:13:35 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:13:35 -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=fm2; t=1727687615; x=1727774015; bh=sHrK6Hq13Y wSAUEgUEHNJkxWC4KdFXF9bEh6SfEDwOc=; b=rfUinpnwzwd1gibl5cCsjTU6iZ W2HRtKzuuj3lwv1l4JC/y3RgDcEp7VrmGlmkI1+5fwn9oj6jm166pzJaUj/3gzGs c2g/G3kbA9vEeBefMXfrZQ7ds2aDGBQSrBgiQpMZrHbj/MGLwi/ciB/h1xBC/se7 0QpYjU2eAFk4aPTqron9ffYDkeqiC9f9+i7Pl+oYtrVOIav5ChHixmfR2bdsV7dG +eT7Je3X16zKL60c9VeSh2VQuJVsLkFk5T+ApFWlOD3bY+Jx15FS2Y9mgZwdVnAn T+FtgeTc0Qe/Rcx1xHTSQ7u9SszJd/B37y1eitibYLXUs+BNsx0sXnWAiofQ== 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= fm2; t=1727687615; x=1727774015; bh=sHrK6Hq13YwSAUEgUEHNJkxWC4Kd FXF9bEh6SfEDwOc=; b=WLsWB8zIe8heiaR0287UpMYN43SYhKIq/mAbxtwS1sOs VepeW7XGs3WXlq54Zjq5nPORMiIiSdRn8NPG0hqE+kkh/Noz4JI7lNPkkH7fXlAJ qimREzvh9AWJSquYmbVddO8uEDX0X2vCDhC2OtohNUavCP/EcQ3hkHiIH2x7FYD1 0NUzNk58hm47mZxc057eyCC1fag5pvKJ2bCyTlL0aVrb+lQ9jG225cDzg3PK85h+ HwnNCsSJ9NfpjbQFJr+PQiFyhMGo1mcfrxWz/JeSAQwuy3iTUBEZ5bf71A6npozk pRXyQFKhmyAETz1jJkLLZjW7ldkZnaOQVCn3xbvp/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:35 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 531ca629 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:49 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/23] builtin/pack-redundant: fix various memory leaks Message-ID: <31480f336a151e1b7dd984368a5cd54ced40b4ac.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are various different memory leaks in git-pack-redundant(1), mostly caused by not even trying to free allocated memory. Fix them. Signed-off-by: Patrick Steinhardt --- builtin/pack-redundant.c | 40 +++++++++++++++++++++++++++++++++------ t/t5323-pack-redundant.sh | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 81f4494d46..5809613002 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -69,6 +69,15 @@ static inline void llist_init(struct llist **list) (*list)->size = 0; } +static void llist_free(struct llist *list) +{ + for (struct llist_item *i = list->front, *next; i; i = next) { + next = i->next; + llist_item_put(i); + } + free(list); +} + static struct llist * llist_copy(struct llist *list) { struct llist *ret; @@ -206,6 +215,14 @@ static inline struct pack_list * pack_list_insert(struct pack_list **pl, return p; } +static void pack_list_free(struct pack_list *pl) +{ + for (struct pack_list *next; pl; pl = next) { + next = pl->next; + free(pl); + } +} + static inline size_t pack_list_size(struct pack_list *pl) { size_t ret = 0; @@ -419,7 +436,8 @@ static void minimize(struct pack_list **min) /* return if there are no objects missing from the unique set */ if (missing->size == 0) { - free(missing); + llist_free(missing); + pack_list_free(non_unique); return; } @@ -434,6 +452,8 @@ static void minimize(struct pack_list **min) } while (non_unique) { + struct pack_list *next; + /* sort the non_unique packs, greater size of remaining_objects first */ sort_pack_list(&non_unique); if (non_unique->remaining_objects->size == 0) @@ -444,8 +464,14 @@ static void minimize(struct pack_list **min) for (pl = non_unique->next; pl && pl->remaining_objects->size > 0; pl = pl->next) llist_sorted_difference_inplace(pl->remaining_objects, non_unique->remaining_objects); - non_unique = non_unique->next; + next = non_unique->next; + free(non_unique); + non_unique = next; } + + pack_list_free(non_unique); + llist_free(unique_pack_objects); + llist_free(missing); } static void load_all_objects(void) @@ -565,7 +591,6 @@ static void load_all(void) int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) { int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl; struct llist *ignore; - struct object_id *oid; char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */ if (argc == 2 && !strcmp(argv[1], "-h")) @@ -625,11 +650,11 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s /* ignore objects given on stdin */ llist_init(&ignore); if (!isatty(0)) { + struct object_id oid; while (fgets(buf, sizeof(buf), stdin)) { - oid = xmalloc(sizeof(*oid)); - if (get_oid_hex(buf, oid)) + if (get_oid_hex(buf, &oid)) die("Bad object ID on stdin: %s", buf); - llist_insert_sorted_unique(ignore, oid, NULL); + llist_insert_sorted_unique(ignore, &oid, NULL); } } llist_sorted_difference_inplace(all_objects, ignore); @@ -671,5 +696,8 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s fprintf(stderr, "%luMB of redundant packs in total.\n", (unsigned long)pack_set_bytecount(red)/(1024*1024)); + pack_list_free(red); + pack_list_free(min); + llist_free(ignore); return 0; } diff --git a/t/t5323-pack-redundant.sh b/t/t5323-pack-redundant.sh index 8dbbcc5e51..4e18f5490a 100755 --- a/t/t5323-pack-redundant.sh +++ b/t/t5323-pack-redundant.sh @@ -34,6 +34,7 @@ relationship between packs and objects is as follows: Px2 | s s s x x x ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh main_repo=main.git From patchwork Mon Sep 30 09:13: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: 13815673 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 773F418787A for ; Mon, 30 Sep 2024 09:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687623; cv=none; b=Z1qzpcmhic/omzHH4v1hRMFQV7hI7O75GpFJuhNXOfDhYChzT9dkhtPw1Cso0h6yu38/ntjORjIbYYppUhlX6QunGx0uXOlk0gusa5mGmUeJ0LVLKhdC7VHfOk6yB293aHcfqcoaovtezlMYQfDqGGETvbRQdl9KqApNVnp8iSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687623; c=relaxed/simple; bh=IqaXnWst05klv64ylyjVaGZuxy1dAD373uK9UJLPWbY=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NlIeppFszhJm7jPMcE8vLsAO51d4qDkfQ6pv8VmmvrBeugimMWiLrOe30bLdxmpQsQEfNxYymoFIy2R7WSwqio9H46xwV8ypsqLhwDuFJGVph15wizURt5aTI8mLWvF2HpyXITb2mAnJpN+k3cXXS23D6a6NlTvyfME+JX7RXps= 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=BLYuukrD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eyA3B2QU; arc=none smtp.client-ip=103.168.172.159 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="BLYuukrD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eyA3B2QU" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id C3AD8114026E for ; Mon, 30 Sep 2024 05:13:40 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:13: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=fm2; t=1727687620; x=1727774020; bh=T7fZ6k1wSx J/Q+xdB+D/cxc88FRkZrFYLqAaP7U6l34=; b=BLYuukrD8TUj8sXwKHcxGOrGrU TEHIFUQ2+o928Y6+9mMytswMI/1ZRNsYd8izlqHCPnYifL7omY8/AW/D48aNYeKg qTnimNjtz6Ycqt2m2hmxrF/vsn87tjAudjYlWmclK04Sr67YBHPJtWVM1ewUXjBv F5jPeLYbuApKYciTuWvyK5zb7QUpUew16/Xonurvud+Os+Cqyl20fFnuBH+o2q1Q 2ba23aaR5gfPl/EuickXcmOlHuHD4eeh9hFo6Omz5Dm3RBvn4magZEpbbWtTncoF nJhYQS49ZUvp/4er0fylkiqdMeyMRvncc5rF1BKqGRrpqmmYAxsnmLDCFYWA== 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= fm2; t=1727687620; x=1727774020; bh=T7fZ6k1wSxJ/Q+xdB+D/cxc88FRk ZrFYLqAaP7U6l34=; b=eyA3B2QUjDO+cubNvLv0eNIKiFqnQgPSTUPxMjhp82RU G5tcUs68/Z4ivL3TakW1J5VKxC8sZDa+MJyz0+fCgIW72JGELW06R1Vpew5Z+SWT k/TxhJpZ+z7eyEGLgx2RADlX+U20/jXWTuW0GLiIBdj+NfKKyovlWyOvCkqPXxVj 6MoTRy2SRWxKykyLvATeoDyKM8z3Xap+gwXEKDCjwkJqO0uJ92E2fMoTScTRPqJP Xj0mKtAYwhZIb6H9nm1+iJ2p/8f9yzMUpkNE7UJbrJWbgUTj8INSbql+4KuLsfU2 /GS7E0cQmLK37ACt0yPJiFNgCRtmB6WCLiPNXSaCwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepfffgkeetffeule eivdeltefgfffhleevkedttefhledtleffiedvgfduheegfeefnecuffhomhgrihhnpehh thhtphdrshhhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 586af1c3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:54 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/23] builtin/clone: fix leaking repo state when cloning with bundle URIs Message-ID: <2fa76a00fc0469d0c64c66e81b96d622844b8f0d.1727687410.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 cloning with bundle URIs we re-initialize `the_repository` after having fetched the bundle. This causes a bunch of memory leaks though because we do not release its previous state. These leaks can be plugged by calling `repo_clear()` before we call `repo_init()`. But this causes another issue because the remote that we used is tied to the lifetime of the repository's remote state, which would also get released. We thus have to make sure that it does not get free'd under our feet. Signed-off-by: Patrick Steinhardt --- builtin/clone.c | 27 ++++++++++++++++++++++++++ t/t5730-protocol-v2-bundle-uri-file.sh | 1 + t/t5731-protocol-v2-bundle-uri-git.sh | 1 + t/t5732-protocol-v2-bundle-uri-http.sh | 1 + 4 files changed, 30 insertions(+) diff --git a/builtin/clone.c b/builtin/clone.c index e77339c847..59fcb317a6 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1403,8 +1403,17 @@ int cmd_clone(int argc, * data from the --bundle-uri option. */ if (bundle_uri) { + struct remote_state *state; int has_heuristic = 0; + /* + * We need to save the remote state as our remote's lifetime is + * tied to it. + */ + state = the_repository->remote_state; + the_repository->remote_state = NULL; + repo_clear(the_repository); + /* At this point, we need the_repository to match the cloned repo. */ if (repo_init(the_repository, git_dir, work_tree)) warning(_("failed to initialize the repo, skipping bundle URI")); @@ -1413,6 +1422,10 @@ int cmd_clone(int argc, bundle_uri); else if (has_heuristic) git_config_set_gently("fetch.bundleuri", bundle_uri); + + remote_state_clear(the_repository->remote_state); + free(the_repository->remote_state); + the_repository->remote_state = state; } else { /* * Populate transport->got_remote_bundle_uri and @@ -1422,12 +1435,26 @@ int cmd_clone(int argc, if (transport->bundles && hashmap_get_size(&transport->bundles->bundles)) { + struct remote_state *state; + + /* + * We need to save the remote state as our remote's + * lifetime is tied to it. + */ + state = the_repository->remote_state; + the_repository->remote_state = NULL; + repo_clear(the_repository); + /* At this point, we need the_repository to match the cloned repo. */ if (repo_init(the_repository, git_dir, work_tree)) warning(_("failed to initialize the repo, skipping bundle URI")); else if (fetch_bundle_list(the_repository, transport->bundles)) warning(_("failed to fetch advertised bundles")); + + remote_state_clear(the_repository->remote_state); + free(the_repository->remote_state); + the_repository->remote_state = state; } else { clear_bundle_list(transport->bundles); FREE_AND_NULL(transport->bundles); diff --git a/t/t5730-protocol-v2-bundle-uri-file.sh b/t/t5730-protocol-v2-bundle-uri-file.sh index 37bdb725bc..38396df95b 100755 --- a/t/t5730-protocol-v2-bundle-uri-file.sh +++ b/t/t5730-protocol-v2-bundle-uri-file.sh @@ -7,6 +7,7 @@ TEST_NO_CREATE_REPO=1 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test protocol v2 with 'file://' transport diff --git a/t/t5731-protocol-v2-bundle-uri-git.sh b/t/t5731-protocol-v2-bundle-uri-git.sh index 8add1b37ab..c199e955fe 100755 --- a/t/t5731-protocol-v2-bundle-uri-git.sh +++ b/t/t5731-protocol-v2-bundle-uri-git.sh @@ -7,6 +7,7 @@ TEST_NO_CREATE_REPO=1 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test protocol v2 with 'git://' transport diff --git a/t/t5732-protocol-v2-bundle-uri-http.sh b/t/t5732-protocol-v2-bundle-uri-http.sh index 129daa0226..a9403e94c6 100755 --- a/t/t5732-protocol-v2-bundle-uri-http.sh +++ b/t/t5732-protocol-v2-bundle-uri-http.sh @@ -7,6 +7,7 @@ TEST_NO_CREATE_REPO=1 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test protocol v2 with 'http://' transport From patchwork Mon Sep 30 09:13: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: 13815674 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 55B131885A1 for ; Mon, 30 Sep 2024 09:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687625; cv=none; b=cTyQzaF4Ir1POoc/Dc+8/mSu7qQp+vYVzGiZDuLGr9zasZo/TqBzzojavAJ0wDdYNwKmswMFr4Xv/XoOUEqH58YWjJZnv6j2xyepoZteB2o/8agX6FCbFw6e1fAKzfSKFuMxLfGHntiQ7qnqpEZ3aWtOrtpQmYcMqCUZYp697wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687625; c=relaxed/simple; bh=h3fwPXDOHy6lIi9z92LFBEHQ+ELo36130Al/75rK8AA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=REpdlgZqbTsEK4gOB6xjSVo8N2D+Y7vrVUvJwslWfW5kXGAL8oEYL5TZHHahUiej6rjlKeAGbsj79ZiOMhYcrVOYKRliG5X+Mi2quz7bhBAjbKJyS5fg8201R94MOkFb9DLF2Z8MGcC8EYHOii2RfTz4JEdpu863wRcvBNwjXtc= 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=Da4QRNOH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ayIpygiE; arc=none smtp.client-ip=103.168.172.159 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="Da4QRNOH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ayIpygiE" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id A8DA31140259 for ; Mon, 30 Sep 2024 05:13:43 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Mon, 30 Sep 2024 05:13: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=fm2; t=1727687623; x=1727774023; bh=ixRb5vdiUm ZSNwMuIoNE1GxAN82oLI8VTsFxgLlEpg8=; b=Da4QRNOHo07hr9nvT6HTdJgITI 9QtawW1SgzrAU9no4E+jbwmca/8IZAcNqJBc5xPQceZ/MJ6eir3wCe5UhLKUiHg5 8axI99/gIVh0+Qrb5LpDsO0U8uagSz4qTqCul2kYs32QXLU34S5HutUVYEB7rOA5 mZ/ihFhmIiFMv6j8+tvcABze2n9c/tKmNvT/m919SVM9g+hT6PpZkAbvWmURMzRy lkcYenyk/5lRSDt5fJ9IOl/1QTnVS4m4LmHxmu3PMEk1JCFegB9Cb4r9W+lZoqHn cBVVEZ8+64XVXZzdkWtYsZaKNbwMdKGKyYEkxVNHCOp5QhXkL7rCM6iO3n+A== 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= fm2; t=1727687623; x=1727774023; bh=ixRb5vdiUmZSNwMuIoNE1GxAN82o LI8VTsFxgLlEpg8=; b=ayIpygiEBnW3NoqemRhR/GZ9Hwnk4g82VHDs972VQL10 mSnZ154uBFD5hKnj+G7A0ic5FpOcvLvFQJPpJz5VMgJ2+6bOI0hzZ+xdjXVdzLyG IRXtQtwoS62b3HUYK1WNnjPvCGWKWQcoho1Sa0ioQx+VGc3GJ/cuSxfHEsfpdy5E Qc51pBSrkMkvGCHxsEW6T75jwA72p1L4IEHeLTg92jWIwikOIp3Lr2BX8zB/RZU3 IjJPMrmXyP46uSRdB0Rw7t6ehaepOKBaZjLL1kjxP369PWxYiMvZSArNMwJiM4A6 b/xdqP5oXVZaCpBxHYJ1R1gdsMxx2itW1mIJsKin9A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:42 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 41e651e7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:57 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/23] t/helper: fix leaking repository in partial-clone helper 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 initialize but never clear a repository in the partial-clone test helper. Plug this leak. Signed-off-by: Patrick Steinhardt --- t/helper/test-partial-clone.c | 2 ++ t/t0410-partial-clone.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c index 0ead529167..a1af9710c3 100644 --- a/t/helper/test-partial-clone.c +++ b/t/helper/test-partial-clone.c @@ -26,6 +26,8 @@ static void object_info(const char *gitdir, const char *oid_hex) if (oid_object_info_extended(&r, &oid, &oi, 0)) die("could not obtain object info"); printf("%d\n", (int) size); + + repo_clear(&r); } int cmd__partial_clone(int argc, const char **argv) diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index 34bdb3ab1f..818700fbec 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -2,6 +2,7 @@ test_description='partial clone' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh From patchwork Mon Sep 30 09:13:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815675 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 7B37C186E39 for ; Mon, 30 Sep 2024 09:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687628; cv=none; b=o5tz2d01ugpsuReOqnu1eok4l5WlCWmhRHR7rY7ICI4z51VAmJD3WuS1c+QP46xWrPXdJ+XPrw3ex+tZQjcvD0n44rnEEu2is5J28Drm82XGkI+1y5+VVOVRHK+V0BgoWlW/ka8alPE9bm+KYI/12kxesTE7OurSXhBTYbXSN2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687628; c=relaxed/simple; bh=+DZeLpfnFIJnxA7zZrVmwqd6sJl2CBAIZ4tTSvLPWJA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pBF6Ggl4LOYwn7n2FLuq67c4bog+d8HQ+731GdbSfwwA3EJ6XoCLPA0dIzf5/Pc8TpsG8TbJCRbsD/CSu1Wo0CIbFAGJEgw0xNuVQUQrmvVZL4UESf0OaXTyCNJf4tt+OWysAIPtwuWv4HtKgsvBiDLGH3kx1do1g5/NZiaGTs8= 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=ZJahBWbN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=II9qaFFE; arc=none smtp.client-ip=103.168.172.159 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="ZJahBWbN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="II9qaFFE" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8E87C1140260 for ; Mon, 30 Sep 2024 05:13:46 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Mon, 30 Sep 2024 05:13: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=fm2; t=1727687626; x=1727774026; bh=rClL9CX3mV RJPnEM1h71xOM6qF8QQaIApqNSzKmtjuk=; b=ZJahBWbNa5hcPZuGnjBY3BbiTd tWvsSVj9p1MZo9jV4EwWiOMlSQbEhHE/rg7MH9nifh1PL4g4GmqyboQDtd9DYic7 +Wh9HNkS1P6lipy5Q15aK/Fe0jAw0sdGgr5rOBMWGqqfh3n+/XEq9iOV0orGngS1 2RFmVlaHyrhxE8GGQoXbBFe3dMbT5X2YeTpmKWAnC8/joeaOmJfosH9kHbV6SSb0 PSnEMvA6WorBF6tKVdFAvDxURvq9c3ALg8FQtdk3j+LUyc+e21wLvcoEh8kiX/wh mNjLDjy8ovi+LE5FeIU6yWDWWnC8XwdaEc7GbtgK6m7Zb6Jpd8th37Ie9aUg== 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= fm2; t=1727687626; x=1727774026; bh=rClL9CX3mVRJPnEM1h71xOM6qF8Q QaIApqNSzKmtjuk=; b=II9qaFFEaWQwAHZ0Us7o/LXkpj5FHOUMfqrJYT6hLddy LbHwkc6XW7IyUuwJ+SkLS6XxZ3ikmPevnVqO1C6KDS6egbxh6m+Kp8UusNUhDm8o KfShjeiVvRgiTCV9Rjvb8F+2T6dk6QVUWH825QP8brQoeVczUv7LxEbP0Q6IO1p0 JeNz0G9OtbnfzpjX96Nvz89gyejCchETUIyD8HIX1GXJBEHNbraLsc5i5iE3hF/P 2Xo+88kdYjgFrOZheqeslQRdBV6uQ8AZDem/EmJFdExzv9RMWm/x4n3MJ95WiOIx uY2fonfqUzgWThmMeakta7/Pgs5DjUt2FWK5rDqhQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9d56d597 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:12:59 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/23] builtin/revert: fix leaking `gpg_sign` and `strategy` config Message-ID: <3177c449206c802239720479bc070df7a22b0d0e.1727687410.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 leak the config values when `gpg_sign` or `strategy` options are being overridden via the command line. To fix this we need to free the old value, which requires us to figure out whether the value was changed via an option in the first place. The easy way to do this, which is to initialize local variables with `NULL`, doesn't work because we cannot tell the case where the user has passed e.g. `--no-gpg-sign`. Instead, we use a sentinel value for both values that we can compare against to check whether the user has passed the option. Signed-off-by: Patrick Steinhardt --- builtin/revert.c | 17 +++++++++++++---- t/t3514-cherry-pick-revert-gpg.sh | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index 55ba1092c5..b7917dddd3 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -110,6 +110,9 @@ static int run_sequencer(int argc, const char **argv, const char *prefix, const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); const char *cleanup_arg = NULL; + const char sentinel_value; + const char *strategy = &sentinel_value; + const char *gpg_sign = &sentinel_value; enum empty_action empty_opt = EMPTY_COMMIT_UNSPECIFIED; int cmd = 0; struct option base_options[] = { @@ -125,10 +128,10 @@ static int run_sequencer(int argc, const char **argv, const char *prefix, OPT_CALLBACK('m', "mainline", opts, N_("parent-number"), N_("select mainline parent"), option_parse_m), OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto), - OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")), + OPT_STRING(0, "strategy", &strategy, N_("strategy"), N_("merge strategy")), OPT_STRVEC('X', "strategy-option", &opts->xopts, N_("option"), N_("option for merge strategy")), - { OPTION_STRING, 'S', "gpg-sign", &opts->gpg_sign, N_("key-id"), + { OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, OPT_END() }; @@ -240,8 +243,14 @@ static int run_sequencer(int argc, const char **argv, const char *prefix, usage_with_options(usage_str, options); /* These option values will be free()d */ - opts->gpg_sign = xstrdup_or_null(opts->gpg_sign); - opts->strategy = xstrdup_or_null(opts->strategy); + if (gpg_sign != &sentinel_value) { + free(opts->gpg_sign); + opts->gpg_sign = xstrdup_or_null(gpg_sign); + } + if (strategy != &sentinel_value) { + free(opts->strategy); + opts->strategy = xstrdup_or_null(strategy); + } if (!opts->strategy && getenv("GIT_TEST_MERGE_ALGORITHM")) opts->strategy = xstrdup(getenv("GIT_TEST_MERGE_ALGORITHM")); free(options); diff --git a/t/t3514-cherry-pick-revert-gpg.sh b/t/t3514-cherry-pick-revert-gpg.sh index 5b2e250eaa..133dc07217 100755 --- a/t/t3514-cherry-pick-revert-gpg.sh +++ b/t/t3514-cherry-pick-revert-gpg.sh @@ -5,6 +5,7 @@ test_description='test {cherry-pick,revert} --[no-]gpg-sign' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" From patchwork Mon Sep 30 09:13: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: 13815676 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 30AD318873D for ; Mon, 30 Sep 2024 09:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687632; cv=none; b=abj6pCEHr155i7JZ28e9aSKCiYPG3qZDditwVQSzNHktgJOvou/xFReo8hm4bDd3C8nczu/UkJEfyxQ3daqfgsEL9ftRmfrNStlH/Ovj6fWpz01cPxV243eaZXO837PZueLCJdRa5HW+eUbEBR/cfyY1ij+97VtIhZEzvRrtvvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687632; c=relaxed/simple; bh=xFLAuXOQ7tEISg+ooFnAA9mSSVyfW5FXp3wxDKnyTlw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zy/CX/j6q1ZOVL5EFOFXEvUcg/rH37wbk+LAdesZLnCbXVqmp5y1IzARKCyDZrbINAvtZqAeUF2P1QQ/EnOxOPjRMIiKn0IqwtsuRzGs6IfwF+ZjfIM2QXtBV8E1mqAsBNtsTIWVViYw1goy/87BJX1g7itd2Nz3mCDSFtFMRjM= 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=KBYsFMAQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Gr01JBeV; arc=none smtp.client-ip=103.168.172.159 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="KBYsFMAQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Gr01JBeV" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 69E7B114026A for ; Mon, 30 Sep 2024 05:13:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 05:13:49 -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=fm2; t=1727687629; x=1727774029; bh=hsQ8jnMUZu W7rwYaT0StV6Kb9gNFFAzQ2lbG1n2g0fU=; b=KBYsFMAQYdH+/hSrK/2Gb40T0H sODhcA6w5+r/d/okUT4Vj/7inyNtI62qZn+B8NwPWQ9dkTaFAZaIpmE6CcstQAIN 0w5XXBpC2ERFG68/GwB4zsqp0Xlsx+fikg4jzGW2jRu3J3eAETZDmt/bAoiyURZu 9T4onAgMn5+1zC0OlIAv/rjY2RH7PXoI704HmpIC79kfiQ2LIN7OQLFmnejVpSQj dJ+88wFan82E1kdj7D3KbWVCHSRH5Cd375lYEkIcXI4C/cz/pf+CGBEOYOPJtjM+ eolvqk6xzHh3egY/yEbtT1gnpN68v/EI4F0rlUVJ6YFTF8o20c1F/JHG9oYQ== 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= fm2; t=1727687629; x=1727774029; bh=hsQ8jnMUZuW7rwYaT0StV6Kb9gNF FAzQ2lbG1n2g0fU=; b=Gr01JBeVe3uzcZVYuvm8GEoqwMplhWppYUswl8YF2U/5 aQQQgo244nuOZPiwwaKoeHzctvZP7JK9NGumK4E/8AhcZ6J3f4YYPnvsVFzhvxBl bkjO0PtHhCKjCjG29dTBz80Ep6KGTsVD9Ucust6qGgtoUfwtwboWCMINF439gsxs f/WAzwlV4mBN0po6SfOQ+HQrFMSbjk+G+N/gimq+c+qkWXbQ55BtDQBVwdG1kfnz O2qdKd80d8YN/S68qW8UOeUKK0zrsT60DR6kWmXNAIWJ9ExWeuCOfOem9wUmB4VH 5zCCF8DJgImpYiCiZqQVczaocYa7wRen2W+I3xAmHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1a850a1c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:02 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/23] diff: improve lifecycle management of diff queues 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 lifecycle management of diff queues is somewhat confusing: - For most of the part this can be attributed to `DIFF_QUEUE_CLEAR()`, which does not release any memory but rather initializes the queue, only. This is in contrast to our common naming schema, where "clearing" means that we release underlying memory and then re-initialize the data structure such that it is ready to use. - A second offender is `diff_free_queue()`, which does not free the queue structure itself. It is rather a release-style function. Refactor the code to make things less confusing. `DIFF_QUEUE_CLEAR()` is replaced by `DIFF_QUEUE_INIT` and `diff_queue_init()`, while `diff_free_queue()` is replaced by `diff_queue_release()`. While on it, adapt callsites where we call `DIFF_QUEUE_CLEAR()` with the intent to release underlying memory to instead call `diff_queue_clear()` to fix memory leaks. This memory leak is exposed by t4211, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- bloom.c | 8 +------- diff.c | 22 ++++++++++++---------- diffcore-break.c | 8 ++------ diffcore-pickaxe.c | 4 +--- diffcore-rename.c | 3 +-- diffcore-rotate.c | 3 +-- diffcore.h | 10 ++++------ line-log.c | 15 +++++++-------- log-tree.c | 4 ++-- merge-ort.c | 2 +- 10 files changed, 32 insertions(+), 47 deletions(-) diff --git a/bloom.c b/bloom.c index c915f8b1ba..c428634105 100644 --- a/bloom.c +++ b/bloom.c @@ -476,8 +476,6 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, *last_slash = '\0'; } while (*path); - - diff_free_filepair(diff_queued_diff.queue[i]); } if (hashmap_get_size(&pathmap) > settings->max_changed_paths) { @@ -508,8 +506,6 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, cleanup: hashmap_clear_and_free(&pathmap, struct pathmap_hash_entry, entry); } else { - for (i = 0; i < diff_queued_diff.nr; i++) - diff_free_filepair(diff_queued_diff.queue[i]); init_truncated_large_filter(filter, settings->hash_version); if (computed) @@ -519,9 +515,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, if (computed) *computed |= BLOOM_COMPUTED; - free(diff_queued_diff.queue); - DIFF_QUEUE_CLEAR(&diff_queued_diff); - + diff_queue_clear(&diff_queued_diff); return filter; } diff --git a/diff.c b/diff.c index 173cbe2bed..3e9137ffed 100644 --- a/diff.c +++ b/diff.c @@ -5983,11 +5983,18 @@ void diff_free_filepair(struct diff_filepair *p) free(p); } -void diff_free_queue(struct diff_queue_struct *q) +void diff_queue_init(struct diff_queue_struct *q) +{ + struct diff_queue_struct blank = DIFF_QUEUE_INIT; + memcpy(q, &blank, sizeof(*q)); +} + +void diff_queue_clear(struct diff_queue_struct *q) { for (int i = 0; i < q->nr; i++) diff_free_filepair(q->queue[i]); free(q->queue); + diff_queue_init(q); } const char *diff_aligned_abbrev(const struct object_id *oid, int len) @@ -6551,8 +6558,7 @@ int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int struct diff_queue_struct *q = &diff_queued_diff; int result = diff_get_patch_id(options, oid, diff_header_only); - diff_free_queue(q); - DIFF_QUEUE_CLEAR(q); + diff_queue_clear(q); return result; } @@ -6835,8 +6841,7 @@ void diff_flush(struct diff_options *options) } free_queue: - diff_free_queue(q); - DIFF_QUEUE_CLEAR(q); + diff_queue_clear(q); diff_free(options); /* @@ -6867,9 +6872,7 @@ static void diffcore_apply_filter(struct diff_options *options) { int i; struct diff_queue_struct *q = &diff_queued_diff; - struct diff_queue_struct outq; - - DIFF_QUEUE_CLEAR(&outq); + struct diff_queue_struct outq = DIFF_QUEUE_INIT; if (!options->filter) return; @@ -6962,8 +6965,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt) { int i; struct diff_queue_struct *q = &diff_queued_diff; - struct diff_queue_struct outq; - DIFF_QUEUE_CLEAR(&outq); + struct diff_queue_struct outq = DIFF_QUEUE_INIT; for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; diff --git a/diffcore-break.c b/diffcore-break.c index 02735f80c6..c4c2173f30 100644 --- a/diffcore-break.c +++ b/diffcore-break.c @@ -131,7 +131,7 @@ static int should_break(struct repository *r, void diffcore_break(struct repository *r, int break_score) { struct diff_queue_struct *q = &diff_queued_diff; - struct diff_queue_struct outq; + struct diff_queue_struct outq = DIFF_QUEUE_INIT; /* When the filepair has this much edit (insert and delete), * it is first considered to be a rewrite and broken into a @@ -178,8 +178,6 @@ void diffcore_break(struct repository *r, int break_score) if (!merge_score) merge_score = DEFAULT_MERGE_SCORE; - DIFF_QUEUE_CLEAR(&outq); - for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; int score; @@ -275,11 +273,9 @@ static void merge_broken(struct diff_filepair *p, void diffcore_merge_broken(void) { struct diff_queue_struct *q = &diff_queued_diff; - struct diff_queue_struct outq; + struct diff_queue_struct outq = DIFF_QUEUE_INIT; int i, j; - DIFF_QUEUE_CLEAR(&outq); - for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; if (!p) diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index b195fa4eb3..43fef8e8ba 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -182,9 +182,7 @@ static void pickaxe(struct diff_queue_struct *q, struct diff_options *o, regex_t *regexp, kwset_t kws, pickaxe_fn fn) { int i; - struct diff_queue_struct outq; - - DIFF_QUEUE_CLEAR(&outq); + struct diff_queue_struct outq = DIFF_QUEUE_INIT; if (o->pickaxe_opts & DIFF_PICKAXE_ALL) { /* Showing the whole changeset if needle exists */ diff --git a/diffcore-rename.c b/diffcore-rename.c index 3d6826baa3..1b1c1a6a1f 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -1388,7 +1388,7 @@ void diffcore_rename_extended(struct diff_options *options, int detect_rename = options->detect_rename; int minimum_score = options->rename_score; struct diff_queue_struct *q = &diff_queued_diff; - struct diff_queue_struct outq; + struct diff_queue_struct outq = DIFF_QUEUE_INIT; struct diff_score *mx; int i, j, rename_count, skip_unmodified = 0; int num_destinations, dst_cnt; @@ -1638,7 +1638,6 @@ void diffcore_rename_extended(struct diff_options *options, * are recorded in rename_dst. The original list is still in *q. */ trace2_region_enter("diff", "write back to queue", options->repo); - DIFF_QUEUE_CLEAR(&outq); for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; struct diff_filepair *pair_to_free = NULL; diff --git a/diffcore-rotate.c b/diffcore-rotate.c index 533986cf63..73ca20b331 100644 --- a/diffcore-rotate.c +++ b/diffcore-rotate.c @@ -10,7 +10,7 @@ void diffcore_rotate(struct diff_options *opt) { struct diff_queue_struct *q = &diff_queued_diff; - struct diff_queue_struct outq; + struct diff_queue_struct outq = DIFF_QUEUE_INIT; int rotate_to, i; if (!q->nr) @@ -31,7 +31,6 @@ void diffcore_rotate(struct diff_options *opt) return; } - DIFF_QUEUE_CLEAR(&outq); rotate_to = i; for (i = rotate_to; i < q->nr; i++) diff --git a/diffcore.h b/diffcore.h index 1701ed50b9..2feb325031 100644 --- a/diffcore.h +++ b/diffcore.h @@ -153,18 +153,16 @@ struct diff_queue_struct { int nr; }; -#define DIFF_QUEUE_CLEAR(q) \ - do { \ - (q)->queue = NULL; \ - (q)->nr = (q)->alloc = 0; \ - } while (0) +#define DIFF_QUEUE_INIT { 0 } + +void diff_queue_init(struct diff_queue_struct *q); +void diff_queue_clear(struct diff_queue_struct *q); extern struct diff_queue_struct diff_queued_diff; struct diff_filepair *diff_queue(struct diff_queue_struct *, struct diff_filespec *, struct diff_filespec *); void diff_q(struct diff_queue_struct *, struct diff_filepair *); -void diff_free_queue(struct diff_queue_struct *q); /* dir_rename_relevance: the reason we want rename information for a dir */ enum dir_rename_relevance { diff --git a/line-log.c b/line-log.c index 67c80b39a0..89e0ea4562 100644 --- a/line-log.c +++ b/line-log.c @@ -787,15 +787,14 @@ static void move_diff_queue(struct diff_queue_struct *dst, struct diff_queue_struct *src) { assert(src != dst); - memcpy(dst, src, sizeof(struct diff_queue_struct)); - DIFF_QUEUE_CLEAR(src); + memcpy(dst, src, sizeof(*dst)); + diff_queue_init(src); } static void filter_diffs_for_paths(struct line_log_data *range, int keep_deletions) { int i; - struct diff_queue_struct outq; - DIFF_QUEUE_CLEAR(&outq); + struct diff_queue_struct outq = DIFF_QUEUE_INIT; for (i = 0; i < diff_queued_diff.nr; i++) { struct diff_filepair *p = diff_queued_diff.queue[i]; @@ -850,12 +849,12 @@ static void queue_diffs(struct line_log_data *range, clear_pathspec(&opt->pathspec); parse_pathspec_from_ranges(&opt->pathspec, range); } - DIFF_QUEUE_CLEAR(&diff_queued_diff); + diff_queue_clear(&diff_queued_diff); diff_tree_oid(parent_tree_oid, tree_oid, "", opt); if (opt->detect_rename && diff_might_be_rename()) { /* must look at the full tree diff to detect renames */ clear_pathspec(&opt->pathspec); - DIFF_QUEUE_CLEAR(&diff_queued_diff); + diff_queue_clear(&diff_queued_diff); diff_tree_oid(parent_tree_oid, tree_oid, "", opt); @@ -1097,7 +1096,7 @@ static struct diff_filepair *diff_filepair_dup(struct diff_filepair *pair) static void free_diffqueues(int n, struct diff_queue_struct *dq) { for (int i = 0; i < n; i++) - diff_free_queue(&dq[i]); + diff_queue_clear(&dq[i]); free(dq); } @@ -1200,7 +1199,7 @@ static int process_ranges_ordinary_commit(struct rev_info *rev, struct commit *c if (parent) add_line_range(rev, parent, parent_range); free_line_log_data(parent_range); - diff_free_queue(&queue); + diff_queue_clear(&queue); return changed; } diff --git a/log-tree.c b/log-tree.c index 3758e0d3b8..60774c16b3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -675,7 +675,7 @@ static void show_diff_of_diff(struct rev_info *opt) struct diff_queue_struct dq; memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff)); - DIFF_QUEUE_CLEAR(&diff_queued_diff); + diff_queue_init(&diff_queued_diff); fprintf_ln(opt->diffopt.file, "\n%s", opt->idiff_title); show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2, @@ -694,7 +694,7 @@ static void show_diff_of_diff(struct rev_info *opt) }; memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff)); - DIFF_QUEUE_CLEAR(&diff_queued_diff); + diff_queue_init(&diff_queued_diff); fprintf_ln(opt->diffopt.file, "\n%s", opt->rdiff_title); /* diff --git a/merge-ort.c b/merge-ort.c index 8b81153e8f..11029c10be 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -3536,7 +3536,7 @@ static int detect_and_process_renames(struct merge_options *opt) /* Free memory for renames->pairs[] and combined */ for (s = MERGE_SIDE1; s <= MERGE_SIDE2; s++) { free(renames->pairs[s].queue); - DIFF_QUEUE_CLEAR(&renames->pairs[s]); + diff_queue_init(&renames->pairs[s]); } for (i = 0; i < combined.nr; i++) pool_diff_free_filepair(&opt->priv->pool, combined.queue[i]); From patchwork Mon Sep 30 09:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815677 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 089A918892F for ; Mon, 30 Sep 2024 09:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687634; cv=none; b=PNUtJoKnzpJEfkaNwoWluYA19G3Zm5ynSQOLNFGaiZBWp0xwp1+xHbr1jZ4UcbUWk5i1dYBi10tbj26ZA8Zd1BCnOc5M9D1LppZIU2pcVwfG7rQ1/ZdNZjIhQyCuekK8LQVCOJ3tH7tFSQzGTjT76FJUstT4V3ZVL8RaKaZme88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687634; c=relaxed/simple; bh=tIjyd92U/zjhAzxQ174Uh0LVYzjb7xvYHNpcZrVj9Yc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KY6KnbMVLbbblX9lU/j+p8c62Ur7pFCck8lN48iiU/zjDFnFHdI4j/OfbxUPs8QLcQySuoSjg2Wr9vTLVwpaCe/mZ/gw0VHAXMGpBDApFaqpMuVoAl64wHFnc9tCioS9vhTmOzDLySzVRWDs/cdHPWN3vLfE49vwFVM4HCwD27U= 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=njunO4vm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iGoulgdG; arc=none smtp.client-ip=103.168.172.145 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="njunO4vm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iGoulgdG" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 44B8213803A6 for ; Mon, 30 Sep 2024 05:13:52 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 05:13: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=fm2; t=1727687632; x=1727774032; bh=lSu7ojzHzx w0l63Gw41WQmmw9/lZt3eXDeVkUcX2bms=; b=njunO4vm01TabnOUSNizWmiFhS cyowdxZSplq4GApLtlobTdpc6pGuQ2d88gK4pxnpW3D+x2O0I8dOz+PbVNFJcZgN ehQ7Nr9hUBcDNLk58KHVuzq6HO1njPER9FPhTq3zTnxiez7nt8LDTmedHOv9WS94 Y66w968vY+wI3n3okYVMaF3opQYEokuGw/v36PQeCl5kM+j6gGJPcOU5YVqA9PyD 6aE2WSAPMLHU/KJe2snFrZIvzQNAsWfC37Mo9iBJI98l8Kn1Vax7Yw4p37KXpn0B DWKagw1WvvYr7/a/odCZWRzE+qCiL7UeGCa8uq7yDaNVx8whOagw9R4rQCyg== 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= fm2; t=1727687632; x=1727774032; bh=lSu7ojzHzxw0l63Gw41WQmmw9/lZ t3eXDeVkUcX2bms=; b=iGoulgdGFcYpSNapH6dIhJGcAbDmbYDKUAJ/pUsN93mJ 3c5OlyZIQayl3dyLW99uwMP4hqOFEYrpwkqBrcXQWRiWlADDEFt6U9u3YMbfmttY 6wYXNaDzF1JF6sqr/H8SuKo6toZl8dBZ9PhqWZZl/3aPcUMg/uBj7vw/iSMUiBvL quZYcUgJw4xdoM3pmhtm6gnDifZ80nWnYWgWNmTSuZzlB5vbtsnSj5tIvDSTuJ1+ HnRehxFbzyrvO+cOnxq8LKPPWcRQeWdCLQIQOYCWq52FMIqSeva34/ErSGeECkp4 4TYO5/3Kn1Beoo6xWc/T+gFODUBg9WHSm4M/BaAPSQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:51 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3ed19c60 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:05 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 13/23] line-log: fix several 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: As described in "line-log.c" itself, the code is "leaking like a sieve". These leaks are all of rather trivial nature, so this commit plugs them without going too much into details for each of those leaks. The leaks are hit by t4211, but plugging them alone does not make the full test suite pass. The remaining leaks are unrelated to the line-log subsystem. Signed-off-by: Patrick Steinhardt --- line-log.c | 54 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/line-log.c b/line-log.c index 89e0ea4562..ee48988c66 100644 --- a/line-log.c +++ b/line-log.c @@ -248,8 +248,10 @@ static void line_log_data_init(struct line_log_data *r) static void line_log_data_clear(struct line_log_data *r) { range_set_release(&r->ranges); + free(r->path); if (r->pair) diff_free_filepair(r->pair); + diff_ranges_release(&r->diff); } static void free_line_log_data(struct line_log_data *r) @@ -571,7 +573,8 @@ parse_lines(struct repository *r, struct commit *commit, struct line_log_data *p; for_each_string_list_item(item, args) { - const char *name_part, *range_part; + const char *name_part; + char *range_part; char *full_name; struct diff_filespec *spec; long begin = 0, end = 0; @@ -615,6 +618,7 @@ parse_lines(struct repository *r, struct commit *commit, free_filespec(spec); FREE_AND_NULL(ends); + free(range_part); } for (p = ranges; p; p = p->next) @@ -760,15 +764,13 @@ static void parse_pathspec_from_ranges(struct pathspec *pathspec, { struct line_log_data *r; struct strvec array = STRVEC_INIT; - const char **paths; for (r = range; r; r = r->next) strvec_push(&array, r->path); - paths = strvec_detach(&array); - parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", paths); - /* strings are now owned by pathspec */ - free(paths); + parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", array.v); + + strvec_clear(&array); } void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args) @@ -781,6 +783,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list add_line_range(rev, commit, range); parse_pathspec_from_ranges(&rev->diffopt.pathspec, range); + + free_line_log_data(range); } static void move_diff_queue(struct diff_queue_struct *dst, @@ -1131,10 +1135,18 @@ static int process_all_files(struct line_log_data **range_out, while (rg && strcmp(rg->path, pair->two->path)) rg = rg->next; assert(rg); + if (rg->pair) + diff_free_filepair(rg->pair); rg->pair = diff_filepair_dup(queue->queue[i]); + diff_ranges_release(&rg->diff); memcpy(&rg->diff, pairdiff, sizeof(struct diff_ranges)); + FREE_AND_NULL(pairdiff); + } + + if (pairdiff) { + diff_ranges_release(pairdiff); + free(pairdiff); } - free(pairdiff); } return changed; @@ -1212,12 +1224,13 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm struct commit_list *p; int i; int nparents = commit_list_count(commit->parents); + int ret; if (nparents > 1 && rev->first_parent_only) nparents = 1; ALLOC_ARRAY(diffqueues, nparents); - ALLOC_ARRAY(cand, nparents); + CALLOC_ARRAY(cand, nparents); ALLOC_ARRAY(parents, nparents); p = commit->parents; @@ -1229,7 +1242,6 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm for (i = 0; i < nparents; i++) { int changed; - cand[i] = NULL; changed = process_all_files(&cand[i], rev, &diffqueues[i], range); if (!changed) { /* @@ -1237,13 +1249,10 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm * don't follow any other path in history */ add_line_range(rev, parents[i], cand[i]); - clear_commit_line_range(rev, commit); commit_list_append(parents[i], &commit->parents); - free(parents); - free(cand); - free_diffqueues(nparents, diffqueues); - /* NEEDSWORK leaking like a sieve */ - return 0; + + ret = 0; + goto out; } } @@ -1251,18 +1260,25 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm * No single parent took the blame. We add the candidates * from the above loop to the parents. */ - for (i = 0; i < nparents; i++) { + for (i = 0; i < nparents; i++) add_line_range(rev, parents[i], cand[i]); - } + ret = 1; + +out: clear_commit_line_range(rev, commit); free(parents); + for (i = 0; i < nparents; i++) { + if (!cand[i]) + continue; + line_log_data_clear(cand[i]); + free(cand[i]); + } free(cand); free_diffqueues(nparents, diffqueues); - return 1; + return ret; /* NEEDSWORK evil merge detection stuff */ - /* NEEDSWORK leaking like a sieve */ } int line_log_process_ranges_arbitrary_commit(struct rev_info *rev, struct commit *commit) From patchwork Mon Sep 30 09:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815678 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 D3FD6186E3F for ; Mon, 30 Sep 2024 09:13:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687636; cv=none; b=L81RIvwhLlb8pogMdOa66jpdDXB5Rr9+6HpLjkCSbze4sX5JII+2OtfI7OZnzNnH7DI626jXInVXyNC+4ooHH9Ct7tcLFjqRVMgCn/dRejJc9td3QMoHK24WwGwou/4B2tGv4W6doo18C7PBe6DFky70fdlR+DfjxYD4kNMuTBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687636; c=relaxed/simple; bh=ucQzhGntvLuhFM3M+d8I10C9ch0+16AHkiMtzsjw7Zs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A0WOyo684kxKrBZbcRgwpb8U0aX8gfpKLcckHNjMde/wCGIAlKhiW6bpIaey8XGFqiwKuVtW3YIkQjrmEJTcdcnr+SVoZK+SqrUFkNAan047+rBH+enBKXQbsWVYbLOUG5Yf5MEyYVU0RzoX9PyX+w8jvPfQYlMG8ZBj2d3h40o= 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=QgvBpsqR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dY/OZ7BI; arc=none smtp.client-ip=103.168.172.145 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="QgvBpsqR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dY/OZ7BI" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 16BD7138029D for ; Mon, 30 Sep 2024 05:13:54 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 05:13:54 -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=fm2; t=1727687634; x=1727774034; bh=lGHcHYVFE8 grfjeEFfWdVGcBbZNSvt/q4GHswxk1NEw=; b=QgvBpsqRtAdWegNBVBBxpIobeB TXn2RLx2htbFBJV0H+sC0ewDN1zAQKtgSB3rbMzQntw9hk9Zme12dlxdmGmIdVPE 4PpYMJ4Th/eiQeTM/GvRlUuGLmO0UUATMnrzHVi665LhiZAMNhK/ZwGAEfUkl17k tvtAOquKvZk6q0LnTJqjkUNitZrcfPLgygRxGG+NRJuURXP+0zhRuMwbwVPffMJr WxIDVgyFJr7zPQx1j+rh4uAI3fpZrYUO+kOzLvmykWaozXMCp/fgwhTLpChmPdzw 007MC8Uyu9/kGW8lGYtmrHewcCnrG+UK5BAkF1mREb53Usxo7Jut3NxIrVeA== 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= fm2; t=1727687634; x=1727774034; bh=lGHcHYVFE8grfjeEFfWdVGcBbZNS vt/q4GHswxk1NEw=; b=dY/OZ7BI1KFEKp3L8/7zEVhLCZPSlVGGLIX7oQE1t3F/ sS6fWMMeCxsrY3WEsI/AeZhktPaLxoQf0DrmDdckdeGSmc62wg18sELRZ4P/xn06 SdLqI1TA97RG0AuEqZY4rPimxjmxPafP+J/x39k0fpdiFniAKXil5IMPqD37fh2a BOak+5KeniXdpIW2lbZk4rxLcOlyfQuJ9tLEu5t8GNIzZajCA7HX+qeiSvhnQ1P3 Zh1dEyxhbHdhbgTBahuDHjvuUJDGfxDYq6MEE+x0RGq5xYRta6GSWbUCsEEFzz7/ MnAXLoP1BQlLFAnYGNas6XbzRBsmi2wH3kSwMoCLWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3fe90d42 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:08 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 14/23] pseudo-merge: fix various memory leaks Message-ID: <6e7a272c29577536ba992cc73d736d8f66397607.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Fix various memory leaks hit by the pseudo-merge machinery. These leaks are exposed by t5333, but plugging them does not yet make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- pack-bitmap-write.c | 8 ++++++++ pack-bitmap.c | 4 ++-- pseudo-merge.c | 19 +++++++++++++++++++ pseudo-merge.h | 2 ++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 4dc0fe8e40..6413dd1731 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -64,6 +64,12 @@ static void free_pseudo_merge_commit_idx(struct pseudo_merge_commit_idx *idx) free(idx); } +static void pseudo_merge_group_release_cb(void *payload, const char *name UNUSED) +{ + pseudo_merge_group_release(payload); + free(payload); +} + void bitmap_writer_free(struct bitmap_writer *writer) { uint32_t i; @@ -82,6 +88,8 @@ void bitmap_writer_free(struct bitmap_writer *writer) kh_foreach_value(writer->pseudo_merge_commits, idx, free_pseudo_merge_commit_idx(idx)); kh_destroy_oid_map(writer->pseudo_merge_commits); + string_list_clear_func(&writer->pseudo_merge_groups, + pseudo_merge_group_release_cb); for (i = 0; i < writer->selected_nr; i++) { struct bitmapped_commit *bc = &writer->selected[i]; diff --git a/pack-bitmap.c b/pack-bitmap.c index 9d9b8c4bfb..32b222a7af 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1390,8 +1390,8 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git, } base = bitmap_new(); - if (!cascade_pseudo_merges_1(bitmap_git, base, roots_bitmap)) - bitmap_free(roots_bitmap); + cascade_pseudo_merges_1(bitmap_git, base, roots_bitmap); + bitmap_free(roots_bitmap); } /* diff --git a/pseudo-merge.c b/pseudo-merge.c index 10ebd9a4e9..28782a31c6 100644 --- a/pseudo-merge.c +++ b/pseudo-merge.c @@ -97,6 +97,25 @@ static void pseudo_merge_group_init(struct pseudo_merge_group *group) group->stable_size = DEFAULT_PSEUDO_MERGE_STABLE_SIZE; } +void pseudo_merge_group_release(struct pseudo_merge_group *group) +{ + struct hashmap_iter iter; + struct strmap_entry *e; + + regfree(group->pattern); + free(group->pattern); + + strmap_for_each_entry(&group->matches, &iter, e) { + struct pseudo_merge_matches *matches = e->value; + free(matches->stable); + free(matches->unstable); + free(matches); + } + strmap_clear(&group->matches, 0); + + free(group->merges); +} + static int pseudo_merge_config(const char *var, const char *value, const struct config_context *ctx, void *cb_data) diff --git a/pseudo-merge.h b/pseudo-merge.h index 4b5febaa63..29df8a32ec 100644 --- a/pseudo-merge.h +++ b/pseudo-merge.h @@ -51,6 +51,8 @@ struct pseudo_merge_group { timestamp_t stable_threshold; }; +void pseudo_merge_group_release(struct pseudo_merge_group *group); + struct pseudo_merge_matches { struct commit **stable; struct commit **unstable; From patchwork Mon Sep 30 09:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815679 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 9F4A518952C for ; Mon, 30 Sep 2024 09:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687641; cv=none; b=RWl3ZteM13wit4gFotwXw4AYSNEAhITiDc2zrH408DS1JoBZ3FWQ21cakw6WSFLl8EJeRgJJqz1GpsyYd9R8frYAi1t4z0FFqVFnBmKfkJa6K//mpBZTI3t1rtgbn30G3w2kwRcIV4ZgenuSIRmcftp/sB1pHeG3sIkFyBTMSAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687641; c=relaxed/simple; bh=ZcPOlwEC9nSBhPwsP/uHloMq6nfrynv1PXipBWbuUn0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bfTNIyy+8mkVXoukZqmb1KmGjvos9Q2KRxvjMs56ZxtSf9lTqmwDXFDfo1aralTBJOBYhbdr0QIWSGPAk0uaX49wXLkBA7ZIoU+qHh+bXhcKiuAL/2fC91EW09SGrYZw/9arWrzfSNS0mCZg8hiCIcFy8WGZ/sZyJ5KR2eUomW8= 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=F/4SfSwb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OImCSifP; arc=none smtp.client-ip=103.168.172.145 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="F/4SfSwb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OImCSifP" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id E177313803A6 for ; Mon, 30 Sep 2024 05:13:58 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 30 Sep 2024 05:13:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727687638; x=1727774038; bh=PkFfBejS6v yN6U5GoGafXYqQGc9rWUArLvkUJKidIq0=; b=F/4SfSwbMMg6txwMiR7qQzwy5F 1vs/Da1seaqRO7E7OjOfjgJUDoKM1zwf7soek/7fubBzIEMndGFtuT8m7rzPGezV NAxbgDGGMTa0+z/qWThfHil+ea/c46luJa4/4R1QozZ73SY1I++XWQQ80TqBKqau EMV4mrE9oaRnxZW3mcgERvDu46Y/J9frj8DFtszFbvcbw7HoJ3w+AY/JfhRiUp9n WiFYAbFJp2t9RByYB4pf5QiyRofrsPvxa9Mu05vgmqEtGvrgp98f83mhrk3L54In iIcQweZk1YwPfcaDc2wt4DhhDamOks/Yyd/eKtbWROO+51eKas506rTt9HHA== 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= fm2; t=1727687638; x=1727774038; bh=PkFfBejS6vyN6U5GoGafXYqQGc9r WUArLvkUJKidIq0=; b=OImCSifPn2pkWFKC0+x7ziI0ddlTzucM99rM++3ONHYA jJ4mjqYbzgxer4iE9jDv+Sd+HJlYdTXtRCcJ+TZWZ2LeZTDsWD4v7DYj/E8kZA42 iu6hIAgDXCbB29srZqKgD7jHFuCGkLfwlmtOqfd/CNSt4P7Z6bm2YRANV5K0gGZU NldpySc2swg/rfnfh+QDDRbzi3gWs+UHzhenTrerYfD2+0WM8W7WbpC/WL2Msm3Z bsCIyMwIgNeiCFTkOCi+9hnZGxzU3G7EpEOUd6mwN/VN/8VOo0orseJ6BATMdGB5 aKdeEKR1rZYDwj2HZvvxCh99XBT/yDMgO5D2quKxag== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:13:58 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id be0a461e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:12 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 15/23] pseudo-merge: fix leaking strmap keys Message-ID: <9e1161d55f96253bfeb5cddd1bbd381e2dad8a71.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When creating a new pseudo-merge group we collect a set of matchnig commits and put them into a string map. This strmap is initialized such that it does not allocate its keys, and instead we try to pass ownership of the keys to it via `strmap_put()`. This isn't how it works though: the strmap will never try to release these keys, and consequently they end up leaking. Fix this leak by initializing the strmap as duplicating its keys and not trying to hand over ownership. The leak is exposed by t5333, but plugging it does not yet make the full test suite pass. Signed-off-by: Patrick Steinhardt --- pseudo-merge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pseudo-merge.c b/pseudo-merge.c index 28782a31c6..bb59965ed2 100644 --- a/pseudo-merge.c +++ b/pseudo-merge.c @@ -87,7 +87,7 @@ static void pseudo_merge_group_init(struct pseudo_merge_group *group) { memset(group, 0, sizeof(struct pseudo_merge_group)); - strmap_init_with_options(&group->matches, NULL, 0); + strmap_init_with_options(&group->matches, NULL, 1); group->decay = DEFAULT_PSEUDO_MERGE_DECAY; group->max_merges = DEFAULT_PSEUDO_MERGE_MAX_MERGES; @@ -275,7 +275,7 @@ static int find_pseudo_merge_group_for_ref(const char *refname, matches = strmap_get(&group->matches, group_name.buf); if (!matches) { matches = xcalloc(1, sizeof(*matches)); - strmap_put(&group->matches, strbuf_detach(&group_name, NULL), + strmap_put(&group->matches, group_name.buf, matches); } From patchwork Mon Sep 30 09:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815680 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 B92F7189B9D for ; Mon, 30 Sep 2024 09:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687644; cv=none; b=RVTDv6OZDWwz927RJ9fm3g1yyF5vGTahYngOG+oFnpdusBOSl9AA/NjnC03/QGHjzmwiJTXF3l1v5jlGEyXr6ixWlqOwq1aF1yZCKYwl6KHs+1f/hILj5N2CslXeJZVhl00EMOqTYc3mfn7JAEPIiuYNsxiB1Y8JK/nna1//cKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687644; c=relaxed/simple; bh=8RFLKRkNUZHLOj/cOWBG8pPv9dXIFZgnULHvje1BIn4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s6VrRDjeory7eC113ZnurQi8e45jEMFcAG75Wy/0PXaBbEmFOiKbVxeUUw1wZabnVrvwNtq2zD1amST+om2MVrOhC0flZjEaOpNo0qfPwNeKNWS2cc5fc49pK3nraaDhO07JSOWtdtNVx+1INSkX8KKZfVv/YLwG8nhyfTfKftU= 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=QlXVpcuo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FJOl8UJx; arc=none smtp.client-ip=103.168.172.159 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="QlXVpcuo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FJOl8UJx" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id D84001140259 for ; Mon, 30 Sep 2024 05:14:01 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 30 Sep 2024 05:14:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727687641; x=1727774041; bh=9u4LD4Ms2h XiiRBwJSsqoastO9z8xmpfgOompqTiH+E=; b=QlXVpcuoC5KVL6KWuztu3ngaAO gy1Er4e7kB5GgZrgHDfY54KfYxvsdsK8AB4C4O54/CzUm+HJ9m1FEOCFQECDR7WR YuvNqIVa8WKgmEK78VrWdTbyW2CKQ59109dwGrAmcZmU862hQr7gJl6YycBVMhzA ACC0LBGXZVpalKxv4cHvi7fHerfwLonYoz26t+6La9IIpatzLIR72VqzN287NRGY kHvTWxWTRR1BZjEWIxIjLnS6krLpkyqyl5oTVawfcwbKRmGMhlGJqZNocoScUNI3 z/q0xGBujzvK4pIEQqUuPczH+NjwQNtOkfm1mfrerjtAZAnucVyPSxS0XFkw== 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= fm2; t=1727687641; x=1727774041; bh=9u4LD4Ms2hXiiRBwJSsqoastO9z8 xmpfgOompqTiH+E=; b=FJOl8UJxs8W4Ps0xQKtgNOB8/ZUcYuoFt7iueOJDiTcn MCGG42YLgKnVLDr6HjVl9WiqRYWSJOkYADBZ0YhkmcGBpT5WFqo5pMppgRz5/8D5 krZAT9n0cu2IrYtDIxasGOgTWZwjOM0QKV/fwiGGqbyBsGVz41RhKwt4e/0zoUj4 jBYd+lbK58RaA1pBYRx52whxtnAB4wl0aRj8LqGOYUj4mWZE1ZoIRsIku/mPOZ/h QmsQXoPYW211r6aQN+7hvjmMM9S9wiG8J9RbxVM6FM45Vmose0qnYQb6ppvVTbRK 96jeunT9Q1bnfKTLIqIyfUsvK3s+DsnCN4GZk1JhmA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f0a5117d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:15 +0000 (UTC) Date: Mon, 30 Sep 2024 11:13:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 16/23] pack-bitmap-write: fix leaking OID array Message-ID: <98228243be04d7ab296ccf7516e092549bbd1236.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Fix a leaking OID array in `write_pseudo_merges()`. Signed-off-by: Patrick Steinhardt --- pack-bitmap-write.c | 1 + t/t5333-pseudo-merge-bitmaps.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 6413dd1731..49758e2525 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -913,6 +913,7 @@ static void write_pseudo_merges(struct bitmap_writer *writer, for (i = 0; i < writer->pseudo_merges_nr; i++) bitmap_free(commits_bitmap[i]); + oid_array_clear(&commits); free(pseudo_merge_ofs); free(commits_bitmap); } diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh index 1dd6284756..eca4a1eb8c 100755 --- a/t/t5333-pseudo-merge-bitmaps.sh +++ b/t/t5333-pseudo-merge-bitmaps.sh @@ -4,6 +4,7 @@ test_description='pseudo-merge bitmaps' GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_pseudo_merges () { From patchwork Mon Sep 30 09:14:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815681 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 89C39189BAF for ; Mon, 30 Sep 2024 09:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687646; cv=none; b=SQOiTdV3vnLyWNkUfx986+IbG3cT5zN63kPKoaXbRdozV5tV092g/1N5IdgvMRNmbOGeFc24OegaHicg36Zi8xFPSY/rSyocEcQHTrb6kQ0+nPr10L/aalukPlIpqXTBJsAPTKbzv6niRgdNS2sNxzBLK7kPZay5R6es4tUWKLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687646; c=relaxed/simple; bh=rMBi/n9zu2mZ8tckSuOO4+suS8yBNh7IKHfhKs22+vA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ckJW4ey0viD7p35/O/om+VlrRmfRVYTcrx5AB84O0pYrYVlLEanR2c8piECSv8OPECS96dBFgl4zF1JiLummdIoejuP0cfwTFUvjX9/1CHz5bqo8q3D9ZEZmKjBRNHioiVgxZxHA86x61QJkoEtcAmzbvN1bvrFC8C54xpnv3E4= 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=m7LYVPY2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qGwm1irk; arc=none smtp.client-ip=103.168.172.145 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="m7LYVPY2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qGwm1irk" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id AC7F5138029D for ; Mon, 30 Sep 2024 05:14:04 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 30 Sep 2024 05:14:04 -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=fm2; t=1727687644; x=1727774044; bh=DhGq8cTOff InH3xqZfZU8PiAkY/lm2XcyWoSVhhs5h0=; b=m7LYVPY2pq/S8N9xUd+SoOI0aD jE27qDAndOkbeqxjyw/IrRjQiMgfk/DjHL50fw0HzYI+HRcmK7RWDXYG6N82tsQz 0II9E2mhGDz/Ik2ZwRAaMzXlZYYc3jJ3GIo6gqGm6quGIpkNz4uSh6kV9INtaNV6 3O0xQBd6bC/Mf9/3Hv9XoJ2OWRq68grTY38U9747Nh+x8Yy6YEBlgMCNhOTHlIS/ UhOabVZEZKUvfPdukL1k47wKMWsmOu84ZDauwWbWXtFg27Isfv6wblU+xl6R0Jq+ MPjBdMdXgvYzfw476NYlNWuPJo45JvPhtHEkJnYUznu1HLuVe0zb8KjV6lyw== 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= fm2; t=1727687644; x=1727774044; bh=DhGq8cTOffInH3xqZfZU8PiAkY/l m2XcyWoSVhhs5h0=; b=qGwm1irkwivl1uURf+QZVkOrYNi7ORth8CUlQvtn1fOB Rn45fmscxst7fBAlFkmBJz99/wOwUAM0bNC/6acE7bPJ4zJS91RL2aLjblCP9jDo NnG1dYiO70UetTVwvDKX1555oSINvi6TBST7qTySujwJWtmckGFEZ3Aqj7cJCZR8 zOlcSw8NK9OOFI9TWCh2o3ml0QBs9ODX5VVPnTQ99eJDZH37I1jBSmcnotvNZ0re R0kZvoJcLBYXhZMh2BbKcAxQQ6Dcvr6Hpvihc1iEY1CoNf5UYzbZ9ExA0EnV28Bp JhrqE44QpCq/cYHCuCKSaLeEo2/cLqYmOOrD1JaZVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e0adeb55 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:18 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 17/23] midx-write: fix leaking buffer Message-ID: <5db4e17db9b9b991e0dbe56d7043b56e5d161097.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The buffer used to compute the final MIDX name is never released. Plug this memory leak. Signed-off-by: Patrick Steinhardt --- midx-write.c | 2 ++ t/t5334-incremental-multi-pack-index.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/midx-write.c b/midx-write.c index 1ef62c4f4b..625c7d3137 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1445,6 +1445,8 @@ static int write_midx_internal(const char *object_dir, return -1; } + strbuf_release(&final_midx_name); + keep_hashes[ctx.num_multi_pack_indexes_before] = xstrdup(hash_to_hex(midx_hash)); diff --git a/t/t5334-incremental-multi-pack-index.sh b/t/t5334-incremental-multi-pack-index.sh index c3b08acc73..471994c4bc 100755 --- a/t/t5334-incremental-multi-pack-index.sh +++ b/t/t5334-incremental-multi-pack-index.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='incremental multi-pack-index' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-midx.sh From patchwork Mon Sep 30 09:14: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: 13815682 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 33D22189F58 for ; Mon, 30 Sep 2024 09:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687649; cv=none; b=jZcE0ZLeic93/Y66BZIqptBNoMRpjE7FQs89ie9AvdwTYobUav5SAVumqb7pUagdaxrt72YIqatb3ov5fRyLieYpwzFVewUKXoGzf9+MPH1h/dN5RYVoR/zeoLSbpJzfsgsCz3H3/uFbHA8fB0/YJIUE4GLFSDEeOxeleKY4ktQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687649; c=relaxed/simple; bh=hkmezCtm7cUj3Y0Tt3ex8uNxObEnkhhQ2gWCT80EOgg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tblXqCAthNIjLFJG01f5tBd3SIqru97ZWOFdieDnQ7zSBDigrXX23g8LFLMSjiMZBZfUxtID3P9ZJ2WiybZjv7YVY0nzoMS2lkQEvYdA8Ftj/Ec1f2zfjrf2VZLAbjF/afwc5dK7Tm/xWdLPt1lox4CamY4CFt3qt/vVgibW3Oc= 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=ZaPafXoe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fEyZV0hm; arc=none smtp.client-ip=103.168.172.159 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="ZaPafXoe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fEyZV0hm" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 89D3B1140259 for ; Mon, 30 Sep 2024 05:14:07 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Mon, 30 Sep 2024 05:14:07 -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=fm2; t=1727687647; x=1727774047; bh=5MWaEBGYIu IbDGXGEIT52eBhAHsEX7PZm2OU2ca0N98=; b=ZaPafXoeythBtjeLCgIgUVk664 OMYLnDlHPfPo7IaV44RTxQLtjl0cJDkAZAmYeu2/NEe1LoODz3Mij9y8O1bIwS6p ra5I03LDVC17Lrzt2irSZ9DoFcI0mrwEHCmbCfmp4j0WzntBzuDV+5ypFdmzKBiB txxcrfTVThpkb7f+IhLeajWpZoEEFgQofVWxAfUXvLgu6hY9QA4hwFQis/kZADMJ TW9AEmm8H4jZsbokbnFVx2HHYo315YcN9+Gyfk/GGrNXXTSZBxpTv91fHJlv9UEN 4xjz+up9pjk7eu67mwqC2gpIeNESqoZBO9nIuv+vi1cUSZywpHE4c5xZUGhQ== 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= fm2; t=1727687647; x=1727774047; bh=5MWaEBGYIuIbDGXGEIT52eBhAHsE X7PZm2OU2ca0N98=; b=fEyZV0hmlTHsiOuoXXzVDyUabmoPR/igYzHV5s8FKTYX fp4AAbcwzs1Evs50xMrVE1j5k1+DvHEZ4afzQo/zu+WkRMfVmywSx+0oYGh5AemH hgja7BbS27qGud65cA2ojDo/9/14Se53SPq1VHTX8Ego1pJl+4BManaCo+B54S+n +3pOAiV4HO+kbxC3t2u9qnUr1Nf6qmz6lkPMoRNeAcvp8CWA3KJJGe7tS8PW2j1M dQMD+hrCWbuja7nYNa0X83We0NL5r/VRuU6WLaMQtSgqvz8EnJVjRjN6HK7xjrSU BqkETrwHSWfatxHFAJfuEC8lJRcdqp8oXLdZrL4HOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id facf0840 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:20 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 18/23] revision: fix memory leaks when rewriting parents Message-ID: <09e067162aa82fddabe6c7aeffc55f734212ee4e.1727687410.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: Both `rewrite_parents()` and `remove_duplicate_parents()` may end up dropping some parents from a commit without freeing the respective `struct commit_list` items. This causes a bunch of memory leaks. Plug these. Signed-off-by: Patrick Steinhardt --- revision.c | 2 ++ t/t3427-rebase-subtree.sh | 1 + t/t6016-rev-list-graph-simplify-history.sh | 1 + t/t7003-filter-branch.sh | 1 + t/t9350-fast-export.sh | 1 + t/t9402-git-cvsserver-refs.sh | 1 + 6 files changed, 7 insertions(+) diff --git a/revision.c b/revision.c index e79f39e555..6b452ea182 100644 --- a/revision.c +++ b/revision.c @@ -3250,6 +3250,7 @@ static int remove_duplicate_parents(struct rev_info *revs, struct commit *commit struct commit *parent = p->item; if (parent->object.flags & TMP_MARK) { *pp = p->next; + free(p); if (ts) compact_treesame(revs, commit, surviving_parents); continue; @@ -4005,6 +4006,7 @@ int rewrite_parents(struct rev_info *revs, struct commit *commit, break; case rewrite_one_noparents: *pp = parent->next; + free(parent); continue; case rewrite_one_error: return -1; diff --git a/t/t3427-rebase-subtree.sh b/t/t3427-rebase-subtree.sh index 1b3e97c875..5e9046e3df 100755 --- a/t/t3427-rebase-subtree.sh +++ b/t/t3427-rebase-subtree.sh @@ -7,6 +7,7 @@ This test runs git rebase and tests the subtree strategy. 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 diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh index 54b0a6f5f8..2656d6a6bc 100755 --- a/t/t6016-rev-list-graph-simplify-history.sh +++ b/t/t6016-rev-list-graph-simplify-history.sh @@ -10,6 +10,7 @@ test_description='--graph and simplified history' 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-log-graph.sh diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 5ab4d41ee7..bf3e3f0b67 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -4,6 +4,7 @@ test_description='git filter-branch' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 1eb035ee4c..2bdc02b459 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -7,6 +7,7 @@ test_description='git fast-export' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t9402-git-cvsserver-refs.sh b/t/t9402-git-cvsserver-refs.sh index 2ee41f9443..c847120d52 100755 --- a/t/t9402-git-cvsserver-refs.sh +++ b/t/t9402-git-cvsserver-refs.sh @@ -8,6 +8,7 @@ tags, branches and other git refspecs' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh ######### From patchwork Mon Sep 30 09:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815683 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 055F818A6A3 for ; Mon, 30 Sep 2024 09:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687651; cv=none; b=Ynk48J3fGenCLywVFfPt3VjvCt9rmrE2YtQl0zf/vLY0i9CUuOZsQkd/8k8lq+qdN0R3rRSxc3gOToZxCfx6tVbg9zKTa2MGJ7OFMEuZBOD0N0VoROnyPy1H5Xbc54aQBM3KFl7B6FBC2f9JynhNq7C+/Mo7nnh5Eioq8a8b4Y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687651; c=relaxed/simple; bh=XzDJxn/SMnT2Lz/5g4O5TmgMVCuwgJV5rok9+sAX6TI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SjlmYXJYiGOtJfAFdGsH/SysfydrkF+y+PUGg+638nbQ2w6Fzg90RLpnHEmaEkB2//Ms8g2imJqLFSoHwbsp3xCcDsfqtpGDvPGucZCuvAMoRS4y/498ilO/CKUjpN6wHXrlv4S82sbAc0z9VfMlBl0rLCLbSXJaseq/iRiCDlw= 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=gtcRW0Al; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JwgM7XeD; arc=none smtp.client-ip=103.168.172.159 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="gtcRW0Al"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JwgM7XeD" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 65C251140253 for ; Mon, 30 Sep 2024 05:14:09 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:14:09 -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=fm2; t=1727687649; x=1727774049; bh=h04vuwbTD1 qXwdCwbsWLNCL9Fm5uKXkArL4LSxdnWtM=; b=gtcRW0AlQG953OuDLAbEccP6fg gHa3OEsLdW3DO39jZvfvlI4XIZ0cK4mauLFo95tk52lq7XRUlVjbX1SpgJVEvFNN maqBpSvZKwEQdUwTsBj7ijwG/458NBSdY3yNFv6hAcHG/YeNSMMODhdQw5wclOqo m3P4tHnYW1aTFU79ZmuCytuadycuyXWAs2U/VnwHy7/EBFvv7uQJuLJUHlaSqunT K02CMA85cneqXgTc5Yu3/+/ier+QbFQc1ua7BzD7YvScYDcSztv9CDqMZYNKN73K GuHMBSpAPzZjsj/HL1ktgh3shrRmyQdfXotkrOPy7gQVpv8dXqiCOPoXkLpg== 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= fm2; t=1727687649; x=1727774049; bh=h04vuwbTD1qXwdCwbsWLNCL9Fm5u KXkArL4LSxdnWtM=; b=JwgM7XeDCnqWi6bKDsnODG4Kd6TnEJakAQHCzccgrQgl fVxoir7UpVYGbHLoA8z/Bk1eQXG3RcQj13oKOQgwWZLSAcqoSiGAk+PRzQ3Ivoji 8T7bbeLawIi7MR9+rMmB+iid5yNpG1AXdKHP0wQ+D/h5fklCFUD3bp/X2ne4tSII wIbptIo4ZBt5owtcA5d/sfFakFLEPCxUDaW1Vd3WNgXvj1zKlqoGyOx+yJpj0b2S wH5WLWuTLYxYWI+XL/Ze9niNsKywbbuXCkQ/YFEHPwg5MVTTf3AJFkpOwAO73vuj zW1NljKhezRCg36AOZgjTBoxrgfI+yh1JDpJftOF1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:08 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id aa0c5bac (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:23 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 19/23] revision: fix leaking saved parents Message-ID: <89892e49e5d1cd0aa72364b686950d1bcbbfd92f.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `saved_parents` slab is used by `--full-diff` to save parents of a commit which we are about to rewrite. We do not release its contents once it's not used anymore, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- revision.c | 12 ++++++++++-- t/t6012-rev-list-simplify.sh | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/revision.c b/revision.c index 6b452ea182..f5f5b84f2b 100644 --- a/revision.c +++ b/revision.c @@ -4207,10 +4207,18 @@ static void save_parents(struct rev_info *revs, struct commit *commit) *pp = EMPTY_PARENT_LIST; } +static void free_saved_parent(struct commit_list **parents) +{ + if (*parents != EMPTY_PARENT_LIST) + free_commit_list(*parents); +} + static void free_saved_parents(struct rev_info *revs) { - if (revs->saved_parents_slab) - clear_saved_parents(revs->saved_parents_slab); + if (!revs->saved_parents_slab) + return; + deep_clear_saved_parents(revs->saved_parents_slab, free_saved_parent); + FREE_AND_NULL(revs->saved_parents_slab); } struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit) diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh index de1e87f162..8ed1a215da 100755 --- a/t/t6012-rev-list-simplify.sh +++ b/t/t6012-rev-list-simplify.sh @@ -5,6 +5,7 @@ test_description='merge simplification' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh note () { From patchwork Mon Sep 30 09:14: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: 13815684 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 E3826187FE8 for ; Mon, 30 Sep 2024 09:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687659; cv=none; b=pxtm9Q/3qynq0RKVXiFz6qBmqDGgsQcDMHiCxjLkQYtNiJzDeaZMukAVN1ZVrTyfTkFrlWiGL8CYoutzVu/6qeE7Ho50FsNMiqB1NT9cS792lHkF2S/z56yvabOMpwYKLtLyBQwyQCu7KzB1vykxbiBYKZjQd0vj+h3tIfaugcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687659; c=relaxed/simple; bh=mFJJt1ngQcysSachnt6VDGjJG6e6UgHPzN8eIm5VGys=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kQT5We5u40NKB6nGLevAKJSkr7lNjo7TONw/Qnf1ICjpSpreFPq3QY2yaX0JS97+xNzQzUx3uxWw/yteCzJV9I1r6Ufn4aSRZSwqZfg89Ujqw8hpfzwbOvbrTr22V6iEX7fHGli63ndpZvbabh3VZtHCpKtmkkpvPSVmN+w1Vww= 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=rKBFN8fK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SkWqUr3I; arc=none smtp.client-ip=103.168.172.159 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="rKBFN8fK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SkWqUr3I" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4E3A71140268 for ; Mon, 30 Sep 2024 05:14:17 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 05:14:17 -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=fm2; t=1727687657; x=1727774057; bh=6tV1M7ju0E XAmCv/0wh6kRzOnXIF96oJW58XhpZ8b5k=; b=rKBFN8fKkz6m2aOjSix3r2kUwv UNWCGtjmU8Q8IDo3OBVdNZbyUfnRGew1H2UcL7QSQlEdDsPQODo9pOTVNz3AlIFU O4ddMTkTL2y64MIwrL7Qc2W8BjcyASrkMMubcAvKRnQWMOIcfi3FZz4HT14sPx7x 3cX8ccpHmwt/t41HOmsFlYhjcSKI2QtEt7V4ikLKTzUhNK0MmicBiT5mXWPOMwIc BzA5c5DHZLITwnPQseg5FMT7OIAfjYEew1v3cQHyxGnU5GZtCvYoaFu2ODVymCR2 7refKy/E0f21eEJJ2LwqSCGDKewFQ8yQKEXec19wA8A0E4SupdYq4tibOZGg== 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= fm2; t=1727687657; x=1727774057; bh=6tV1M7ju0EXAmCv/0wh6kRzOnXIF 96oJW58XhpZ8b5k=; b=SkWqUr3I3wiRc1/8McgjEk/Muclz2RVQUqqEDK7NliAR KWzCt25ELTDCicsANLnqeckue5TQq49Q2qSAIQ3ubxKKyum3016WXQFNQ7oyEIg+ vbQRMP9AI9mH8hP1kmD8JZi29zPvvLKM6FxMA8M2SP5a0JBxogNsD7zwR+IatDb+ vqbWfSCwafB0JaRJB6CrneWYziCGzpf0w9v7eJQbMLCKIx8UfJZdRV4R+CqS6dln WPmdQ2aLMwsYPg7yuI71SzsI9Y1eizaNVnfNYuaNlv/FmLxba0JrJ6B8dxq/Vgpa Pur6+Pc4iMAAJQlmXmLeRCZHL9vFjFq/3zPYLqTHDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepheenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:16 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3b48b40b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:30 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 20/23] pack-write: fix return parameter of `write_rev_file_order()` Message-ID: <2f3e17915d750c0ded8bf4f2f57106b81e9d8b3b.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: While the return parameter of `write_rev_file_order()` is a string constant, the function may indeed return an allocated string when its first parameter is a `NULL` pointer. This makes for a confusing calling convention, where callers need to be aware of these intricate ownership rules and cast away the constness to free the string in some cases. Adapt the function and its caller `write_rev_file()` to always return an allocated string and adapt callers to always free the return value. Note that this requires us to also adapt `rename_tmp_packfile()`, which compares the pointers to packfile data with each other. Now that the path of the reverse index file gets allocated unconditionally the check will always fail. This is fixed by using strcmp(3P) instead, which also feels way less fragile. Signed-off-by: Patrick Steinhardt --- builtin/index-pack.c | 7 +++--- midx-write.c | 3 ++- pack-write.c | 42 +++++++++++++++++-------------- pack.h | 4 +-- t/t5327-multi-pack-bitmaps-rev.sh | 1 + 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index e228c56ff2..9d23b41b3a 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1505,7 +1505,7 @@ static void rename_tmp_packfile(const char **final_name, struct strbuf *name, unsigned char *hash, const char *ext, int make_read_only_if_same) { - if (*final_name != curr_name) { + if (!*final_name || strcmp(*final_name, curr_name)) { if (!*final_name) *final_name = odb_pack_name(name, hash, ext); if (finalize_object_file(curr_name, *final_name)) @@ -1726,7 +1726,7 @@ int cmd_index_pack(int argc, { int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index; const char *curr_index; - const char *curr_rev_index = NULL; + char *curr_rev_index = NULL; const char *index_name = NULL, *pack_name = NULL, *rev_index_name = NULL; const char *keep_msg = NULL; const char *promisor_msg = NULL; @@ -1968,8 +1968,7 @@ int cmd_index_pack(int argc, free((void *) curr_pack); if (!index_name) free((void *) curr_index); - if (!rev_index_name) - free((void *) curr_rev_index); + free(curr_rev_index); /* * Let the caller know this pack is not self contained diff --git a/midx-write.c b/midx-write.c index 625c7d3137..b3a5f6c516 100644 --- a/midx-write.c +++ b/midx-write.c @@ -649,7 +649,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash, struct write_midx_context *ctx) { struct strbuf buf = STRBUF_INIT; - const char *tmp_file; + char *tmp_file; trace2_region_enter("midx", "write_midx_reverse_index", the_repository); @@ -662,6 +662,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash, die(_("cannot store reverse index file")); strbuf_release(&buf); + free(tmp_file); trace2_region_leave("midx", "write_midx_reverse_index", the_repository); } diff --git a/pack-write.c b/pack-write.c index 27965672f1..9961149e65 100644 --- a/pack-write.c +++ b/pack-write.c @@ -212,15 +212,15 @@ static void write_rev_trailer(struct hashfile *f, const unsigned char *hash) hashwrite(f, hash, the_hash_algo->rawsz); } -const char *write_rev_file(const char *rev_name, - struct pack_idx_entry **objects, - uint32_t nr_objects, - const unsigned char *hash, - unsigned flags) +char *write_rev_file(const char *rev_name, + struct pack_idx_entry **objects, + uint32_t nr_objects, + const unsigned char *hash, + unsigned flags) { uint32_t *pack_order; uint32_t i; - const char *ret; + char *ret; if (!(flags & WRITE_REV) && !(flags & WRITE_REV_VERIFY)) return NULL; @@ -238,13 +238,14 @@ const char *write_rev_file(const char *rev_name, return ret; } -const char *write_rev_file_order(const char *rev_name, - uint32_t *pack_order, - uint32_t nr_objects, - const unsigned char *hash, - unsigned flags) +char *write_rev_file_order(const char *rev_name, + uint32_t *pack_order, + uint32_t nr_objects, + const unsigned char *hash, + unsigned flags) { struct hashfile *f; + char *path; int fd; if ((flags & WRITE_REV) && (flags & WRITE_REV_VERIFY)) @@ -254,12 +255,13 @@ const char *write_rev_file_order(const char *rev_name, if (!rev_name) { struct strbuf tmp_file = STRBUF_INIT; fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX"); - rev_name = strbuf_detach(&tmp_file, NULL); + path = strbuf_detach(&tmp_file, NULL); } else { unlink(rev_name); fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600); + path = xstrdup(rev_name); } - f = hashfd(fd, rev_name); + f = hashfd(fd, path); } else if (flags & WRITE_REV_VERIFY) { struct stat statbuf; if (stat(rev_name, &statbuf)) { @@ -270,22 +272,24 @@ const char *write_rev_file_order(const char *rev_name, die_errno(_("could not stat: %s"), rev_name); } f = hashfd_check(rev_name); - } else + path = xstrdup(rev_name); + } else { return NULL; + } write_rev_header(f); write_rev_index_positions(f, pack_order, nr_objects); write_rev_trailer(f, hash); - if (rev_name && adjust_shared_perm(rev_name) < 0) - die(_("failed to make %s readable"), rev_name); + if (adjust_shared_perm(path) < 0) + die(_("failed to make %s readable"), path); finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, CSUM_HASH_IN_STREAM | CSUM_CLOSE | ((flags & WRITE_IDX_VERIFY) ? 0 : CSUM_FSYNC)); - return rev_name; + return path; } static void write_mtimes_header(struct hashfile *f) @@ -549,7 +553,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer, unsigned char hash[], char **idx_tmp_name) { - const char *rev_tmp_name = NULL; + char *rev_tmp_name = NULL; char *mtimes_tmp_name = NULL; if (adjust_shared_perm(pack_tmp_name)) @@ -575,7 +579,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer, if (mtimes_tmp_name) rename_tmp_packfile(name_buffer, mtimes_tmp_name, "mtimes"); - free((char *)rev_tmp_name); + free(rev_tmp_name); free(mtimes_tmp_name); } diff --git a/pack.h b/pack.h index 3ab9e3f60c..02bbdfb19c 100644 --- a/pack.h +++ b/pack.h @@ -96,8 +96,8 @@ struct ref; void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought); -const char *write_rev_file(const char *rev_name, struct pack_idx_entry **objects, uint32_t nr_objects, const unsigned char *hash, unsigned flags); -const char *write_rev_file_order(const char *rev_name, uint32_t *pack_order, uint32_t nr_objects, const unsigned char *hash, unsigned flags); +char *write_rev_file(const char *rev_name, struct pack_idx_entry **objects, uint32_t nr_objects, const unsigned char *hash, unsigned flags); +char *write_rev_file_order(const char *rev_name, uint32_t *pack_order, uint32_t nr_objects, const unsigned char *hash, unsigned flags); /* * The "hdr" output buffer should be at least this big, which will handle sizes diff --git a/t/t5327-multi-pack-bitmaps-rev.sh b/t/t5327-multi-pack-bitmaps-rev.sh index 9cac03a94b..994a8e6be4 100755 --- a/t/t5327-multi-pack-bitmaps-rev.sh +++ b/t/t5327-multi-pack-bitmaps-rev.sh @@ -2,6 +2,7 @@ test_description='exercise basic multi-pack bitmap functionality (.rev files)' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "${TEST_DIRECTORY}/lib-bitmap.sh" From patchwork Mon Sep 30 09:14: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: 13815685 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 CE216184539 for ; Mon, 30 Sep 2024 09:14:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687664; cv=none; b=I/MF0Nrp1E52tA/3vmcRj+J2WcEjOuSLrjVYuEvpgtDERjQy6j1BQdyturzXbAXm+MYU2biAWEd0TOIlnEio32MW9B259xyqMqluVhsCbRMJt9IP/g7pwXL1a7vlFPZ9luIp9EB2P5JqAHdyoHYJsR+U8O6Nuv5AZXy+xmDw1LI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687664; c=relaxed/simple; bh=KLNIVwFdWGyRA+MbOm7ddbmdg0XUywu6bVTyMRvGCiU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lmI7rdZvgkqBICKH738rrzpqFFUPWypDtiSJpFzeZDUU4F0K4t9yaDk/oR54Hs8EkYLKto3yveLq3/j2croT5l7eFAdAa9FITdBWwy72NzVhRJkGxRRZieWGf/M20uPkrn7RClFQ6Hr5T12K+9A2IqxmB9u1Un0fY7f3JTW4l2U= 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=D39Nuc3O; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QH1VQmSY; arc=none smtp.client-ip=103.168.172.159 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="D39Nuc3O"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QH1VQmSY" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 27F34114025A for ; Mon, 30 Sep 2024 05:14:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:14:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727687662; x=1727774062; bh=wBwQs4VjYZ zmdyAnfcbkyGtaYDRla6Iw5bFzJezhD7A=; b=D39Nuc3O3MmY5jOtaVt8pYdK/a Q76Ezp15BLyD32oXYUHY5nfhVJlE6Gd5wh+EeTh9RTbUaAP8S2Obn4a/aVW0YQOc 4DfXJJhsK1LCvZ3cCW4GJoXWtQ0q0vIKuwM50kAUsJXUi1SAHiqrifyhtRZYQMO5 ysiHyAZxRT66TTDiKhj0uKxWSgCXNy1aTEnpKqRfMIVHeGgpAi2BYbzKJocOXW92 Cf9jU7+LqHasAsaVU62TUpQJbx/ql2gfd4Umc0H4Nyqn0fCRJ0x8B5zfncxCqLfa H/QdSvDH5RqrHxEp8sO5W9LoS+vUKflOQyqp4MejwGw/WkbE6fPvBcCwx9Uw== 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= fm2; t=1727687662; x=1727774062; bh=wBwQs4VjYZzmdyAnfcbkyGtaYDRl a6Iw5bFzJezhD7A=; b=QH1VQmSYvny+xjUxyWAGi+79tSfEmkAgpgZkcrr9UOe0 FoAIWCFzCi6zd4bwyN2YO28kdn9nrNJKKkzw+Bpc22vXEU4scdcvCqWVlcIq9rbO PwXL2+3/rVDodw64SeCYu6v54hQjt/pQwutcOc51dSoO/s+MfA/A1R3FV9YPU8XC lcUudV9ZaolAx0n2BKTGyrtC/zYMNyQ0r4Go/KwSkVITxpqPROEuVmVEhlfXV+SU 8Uj+x/rznXYXH0C1DY4dT2c3wqjiRGiiOvOrcnrQk+TXIAA0s7DuuucXmSSfKtth e3XpidHKD9E8PoKk4Q7MmZso11bKehNmZ+0Dpfo/8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepheenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f638509c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:35 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 21/23] t/helper: fix leaks in proc-receive helper Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Fix trivial leaks in the proc-receive helpe. Signed-off-by: Patrick Steinhardt --- t/helper/test-proc-receive.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c index 29361c7aab..3703f734f3 100644 --- a/t/helper/test-proc-receive.c +++ b/t/helper/test-proc-receive.c @@ -196,5 +196,12 @@ int cmd__proc_receive(int argc, const char **argv) packet_flush(1); sigchain_pop(SIGPIPE); + while (commands) { + struct command *next = commands->next; + free(commands); + commands = next; + } + string_list_clear(&push_options, 0); + return 0; } From patchwork Mon Sep 30 09:14: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: 13815686 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 918E818872C for ; Mon, 30 Sep 2024 09:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687667; cv=none; b=b/6LZcLWM8JaJb8Dg58NCSXzp+paMqMEtkJqZ4Jb2it9jg3x1fy2G/60en6AWyMn1sl9tWWTiZOCnZKtD69AxAhQN4gFRM4zrsu1jjuMckm+g0ecaycatGOtoCzkrrQCDl41E3ROd0gHnkQ9OAvGFGNq76G9mM6ec6XSyRVwAWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687667; c=relaxed/simple; bh=eaZqn79u/7oYCeX+s7XpSBmad/TjzIy3m5fJZj2lNX8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GKCLpsWZpNmQM2Ke+RM6gWcg4h0KsxkmvyLD1JpBHoFxB8t7IPv/n6HFPjBM/GZ/uAXvg4rCVlZ/P/WroyM0rnnJNTnkepYDDpTdqWehz2uy0BkWh/wNW37q4u6hquWOInNzc3znGrj94GiZIkJhOpR0ivaFDWxLrhRYBOqwVcA= 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=pC/HpZLu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eCJm60QK; arc=none smtp.client-ip=103.168.172.159 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="pC/HpZLu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eCJm60QK" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id F06D011401C0 for ; Mon, 30 Sep 2024 05:14:24 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Mon, 30 Sep 2024 05:14:24 -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=fm2; t=1727687664; x=1727774064; bh=xTy/xewVGj 5N+/EcHcerJV1MlB9lb7Ibq+YDiiPvIfw=; b=pC/HpZLuJaPtK0O+Tg9qKjbszv bxcVgCsSsGdr8gTUziYOLg0UUh4qiTbLmzIlHGWSNyP4IoonIYGW07MNInmWHacs /2u7kXhPUmsz2CJaCCXaoDLaKoJpoMKyD4W7hwt6WoJYvRIBu8e+wY7fDD9++9po b6ByLp9evfRnl+Ki5YY/qDc4Lff+ryVh7wkiQq/Umzma99IZRcombJfqHzNBMPES JuiH85yRciZ3h93SR8zqLoyfiI6MjhO0auNLS2sWlqi0TX4F0tXDx/7XqN1OeNbp d2ZS4EXZNKqMrXmEH9TtcqAh7moyY368wjrMosMD1SAS2y3KW7TmZRK8hzCg== 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= fm2; t=1727687664; x=1727774064; bh=xTy/xewVGj5N+/EcHcerJV1MlB9l b7Ibq+YDiiPvIfw=; b=eCJm60QKVFvFWLHcODWqhV5ijIh0zUP1oHMrRGNW7bp3 dk1fhTuCjqsP5LOtzq3RDNMC9jhOwR0LnekMZo+YtY4ReEbYBkkkZBdkHWCf9UBs Wle7FkI3GFlwCV9LaAHTwuVRG/AVs/lcETXxaB+2YnOR0JOL1jt4HSaonAMwZcjz FQ4z6bxyokFouZaMA0N8itJCq68escR56Hi2nXfYDBHxB/oGeG+HTYFAEuWi/mru xSakqe9u3wPMyAZy9mtcumSXauNP76yqHNVcbQoZ4dst1/a6RbUzPNb/sXJlMIHd OKzL7ISwmH8aOOJIBQSb04mq9wMcD3CZ7KucbJQ3cg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9a28d7c7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:38 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 22/23] remote: fix leaking push reports 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 push reports that report failures to the user when pushing a reference leak in several places. Plug these leaks by introducing a new function `ref_push_report_free()` that frees the list of reports and call it as required. While at it, fix a trivially leaking error string in the vicinity. These leaks get hit in t5411, but plugging them does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/receive-pack.c | 5 ++++- remote.c | 15 +++++++++++++++ remote.h | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 536d22761d..ab5b20e39c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -374,6 +374,7 @@ static void write_head_info(void) struct command { struct command *next; const char *error_string; + char *error_string_owned; struct ref_push_report *report; unsigned int skip_update:1, did_not_exist:1, @@ -1083,7 +1084,7 @@ static int read_proc_receive_report(struct packet_reader *reader, hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED; if (!strcmp(head, "ng")) { if (p) - hint->error_string = xstrdup(p); + hint->error_string = hint->error_string_owned = xstrdup(p); else hint->error_string = "failed"; code = -1; @@ -2054,6 +2055,8 @@ static void free_commands(struct command *commands) while (commands) { struct command *next = commands->next; + ref_push_report_free(commands->report); + free(commands->error_string_owned); free(commands); commands = next; } diff --git a/remote.c b/remote.c index e291e8ff5c..cd2091ac0c 100644 --- a/remote.c +++ b/remote.c @@ -868,6 +868,20 @@ struct strvec *push_url_of_remote(struct remote *remote) return remote->pushurl.nr ? &remote->pushurl : &remote->url; } +void ref_push_report_free(struct ref_push_report *report) +{ + while (report) { + struct ref_push_report *next = report->next; + + free(report->ref_name); + free(report->old_oid); + free(report->new_oid); + free(report); + + report = next; + } +} + static int match_name_with_pattern(const char *key, const char *name, const char *value, char **result) { @@ -1122,6 +1136,7 @@ void free_one_ref(struct ref *ref) if (!ref) return; free_one_ref(ref->peer_ref); + ref_push_report_free(ref->report); free(ref->remote_status); free(ref->tracking_ref); free(ref->symref); diff --git a/remote.h b/remote.h index ad4513f639..c5e79eb40e 100644 --- a/remote.h +++ b/remote.h @@ -126,13 +126,15 @@ int remote_has_url(struct remote *remote, const char *url); struct strvec *push_url_of_remote(struct remote *remote); struct ref_push_report { - const char *ref_name; + char *ref_name; struct object_id *old_oid; struct object_id *new_oid; unsigned int forced_update:1; struct ref_push_report *next; }; +void ref_push_report_free(struct ref_push_report *); + struct ref { struct ref *next; struct object_id old_oid; From patchwork Mon Sep 30 09:14:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815687 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 7902118C03D for ; Mon, 30 Sep 2024 09:14:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687669; cv=none; b=Ukg8j+blOyrSWFZwJcSaaLrZL0Ee/OdyFjFc4/y5SCo8Vyo+68L1uT3z4xAvZ2Tu3SPFTBoScK9XeX7fvgXRcYXnj8BuNSpKHPHdLKQU4ERbxNsax41/u/Z8ngJw2QAZAmos8zGOi/AM3+kZQyafnW4qGFt/E1Rab6Jill7b72k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727687669; c=relaxed/simple; bh=r84pHqvqnnZLhcGYAgxp8mPZFUsUT+uJjLnQhCqzmoA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TrioRvcx1tUYvdy0o5dMhWwk+7wdxb1B57tmr4xsvfOBYZHZfcDmdUqL+d2H/o/U/JEQ+zufBPhHOeg4+E85zfVfdSoaYOcZTJrjgVV3h+lgFJgimUjM57nWcChY2hDvxi64QzOUS+GOURg21P6RDpTSIYXxhPaCq+iBm2Pj1S8= 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=If4VVvQ9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Rm2NXwHb; arc=none smtp.client-ip=103.168.172.159 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="If4VVvQ9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Rm2NXwHb" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id CF2E8114026F for ; Mon, 30 Sep 2024 05:14:27 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Mon, 30 Sep 2024 05:14:27 -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=fm2; t=1727687667; x=1727774067; bh=p71VE69Wh/ AN4ZcIi14bccifRUnxznCxhnPgwrZgpd0=; b=If4VVvQ9SjG5Znt7X7dO2A1lUk /QRFBuYnPPAV3IhFzDVakfg+CrYBGzA8+js/w16YXQjdOdZ0m6VsjzoVejyoJIqF 9jpNSTD58mI87QB3gWLoqqOdWGFJxxpeIinxOCfdVhsoxkDWNA7mRHQWDP59S/i0 Z3bPG/6m6ePORyeh/M8u+LgiDw/bsS/06ls1F7MH9bj7MGBH1S7E8uGyOCoH2T1r bpWLqzckZ4gz3TW1aw1bRxI94PBvtwVHxrSF/VNCyTr9Pm4F6H+9sTTh8Z6AiZdF LqDrLwRd/9+ZcImHemZfnaNZNHhb3FugTlSmt+QQy0BdmMifAC+nn3KHrU8Q== 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= fm2; t=1727687667; x=1727774067; bh=p71VE69Wh/AN4ZcIi14bccifRUnx znCxhnPgwrZgpd0=; b=Rm2NXwHbjBh07SfwA/6Ehj11XQ5ALsGgsYlJVMPyt3uT G/1k1AQK5fU5VW8Qgm1IrOpZREJn+a629fFsKsGVlvU+T2rHOgIu1avJHpVSH8hl QZ9snbg4BxVNtV+d8UPdWemfIYabK6Cb4CpH1Z1qjow8N/Ocd8UVeQulzLHZrFvP txkOdXgSbrqXDQmrNuexR/6Qawaq4oFMJhm4GZ8Sd/Hib4uWljvqBJCe1SXbLNxG kT/7izsymKNFFxX3UYgNDSdSoa7FkjaWckkMPLbf8y5EvYAiplZEjMOi+gL4s6tA sBGtzMeGRSTtXNre0ZE3UrCB8ER/+glr8EnN+F9ykw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepieenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 30 Sep 2024 05:14:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d847716b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 30 Sep 2024 09:13:41 +0000 (UTC) Date: Mon, 30 Sep 2024 11:14:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 23/23] builtin/send-pack: fix leaking list of push options Message-ID: <312de7828b646101145975466574434d2dae048e.1727687410.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The list of push options is leaking. Plug the leak. Signed-off-by: Patrick Steinhardt --- builtin/send-pack.c | 1 + t/t5411-proc-receive-hook.sh | 1 + t/t5545-push-options.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 8b1d46e79a..59b626aae8 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -340,6 +340,7 @@ int cmd_send_pack(int argc, /* stable plumbing output; do not modify or localize */ fprintf(stderr, "Everything up-to-date\n"); + string_list_clear(&push_options, 0); free_refs(remote_refs); free_refs(local_refs); refspec_clear(&rs); diff --git a/t/t5411-proc-receive-hook.sh b/t/t5411-proc-receive-hook.sh index 92cf52c6d4..13d2d310a9 100755 --- a/t/t5411-proc-receive-hook.sh +++ b/t/t5411-proc-receive-hook.sh @@ -8,6 +8,7 @@ test_description='Test proc-receive hook' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/t5411/common-functions.sh diff --git a/t/t5545-push-options.sh b/t/t5545-push-options.sh index fb13549da7..64ce56d3aa 100755 --- a/t/t5545-push-options.sh +++ b/t/t5545-push-options.sh @@ -8,6 +8,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh mk_repo_pair () {