From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh7-smtp.messagingengine.com (fhigh7-smtp.messagingengine.com [103.168.172.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 685A42F50 for ; Thu, 8 Aug 2024 05:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723093496; cv=none; b=GtSgeU9Iswpbg2lphMrEOAGR52kPNCprWCUeDGtIuCWL9MqA15X4oaK6ip8TdCRqyXYew1MkghTJ8BJRmLVa2oAkNeJv9Nrfvp5Q6loRIkLJnVdW4do47LkU8vamqGS8qflKfbxS/bY7VVXSPCdHGRjDhwsUugcZXVcFas0rbhc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723093496; c=relaxed/simple; bh=aIVFXtlVSYaRRwGLoiv8yz7ZZnL9YBGzxw1VHTEEFK8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PLWMtKrH+FeIc4oX0L+aJiYa0erzvN8cQjeWyITnVtCZRaO9XYEr70klIPgXvYvdlFa6DGhXEdqENPpdFkSiQnr/rOIkNj8fAmdWCCUCqOvJhRU9GT5Dda1no/Lh37IL6Vg8H84s5VRhrF51R0IM5YoWLGhL68zMm+vkkkaHq1c= 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=Trk+8aD2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NVqXIEfV; arc=none smtp.client-ip=103.168.172.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="Trk+8aD2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NVqXIEfV" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 835F11151C47; Thu, 8 Aug 2024 01:04:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 08 Aug 2024 01:04:53 -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=1723093493; x=1723179893; bh=XHWNXkbpTO 8rKb2EFKNX/fuvguY/ZxBsIylO5wqNiRE=; b=Trk+8aD2miM80jk6WEp1donUNC e52I44AjmTZlobuG1RD/1YPdK968hH24h8gYaEKzOHSZ0IE3e9WgLkjfBpWgqJIo ItGvVSzvM4BHpWUM6KFplFwfMaSwuwnYyXcGvN7XS0pK81IwInX6VP/b1jdJKn3z ypYGgOL+ePQgeYkTMt5dAMsjQ38UUxAHdQs7aQ5oeQ85AYeGAYsRFSS5eW5xn70M RLAPP6q28IBbYZ8qWQMZqT6+oKRypF4AvQXuKiQw+wsq9qLeB4CxX8S/9jBaT1gK AOPtmvc5m2EbZJChgPQZPdMvH9D3LjboJXISjmL8ouZi+7/xOQls6TJv0yRw== 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=1723093493; x=1723179893; bh=XHWNXkbpTO8rKb2EFKNX/fuvguY/ ZxBsIylO5wqNiRE=; b=NVqXIEfVCtCZ1ycjl52yt/uA3zNU70LjzkHz3qg+B00r RIHhsJY0DoBcAu3nYjLHW+OV/y9HavvPwpciwDsyMpTmya2fN2GtVvNqELs/dhv+ yxXEmHrpZKMTy3P/OBNWtpyVczfQ0i8Oc8vFJ3huG9J5CKomCoJG94mCQE0VOiZ3 7V7FHPedsPmQ5Qf3LXLcLvFW/8Edl+dOzKUabGevuI1TRyNjRnusSV1BGyX/6YW7 7H8kkGGSyIdIjF3BVYKTDxurfxctGvat9MyL+jpJ2H1cL0OFG/J7yohN93McAX1X 203KZV/9O7vWdUBRVAznbYNRBr9S2T2QSmqd0hpdtw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledugdeludcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehjrghmvghssehjrghmvghslhhiuhdrihhopdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 01:04:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9164ea06 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 05:04:45 +0000 (UTC) Date: Thu, 8 Aug 2024 07:04:49 +0200 From: Patrick Steinhardt To: James Liu Cc: git@vger.kernel.org Subject: Re: [PATCH 06/22] read-cache: fix leaking hashfile when writing index fails Message-ID: References: <2810cada0af14c3331674a807b20d18e6c9af022.1722933642.git.ps@pks.im> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="BzVET1eMFuDd3T4E" Content-Disposition: inline In-Reply-To: --BzVET1eMFuDd3T4E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Aug 07, 2024 at 05:01:17PM +1000, James Liu wrote: > On Tue Aug 6, 2024 at 7:00 PM AEST, Patrick Steinhardt wrote: > > Refactor the code to have a common exit path where we can free this and > > other allocated memory. While at it, refactor our use of `strbuf`s such > > that we reuse the same buffer to avoid some unneeded allocations. > > > > @@ -3105,7 +3117,14 @@ static int do_write_index(struct index_state *is= tate, struct tempfile *tempfile, > > trace2_data_intmax("index", the_repository, "write/cache_nr", > > istate->cache_nr); > > =20 > > - return 0; > > + ret =3D 0; > > + > > +out: > > + if (f) > > + free_hashfile(f); > > + strbuf_release(&sb); > > + free(ieot); > > + return ret; > > } >=20 > Is it generally a pattern in Git to use `goto