From patchwork Thu Aug 8 13:05: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: 13757441 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 F246018CBEC for ; Thu, 8 Aug 2024 13:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122346; cv=none; b=sEx6ZIgOdNJhkUslyJYLSTTt6A+JLIhhwJDj1oVH8z8qY74YNxpp50kibiMLDc9aDG29gzxue2/te5mztkZq3z1xvej8bmnMilC7bklN1CqqxPD1PMQTGx1gmwCHz/I6kZKSL7faaxO/Qf+6EcghA+3MLBfMeVlAWAOyNS6tqWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723122346; c=relaxed/simple; bh=rhP4cgZ8/2QkgMOPLr2lm+02lIck7bhb1EK+3JXdxbc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ghfrdEbnvksDfB1ZMcZoxHmrPHxfoa9cXfb+yK0j9Ddo6loNlHGoScY0qrJhfi1Wlo0v5OADq4OId5/jOcDbpIRHJ7ZxU1ZOOVVVZCj2qlrwKVf84hELnuHIK+Ros5PcCqNEm5tLZBVau8GOKOWmqSuHHB7gm+J2Awl3otNv9KI= 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=INkyfufU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uDHNTjw3; arc=none smtp.client-ip=103.168.172.150 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="INkyfufU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uDHNTjw3" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 242091380522; Thu, 8 Aug 2024 09:05:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Aug 2024 09:05:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723122344; x=1723208744; bh=fGDbC2lrxg mHtTVpLXeAprYMxN9RyFYnJvt/N/UKvm4=; b=INkyfufU3PuFfQQHdzMxpqh8LG nIEMDAa38no94t6tVlICY4JWJ7VRJwXUixB2sZfek2mVeKKMEmmgSYnAnegpmaPL 6OUm4EZewCXrAEXI2fRO+s0Bu42+bDYX2XdAbadtkM51uIIHna8/EpcPsNiisxMs UjtNVqhqvnzzzDpEGjon4G7FsGfPmH45gDMWKU8QhuqU/DglhR1tBBOctIjcpK1q HKMAIx6n+i9l4VesuahCRPB5e471oHPSTntJ0bt5FhYLz6rEqHPEs+1rCM2qS5vF N7f6pIrRAp6TWxJn9CEVunkXl6Hwp6z8tmJmE8R7uyb8Ft5e/XNTaOfSrPGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723122344; x=1723208744; bh=fGDbC2lrxgmHtTVpLXeAprYMxN9R yFYnJvt/N/UKvm4=; b=uDHNTjw3CRBMtGhf4pKdgapdA4HtOF0pEdyoy3/GLUQH KaWeVY1PyLMasSoR+q6G65wV640CsDvOQvurGzUrVzDVuHqViDzgsprUync/M7Ro p9QAX4yUEkjeyUkI4k4akKDGyA5YJlyfNr4SEW2JcIQkIUe7XU3YcpSxSjYs+2Oe I5WL0VC0NusXiVj8IZ4uKwHqAG+20ClXGaBOKEOgGu3WraQ0lEF5nyx7HbI57h+L D7SDibTDuzVxdld2S0YEdRCmkUuRerpcD+Mgbura9RkIsrGuAstNiOrMAAi007Rq SGb9NK6bW2tBep4rrWfsMn5brCFxF+bxYiYZoZLjkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeelnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepphhhihhllhhiphdrfihoohguuddvfeesghhmrghilhdrtghomhdprhgtphht thhopehjrghmvghssehjrghmvghslhhiuhdrihho X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 09:05:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b80517d0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 13:05:35 +0000 (UTC) Date: Thu, 8 Aug 2024 15:05:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , Phillip Wood Subject: [PATCH v2 15/22] sequencer: release todo list on error paths Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're not releasing the `todo_list` in `sequencer_pick_revisions()` when hitting an error path. Restructure the function to have a common exit path such that we can easily clean up the list and thus plug this memory leak. Signed-off-by: Patrick Steinhardt --- sequencer.c | 66 +++++++++++++++++++++++---------- t/t3510-cherry-pick-sequence.sh | 1 + 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/sequencer.c b/sequencer.c index cade9b0ca8..ea559c31f1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5490,8 +5490,10 @@ int sequencer_pick_revisions(struct repository *r, int i, res; assert(opts->revs); - if (read_and_refresh_cache(r, opts)) - return -1; + if (read_and_refresh_cache(r, opts)) { + res = -1; + goto out; + } for (i = 0; i < opts->revs->pending.nr; i++) { struct object_id oid; @@ -5506,11 +5508,14 @@ int sequencer_pick_revisions(struct repository *r, enum object_type type = oid_object_info(r, &oid, NULL); - return error(_("%s: can't cherry-pick a %s"), - name, type_name(type)); + res = error(_("%s: can't cherry-pick a %s"), + name, type_name(type)); + goto out; } - } else - return error(_("%s: bad revision"), name); + } else { + res = error(_("%s: bad revision"), name); + goto out; + } } /* @@ -5525,14 +5530,23 @@ int sequencer_pick_revisions(struct repository *r, opts->revs->no_walk && !opts->revs->cmdline.rev->flags) { struct commit *cmit; - if (prepare_revision_walk(opts->revs)) - return error(_("revision walk setup failed")); + + if (prepare_revision_walk(opts->revs)) { + res = error(_("revision walk setup failed")); + goto out; + } + cmit = get_revision(opts->revs); - if (!cmit) - return error(_("empty commit set passed")); + if (!cmit) { + res = error(_("empty commit set passed")); + goto out; + } + if (get_revision(opts->revs)) BUG("unexpected extra commit from walk"); - return single_pick(r, cmit, opts); + + res = single_pick(r, cmit, opts); + goto out; } /* @@ -5542,16 +5556,30 @@ int sequencer_pick_revisions(struct repository *r, */ if (walk_revs_populate_todo(&todo_list, opts) || - create_seq_dir(r) < 0) - return -1; - if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) - return error(_("can't revert as initial commit")); - if (save_head(oid_to_hex(&oid))) - return -1; - if (save_opts(opts)) - return -1; + create_seq_dir(r) < 0) { + res = -1; + goto out; + } + + if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) { + res = error(_("can't revert as initial commit")); + goto out; + } + + if (save_head(oid_to_hex(&oid))) { + res = -1; + goto out; + } + + if (save_opts(opts)) { + res = -1; + goto out; + } + update_abort_safety_file(); res = pick_commits(r, &todo_list, opts); + +out: todo_list_release(&todo_list); return res; } diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 7eb52b12ed..93c725bac3 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -12,6 +12,7 @@ test_description='Test cherry-pick continuation features ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Repeat first match 10 times