From patchwork Fri Jul 26 12:18: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: 13742744 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 3E697E57E for ; Fri, 26 Jul 2024 12:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996352; cv=none; b=hvz6GsEUIxueqjRKOwJuSNUDvvIrcVkxKRfyVdPaBewmbLU925NyQqO9Efmlvmv1FxXEApr6jVbU5/yzHpMmRq9n6HdxEKrvF5mBZg8h11zaoiDpaAJ+qd/+CZDrbDdq1tDgvUTdWwqox6rtuE19jZc4J+OfireKs9L52zlHDU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996352; c=relaxed/simple; bh=rmpiy5hwE4FV64d8alnUwdZLadBiln3/H1UwsdLc6Es=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n9ICUVdDthnbo8zzWJrBDvlW3qekGTbNup6oqUqtLjy5HR8yzyskiJXY34EmPlP0GHebwX9gcSvYGw6yD+8PF+0mX6VVYlZ82tMqL/g4QF4nMCvFK/8/aZNz8JeULbssF+6hH4YhlSaFTZcZ39fz9nTovomogS8KqBVUrDWXoAg= 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=gq50Wn2W; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VJJ1e5OO; arc=none smtp.client-ip=103.168.172.148 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="gq50Wn2W"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VJJ1e5OO" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 5BA4313800B5 for ; Fri, 26 Jul 2024 08:19:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 26 Jul 2024 08:19:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996350; x=1722082750; bh=oenikin661 0tWh48CMlXxSfi3YtE5E1SlEkRwQxdGyw=; b=gq50Wn2W74D2L1LzlaYYgsGCrh lH9v13ghbXHzvLfGYhjkwki4Zo8Knn6t6zcS4PdlZteEr5Kfa1HvZnRFzoZW0W+U KWBPBgLpp9ZIIjFzzfvsm/rkruOaHrYQ45XyLyzXEfss+CLVNow6d4REDIYownCr VcDGtvZu3pOFzhHh2P7RPtmH7CqU13w/drkDVtlN5p/hwB7PleCt5gadIO9mkhji mxQJC3RDBsPVqMFY3y3MMmnJElBw3i/O9b0lDKiJUA3dDlPfbjfEct1v1TOvYiYp JyyA+NOJcpI0Zan5WgLTVhE4KAsjjGjSYQZWcJFm0JSZl3XlXbkGAl3W5Vdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996350; x=1722082750; bh=oenikin6610tWh48CMlXxSfi3YtE 5E1SlEkRwQxdGyw=; b=VJJ1e5OOFw9vN2oE8a8fyzbpOmJXh8hhaSaYJIOy/+LH mUh/hG0xP3iZo9OmQOMuV6cdkvhsgI09NodeDYgf95yhuYRCR6saaam2QQyKOeEF qEvCpLpECMSIHyQa9fMi6RXvbEUxJDvLyZ7w0A8LCRf4pJVPUZCTv7p8+nCoN0EY lof6KfNdLcaSYsEJQ6qaLNBnYih62Y+sbTIN/R1MTrvdVUi8uiSEMqE7a9WCziaL MthOLGk4g6vDtpFe9zdUI9GeKKfZDZx+QG59tyczWDGG4YhRYe65vhpHQoAhVydO kztfLKTzwA95Rr3zMme2W3HhAMKSTJNEFOjQmAV8Zw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:19:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3c606302 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:17:49 +0000 (UTC) Date: Fri, 26 Jul 2024 14:18:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 21/23] entry: fix leaking pathnames during delayed checkout 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 filtering files during delayed checkout, we pass a string list to `async_query_available_blobs()`. This list is initialized with NODUP, and thus inserted strings will not be owned by the list. In the latter function we then try to hand over ownership by passing an `xstrup()`'d value to `string_list_insert()`. But this is not how this works: a NODUP list does not take ownership of allocated strings and will never free them for the caller. Fix this issue by initializing the list as `DUP` instead and dropping the explicit call to `xstrdup()`. This is okay to do given that this is the single callsite of `async_query_available_blobs()`. Signed-off-by: Patrick Steinhardt --- convert.c | 2 +- entry.c | 4 +++- t/t2080-parallel-checkout-basics.sh | 1 + t/t2082-parallel-checkout-attributes.sh | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/convert.c b/convert.c index d8737fe0f2..61a540e212 100644 --- a/convert.c +++ b/convert.c @@ -960,7 +960,7 @@ int async_query_available_blobs(const char *cmd, struct string_list *available_p while ((line = packet_read_line(process->out, NULL))) { const char *path; if (skip_prefix(line, "pathname=", &path)) - string_list_insert(available_paths, xstrdup(path)); + string_list_insert(available_paths, path); else ; /* ignore unknown keys */ } diff --git a/entry.c b/entry.c index e7ed440ce2..3143b9996b 100644 --- a/entry.c +++ b/entry.c @@ -191,7 +191,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) progress = start_delayed_progress(_("Filtering content"), dco->paths.nr); while (dco->filters.nr > 0) { for_each_string_list_item(filter, &dco->filters) { - struct string_list available_paths = STRING_LIST_INIT_NODUP; + struct string_list available_paths = STRING_LIST_INIT_DUP; if (!async_query_available_blobs(filter->string, &available_paths)) { /* Filter reported an error */ @@ -245,6 +245,8 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) } else errs = 1; } + + string_list_clear(&available_paths, 0); } filter_string_list(&dco->filters, 0, string_is_not_null, NULL); diff --git a/t/t2080-parallel-checkout-basics.sh b/t/t2080-parallel-checkout-basics.sh index 5ffe1a41e2..59e5570cb2 100755 --- a/t/t2080-parallel-checkout-basics.sh +++ b/t/t2080-parallel-checkout-basics.sh @@ -8,6 +8,7 @@ working tree. ' TEST_NO_CREATE_REPO=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-parallel-checkout.sh" diff --git a/t/t2082-parallel-checkout-attributes.sh b/t/t2082-parallel-checkout-attributes.sh index f3511cd43a..aec55496eb 100755 --- a/t/t2082-parallel-checkout-attributes.sh +++ b/t/t2082-parallel-checkout-attributes.sh @@ -10,6 +10,7 @@ properly (without access to the index or attribute stack). ' TEST_NO_CREATE_REPO=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-parallel-checkout.sh" . "$TEST_DIRECTORY/lib-encoding.sh"