From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (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 A357E5383E4 for ; Tue, 29 Sep 2026 18:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790707025; cv=none; b=d2QjeA/1q/Ur60boBpQisaIjLIF6AXqZUyL/jPMxmXjfS0Sjr0AhpLT0MkEiDSe6x/Fu+dFmrGyi761/tRHz+B1DVNbKOcQ0K8Ga1Rnn+qE70/dVnNlCIIlOyVC2C3UavMeA+HKAg0LzBB5tyM2vTGh1P4ZtjAygxuXb+QEyAfQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790707025; c=relaxed/simple; bh=GoMA5ca2Edj47EzmkJlsmHf/1hWu0/88A2kCsy4IMqg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=PqC29ohUXO6gZyhdM3eGV+ivjx+MCRixscjo9aXAnvsicsOcpGEZY47LZV7DhWFg2OtHbD+PMDD8lPN4RhbdwILmMQXIe0xpYmRVgFQhg59NlkUXQDTDrEnsCH8ftKqwCqKc6jxkI16jTznHQDXOq0ldn4nEq9cpjOIFnQJhO2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=Xd6MzKOv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EJR2ROfd; arc=none smtp.client-ip=202.12.124.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="Xd6MzKOv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EJR2ROfd" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id CBED41D00060; Tue, 29 Sep 2026 14:37:02 -0400 (EDT) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-03.internal (MEProxy); Tue, 29 Sep 2026 14:37:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; 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=1790707022; x=1790793422; bh=DRXAdkKfSJ gbT/z3F4vRLCwpDWoh7jRolvvCffeLlp0=; b=Xd6MzKOvS1xk1aqVgD2Daw5nBo vFzFo16nK8wfYd89uPSQLZzlxuX8KbVexPpzwezFbNPnIQhfMxkfpLhteDg+t9QV eomtHBA6cFIrYZSahQFh0bec1SNHlZM3DcnrqmcPun708battb5TFJCMUP/p31bq S90+ntrlxH3XhNPxpkzegnw2a1/lT1iXlIM8qKrodn3+U7tGL/gP+vcF1loROmx8 eivOVyZ7FEL8tXVHSMRiqj5f13oQ3dGsH31VYf0RTp8SptiV78y2iLQX3HTiCqaS RFPnb5v7/NYwVY6B/79ZCDFzeDapdIi9zj9J7gcm3x7lVD4vy4Ld3J5f3X2A== 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-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1790707022; x=1790793422; bh=DRXAdkKfSJgbT/z3F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8838CY0nwrbEocYg2k5zoSCrGR5TQg X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 29 Sep 2026 14:37:02 -0400 (EDT) From: Junio C Hamano To: Jeff King Cc: git@vger.kernel.org, Elijah Newren Subject: Re: [PATCH 1/5] xdiff: clean up read_mmfile() allocations on error In-Reply-To: <20260929065131.GA1697497@coredump.intra.peff.net> (Jeff King's message of "Tue, 29 Sep 2026 02:51:31 -0400") References: <20260929064935.GA1276867@coredump.intra.peff.net> <20260929065131.GA1697497@coredump.intra.peff.net> Date: Tue, 29 Sep 2026 11:37:00 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Jeff King writes: > When read_mmfile() returns an error, it may or may not have allocated a > buffer in the passed-in mmfile_t. So callers must initialize the pointer > to NULL and free it even on error. > > Most callers do this already, but rerere's diff_two() does not, and > would leak the buffer after a read error. We could fix it directly, but > let's instead try to make the interface less error-prone by freeing the > memory when returning failure from read_mmfile(). > > This fixes (part of) the leak in diff_two(). In theory it also lets us > simplify other callers to skip initializing the mmfile. But in practice > most still need zero-initialization because they may jump to free() > before even calling read_mmfile (e.g., in try_merge()). But we can at > least simplify rerere_forget_one_path() a bit. > > I said "part of" earlier. There's a related leak in diff_two(): if > reading the first file succeeds but reading the second fails, we return > early and leak the first buffer. We can fix that by checking each > individually. Nice. Thanks for plugging my leaks.