From patchwork Mon Sep 30 08:08:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13815530 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 56606180A81 for ; Mon, 30 Sep 2024 08:08:55 +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=1727683736; cv=none; b=qLiuUwxCK2ufA09eLwv6ffqIY2573cRJESbn985kJDt2d++j77d/MR8hE/8EAqiTq2nwhRUAhCC6eGMAzhcYaufAOrG8F69GsO7QqL+Yg4OSS2/OdOmrTJzYyzGB1Tg0BvO8LResmQ1slVCU58Bc7obmArDL6Hy6eOv7R98Fr0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727683736; c=relaxed/simple; bh=Zswhj8bzzwaDVF9AVjXkQKAz1m9kMspBbAzz3AT6mNs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CaXYnB9jtEeH2O3zU3h3bpxSNWY0llevTMAPL1H7Upqa2wOuPZLXXIXaE72S4jGrFAwDg9M8h68TIxyEouBCaNQdeBDgtqEqi1pLKBzgTiAFwwLTMbu2r/eMEa3DKm9rACdFFs8sCAg9Ndi41crH0BvygmB4fw97hDQN6KdAIJs= 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=G6HmKmmT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BJ53XeQB; 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="G6HmKmmT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BJ53XeQB" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 73EA1114020B; Mon, 30 Sep 2024 04:08:54 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Sep 2024 04:08:54 -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=fm2; t=1727683734; x=1727770134; bh=z8Kzk/FqIB ZU/NtRBLbQbHWe9vmBuE9QSNvJ4WCGjKw=; b=G6HmKmmTCb25Oh6g5fyr3nhV0a mzu+Tb3/l9OYoi2Np2A69cGpET05wfI0Z+gkd8lYF6nVWxlg3pFTE93H4QeUEPXF Rl4cbH4eKjOLx3I5sV1YXIm7iDJxprx0m5d++xM98B0czROK50CAaWvRagniuahZ Cg50H/eneS/aMq6FrP0ylWEqG28X1sx+P6WrOewaIzRkvGkFvUScEpDXB9twBosd k8GNI9IOxcikrEtXN1MivpPb777j4p7E+FoJHdGEqXCd/SdqyHBUei9620OvQggy f6tCxoqB+G7JzBT3HjfsT3d9lR7wgzAuM/eIXEGUPJ/Ngzo2hQ5eSHxqHgBQ== 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= fm2; t=1727683734; x=1727770134; bh=z8Kzk/FqIBZU/NtRBLbQbHWe9vmB uE9QSNvJ4WCGjKw=; b=BJ53XeQBjKegTsmoxytoeJw9B1R3LWnbPBGvPc8AFYq7 TlFrAyYtDbTRFUuxhEGduYkIaEU9VZZa8AcLdhY6RBh50rEcHni//znc8dd2QrKQ h7ybzAiA4z5uDx8R/wdSy/0TxGIbd2jVNk4AgPCM37JniAvRmuwEaaRtlLNbjs2J xCqkoKPI6TuUXhBBr798nvXUFrbPu8LOyjJibbQ/h8alYeXtS1wODzTKC7wN2BGE fvtoHmo3umnxgTXn30OPurGjciXPlvgWDVgo47qwwsjxvIuRrImIPxN6zpImse5a RIh8Qd5fJgoBw7Xfp9JDDa0J8fxhddfyei+pCmKUkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeegpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehlrdhsrdhrseifvggsrdguvgdprhgtphhtthhope gvthhhohhmshhonhesvggufigrrhguthhhohhmshhonhdrtghomhdprhgtphhtthhopehg ihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvg hrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Sep 2024 04:08:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a03bbafc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 30 Sep 2024 08:08:07 +0000 (UTC) Date: Mon, 30 Sep 2024 10:08:50 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Edward Thomson , Junio C Hamano , =?utf-8?b?UmVuw6k=?= Scharfe Subject: [PATCH v3 14/22] reftable/stack: handle allocation failures in `reftable_new_stack()` 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: Handle allocation failures in `reftable_new_stack()`. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index 060b2c1b90..1b77c9d014 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -56,10 +56,16 @@ static int reftable_fd_flush(void *arg) int reftable_new_stack(struct reftable_stack **dest, const char *dir, const struct reftable_write_options *_opts) { - struct reftable_stack *p = reftable_calloc(1, sizeof(*p)); struct strbuf list_file_name = STRBUF_INIT; - struct reftable_write_options opts = {0}; - int err = 0; + struct reftable_write_options opts = { 0 }; + struct reftable_stack *p; + int err; + + p = reftable_calloc(1, sizeof(*p)); + if (!p) { + err = REFTABLE_OUT_OF_MEMORY_ERROR; + goto out; + } if (_opts) opts = *_opts; @@ -74,15 +80,23 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir, p->list_file = strbuf_detach(&list_file_name, NULL); p->list_fd = -1; - p->reftable_dir = xstrdup(dir); p->opts = opts; + p->reftable_dir = reftable_strdup(dir); + if (!p->reftable_dir) { + err = REFTABLE_OUT_OF_MEMORY_ERROR; + goto out; + } err = reftable_stack_reload_maybe_reuse(p, 1); - if (err < 0) { + if (err < 0) + goto out; + + *dest = p; + err = 0; + +out: + if (err < 0) reftable_stack_destroy(p); - } else { - *dest = p; - } return err; } @@ -171,6 +185,10 @@ void reftable_stack_destroy(struct reftable_stack *st) { char **names = NULL; int err = 0; + + if (!st) + return; + if (st->merged) { reftable_merged_table_free(st->merged); st->merged = NULL;