From patchwork Mon Jun 3 09:46:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13683530 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FE64127B67 for ; Mon, 3 Jun 2024 09:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717408008; cv=none; b=DVZY3YZuyAAb9SndWhDqwhj0zFIlhdtXqHarAhyU2sIw3rTtyyULpLmrhzp3jWZfbNQNPSpXMOun7X3VK1e/reB22ThEfuYYsOx6hTk41v55CRrBVtUQ3gocPaXSwKmxL7D885mBT6Wei54esKGaKyC+BCfjZMIBEYFdNo+hlhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717408008; c=relaxed/simple; bh=xMBzTS+QJ3XPrblx0DBDvTCn+V6MBClVuraNlFMcsqs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FtWqu2HdoaIONpNdblHekO2KU+MTkGChX81dToGmrJRPiaBkC+MAFRrDzQ/GITwndg4RMCnI8R51tYfRgOVxtxby+sg+7ejyX9oqO8+CHJQromOjlCEzGC+rh8jpEJ7u27SW+bc12AP8OpifnBKo8xp5HKA4ea5XzFLEQSIOGf4= 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=om1yGuDh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MYlRM707; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="om1yGuDh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MYlRM707" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.west.internal (Postfix) with ESMTP id 29067180009A for ; Mon, 3 Jun 2024 05:46:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 03 Jun 2024 05:46: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=fm1; t=1717408005; x=1717494405; bh=KlSva9prd8 AHhi47XCaqbHhZz5Ea03tJcBEaLUcFFPA=; b=om1yGuDh7gisGCBEp9wec0EBHz tw1BhcbNUNvaA5hUdVzkkyZe3CBtI/AJt/KOIG3g9FYsbXEexd6smDhKPvxVlciu oL3jMKqB390R8J3daj+DAfDYVJtgH+8Mz96uMhziWmUonlsD8qwf+zIKIdTLXmzO vZCYBq/kBr+TlgpqULK9iNUOBsNP8+j1iUAaJ+bG81B+rkik81Z8mO4JSxuVOPeZ NaiXkPShgTfX1S+h4lO2gJ5rozzDg5aYLWUwKAomN3mx7CqjktQ6/qbO7hmTWhUg OduK4JjSMUaeCipf3tEmz+iYUklZR/sy13zZxfqdit4p+b96I59N5/SXzJKw== 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= fm1; t=1717408005; x=1717494405; bh=KlSva9prd8AHhi47XCaqbHhZz5Ea 03tJcBEaLUcFFPA=; b=MYlRM707Ziskg0WQxVDycVb3qQ3xLN4hBN9L1l2pcprd ZspYNJBbvp3jZxgegpb18avhTslmHvylbRv7qQHujOm7XKFtVWA789sVhCHNhP/z YIg2zrrVXUBuT7rXIsuRpYaSw3liEnkP+d0/MKGHoypP8f6QLTpFLg5RZKuu6YoX AoPcldFsuQi8SzNNxu6GrsMi7aDiRM9TGfAaikLEl53QYp2rrUP57+2LGR2/T29x wQnjkjo/IKCSSvYDd0bFkBePSQ3zsV4DzonwURfyBFEaF92T0Zu0FqDH7yu5vOg7 WyGbJqrBanDamCsNd870T/nG3o6jb+db6aU7So6izw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 3 Jun 2024 05:46:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 2f2f475a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 3 Jun 2024 09:46:20 +0000 (UTC) Date: Mon, 3 Jun 2024 11:46:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/29] bundle: plug leaks in `create_bundle()` Message-ID: <0c8c97cded4b5070f9c1d4b35729636279f87b96.1717402439.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 bundle, we set up a revision walk, but never release data associated with it. Furthermore, we create a mostly-shallow copy of that revision walk where we only adapt its pending objects such that we can reuse the walk. While that copy must not be released, the pending objects array need to be. Plug those memory leaks by releasing the revision walk and the pending objects of the copied revision walk. Signed-off-by: Patrick Steinhardt --- bundle.c | 29 +++++++++++++++++++---------- t/t5605-clone-local.sh | 1 + t/t5607-clone-bundle.sh | 1 + t/t6020-bundle-misc.sh | 1 + 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/bundle.c b/bundle.c index 95367c2d0a..9af558c7a9 100644 --- a/bundle.c +++ b/bundle.c @@ -500,6 +500,7 @@ int create_bundle(struct repository *r, const char *path, struct rev_info revs, revs_copy; int min_version = 2; struct bundle_prerequisites_info bpi; + int ret; int i; /* init revs to list objects for pack-objects later */ @@ -525,8 +526,8 @@ int create_bundle(struct repository *r, const char *path, min_version = 3; if (argc > 1) { - error(_("unrecognized argument: %s"), argv[1]); - goto err; + ret = error(_("unrecognized argument: %s"), argv[1]); + goto out; } bundle_to_stdout = !strcmp(path, "-"); @@ -591,23 +592,31 @@ int create_bundle(struct repository *r, const char *path, /* write bundle refs */ ref_count = write_bundle_refs(bundle_fd, &revs_copy); - if (!ref_count) + if (!ref_count) { die(_("Refusing to create empty bundle.")); - else if (ref_count < 0) - goto err; + } else if (ref_count < 0) { + ret = -1; + goto out; + } /* write pack */ - if (write_pack_data(bundle_fd, &revs_copy, pack_options)) - goto err; + if (write_pack_data(bundle_fd, &revs_copy, pack_options)) { + ret = -1; + goto out; + } if (!bundle_to_stdout) { if (commit_lock_file(&lock)) die_errno(_("cannot create '%s'"), path); } - return 0; -err: + + ret = 0; + +out: + object_array_clear(&revs_copy.pending); + release_revisions(&revs); rollback_lock_file(&lock); - return -1; + return ret; } int unbundle(struct repository *r, struct bundle_header *header, diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh index a3055869bc..9a1390a98f 100755 --- a/t/t5605-clone-local.sh +++ b/t/t5605-clone-local.sh @@ -4,6 +4,7 @@ test_description='test local clone' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh repo_is_hardlinked() { diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh index 0d1e92d996..ac5ce9b648 100755 --- a/t/t5607-clone-bundle.sh +++ b/t/t5607-clone-bundle.sh @@ -4,6 +4,7 @@ test_description='some bundle related tests' 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/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index 3e6bcbf30c..fe75a06572 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -8,6 +8,7 @@ test_description='Test git-bundle' 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-bundle.sh . "$TEST_DIRECTORY"/lib-terminal.sh