From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (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 4BD642571A0 for ; Sat, 25 Jul 2026 00:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784940210; cv=none; b=X9bS8rOsJuVHumT+nN4iGmV46iT4TIhs2BU2I6jOb7F4zgUozEm6PSvvXZFaWs6be8gd/ud3LXC+yKEv2PuPHtPcIaTXYN4QbMHAJb1PkLPQ41dt6B6Dbg5YbDIcpS83gYxZopZYD5t6icWCilTKg9V8PdfdYHTkSZHbceyqk5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784940210; c=relaxed/simple; bh=i/VHSfV/DzWZs3tCSBxLsO92EO0Ti3E/VcWIwUX8cbA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=LFIB5wyUKPA8ezVY2BeNKCd7y6dzDgZGpBTZPRwNdb5PdxJ1FOEsd6ecB0UVuJWvjM8Wo+fbZKTGGS/Il5FT7eMjSc2TJFhh00k7l1ge87Nl2viJLKNo1KX/iAUkTCkr86yVi2DPeWHEHEHKZWTwzHWHlExhYWhebz0/JjNGuHc= 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=nYOwcbix; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Wgm0rCRO; arc=none smtp.client-ip=103.168.172.146 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="nYOwcbix"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wgm0rCRO" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 8A5C4EC01DB; Fri, 24 Jul 2026 20:43:28 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-01.internal (MEProxy); Fri, 24 Jul 2026 20:43:28 -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 :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1784940208; x=1785026608; bh=YLifFARasdlRrrYlOk+0qO0ofVGf4hTJ ri1hZzpugBM=; b=nYOwcbixsS2b6Z+TEApFDilAbksiBROKE88VI9gfyVKTKGrD GQyOV/rJvv67CPsDbWoMF0c7RoarCtQ7L7TBY4p7YntP1Ol6D+nowXQwLR/7cY83 i0EwIhUbsgAPEQRJGclYWjTxZRrkJKppn87xtXCasZjKVzOQqtSMCQx9RakQNeEt xXJZOt1WnXYMvbbnUOJpSbyinHQ5RP3upH5T3IwWo13E1e0AYOSAq2L3tN5kjscH yP69cbwbsOQ+SY3cf/UkBbMP0/c9V9Klb/Exc9NQZUt8JltSrlrFm2DhdaZFDD4F TgJOYoB+MB+Qy1oGoa/vjnLjsyMUEF8ar1AWTg== 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:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1784940208; x= 1785026608; bh=YLifFARasdlRrrYlOk+0qO0ofVGf4hTJri1hZzpugBM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jrWxOYYbXvNF7S7A X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 Jul 2026 20:43:28 -0400 (EDT) From: Junio C Hamano To: git@vger.kernel.org Cc: =?utf-8?Q?=C3=89ric?= NICOLAS Subject: [PATCH] remote: plug memory leaks Date: Fri, 24 Jul 2026 17:43:26 -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 The in-core data structure used to keep track of 'url..{insteadOf,pushInsteadOf} = ' settings is not properly cleaned up when the process is done with it. Fix the rewrites_release() function to free not just the 'struct rewrites' instance itself, but also allocated structures that are pointed at by the 'struct rewrites' instance. One of the embedded structures holds a 'const char *' to point at a borrowed constant string from a configuration callback. Since the code does not modify this string, stop copying the value (alias URL) before registering it in 'struct rewrite', as nobody is freeing this member, to avoid leaking the extra copy. Signed-off-by: Junio C Hamano --- * These are not recently introduced leaks as far as I can tell, but the new tests in en/submodule-insteadof-remote-match expose them. remote.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/remote.c b/remote.c index 368a43c1b2..e3d4b25040 100644 --- a/remote.c +++ b/remote.c @@ -309,8 +309,11 @@ static struct rewrite *make_rewrite(struct rewrites *r, static void rewrites_release(struct rewrites *r) { - for (int i = 0; i < r->rewrite_nr; i++) + for (int i = 0; i < r->rewrite_nr; i++) { free((char *)r->rewrite[i]->base); + free(r->rewrite[i]->instead_of); + free(r->rewrite[i]); + } free(r->rewrite); memset(r, 0, sizeof(*r)); } @@ -469,13 +472,13 @@ static int handle_config(const char *key, const char *value, return config_error_nonbool(key); rewrite = make_rewrite(&remote_state->rewrites, name, namelen); - add_instead_of(rewrite, xstrdup(value)); + add_instead_of(rewrite, value); } else if (!strcmp(subkey, "pushinsteadof")) { if (!value) return config_error_nonbool(key); rewrite = make_rewrite(&remote_state->rewrites_push, name, namelen); - add_instead_of(rewrite, xstrdup(value)); + add_instead_of(rewrite, value); } } -- 2.55.0-576-g1c3ad6b142