Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vnqab-00CTbk-1h for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Feb 2026 04:03:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnqaa-00EwMj-1z for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Feb 2026 04:03:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vnqaa-00EwMW-14 for pgsql-hackers@lists.postgresql.org; Thu, 05 Feb 2026 04:03:32 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnqaX-00000000cl0-2OpJ for pgsql-hackers@postgresql.org; Thu, 05 Feb 2026 04:03:31 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-81df6a302b1so625224b3a.2 for ; Wed, 04 Feb 2026 20:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770264208; x=1770869008; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jNYLhRzGjiXGUfEzUcdrWecph5C7nBgttfJCFFOe4L0=; b=kRyCydz3r8xa/LKLIHI+rT4JU0qJwqnTKPyvpwjemk0oIxVaFXdw8ElSGB5KZHyN2Q OkSRsUGhrBq1XwsBnPHMdvJRvox4LQGASMhKuZ8R7hfvpdaZEyHlUGUze9N7syF2zC0U 6nvbrZ/vLjp7Ww05Rbn9YIzaKUB7XS7cPJwTtPKDG2GGN/w1EDKMcuMHUliSEjuUiGOi OaDOl9bAyw0gNO5B6HpemXpB4QKTDivbELOUsVyQ6GZCOOZlNzf28GLIxsgglMg7TR3V n2JVGq/UgRIhgCNB2UTa64NSnIXIEOEtm+sqNTxBh/Ml1/AWCso10BJzuFu0+K5RHEjY +4pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770264208; x=1770869008; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jNYLhRzGjiXGUfEzUcdrWecph5C7nBgttfJCFFOe4L0=; b=qIaMOeMOpzlKfLtP1VTVxtu9Gqi5qn7jvXiXGchiGvuyEc+MElIw75nuoy+sMTmKbZ /h8llUX2mr8fSl3RmsVoIbvrmbreevdmg6rTuNUKjXBNrER1OB6/2x52VvOVQ9P4y41Y t0V81Mx9scNoq1XO1jt3akcWzNdy0aNtmPNVF7eIsrdvXjVo5an47h2aaJi24QrZcIz0 Dsx4Kgex3UmICWYJAAW80B5wGS9UrImSZi5t4a8JoCVKUTr4us2GaxYbRZJcgfJa1ePI YwiS17GkvfTIkBgUAx/JkkDd/p4hQy12uSlkBc7IWPjHUe88ZQc9MrEq2U+XEcUtsNKc /QbQ== X-Gm-Message-State: AOJu0YxyqKVFfFdWExUWdH4hJF+bkZhrX/OKJBHT27a4/IJSN6ho0UGH QkIck6uzdr8sJyC2K2QhMWhA8pG6im3HLLdr5ivPqMcTCk+vSYFYzCCGMtFWL+tRQwrdKA== X-Gm-Gg: AZuq6aIeQ94RwYwnuorTFlF6xcDq9cgopV1bHRVMGxYmNXHOJgU6qPHW9zekRe5e0ym +OHyw8K2F3cMrRXZzxT5Kwl3ugOkS5fLns+6JvsiQbL6LfDiAE3wQKelGIgWUxoNhfi5Aynt62w w3as8rvPBkwKbb37ZzhPQf94XfGPPa03doHJoP3AJkxiJ5ekMcY7qDdaqSYau4C+tWEJE9OFP+n Pikz0//mWDFYf0eQhvw2X72FOq68qZ6P9VDGWwoIITQlaa6Fu2Fj6gIz1wG07LF11AYlG2xd1KT WTgknM0oALWJcn7f1405Rzakk2eKJ2cn4oRTVrXWLpRnI2hvnOgaEviOlpAFpbqgsPESr3sko8q 9wfGdF0GNQXiu8uiX7Jo95NNoAMcDbq2bKS6Wk+z0LF0Yn0mmC5MHLKPAUjUOSVzwcxOhoRcJZa 61akzRj8JDNJMU94tzOaU= X-Received: by 2002:a05:6a00:390b:b0:81f:9b09:ad02 with SMTP id d2e1a72fcca58-8241c1b3c10mr4914286b3a.1.1770264208429; Wed, 04 Feb 2026 20:03:28 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8241d478975sm3841530b3a.52.2026.02.04.20.03.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Feb 2026 20:03:27 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: Re: pg_upgrade: fix memory leak in SLRU I/O code From: Chao Li In-Reply-To: <20260205105433.9fcc5f980241bb35a6517448@sraoss.co.jp> Date: Thu, 5 Feb 2026 12:02:51 +0800 Cc: PostgreSQL mailing lists Content-Transfer-Encoding: quoted-printable Message-Id: References: <5DED17B4-D948-4C0B-9DE1-A915D0BFAA54@gmail.com> <20260205105433.9fcc5f980241bb35a6517448@sraoss.co.jp> To: Yugo Nagata X-Mailer: Apple Mail (2.3864.300.41.1.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Feb 5, 2026, at 09:54, Yugo Nagata wrote: >=20 > On Wed, 4 Feb 2026 17:20:49 +0800 > Chao Li wrote: >=20 >> Hi Hackers, >>=20 >> This comes from a previous review and has been on my to-do list for a = while. >>=20 >> Since src/bin/pg_upgrade/slru_io.c includes postgres_fe.h, it is = frontend code, so backend memory contexts are not used here. >>=20 >> In the current code: >> ``` >> void >> FreeSlruWrite(SlruSegState *state) >> { >> Assert(state->writing); >>=20 >> SlruFlush(state); >>=20 >> if (state->fd !=3D -1) >> close(state->fd); >> pg_free(state); >> } >> ``` >>=20 >> the SlruSegState itself is freed, but state->dir and state->fn are = not, which results in a memory leak during pg_upgrade runs. More = generally, I don=E2=80=99t see a reason to free an object itself without = also freeing the memory owned by its members. >=20 > As far as I know, AllocSlruSegState() and FreeSlruWrite() are not = called > repeatedly in a loop, and the amount of memory involved is small, so = the > impact of the leak seems limited. That said, I agree that it is better = to > also free the memory owned by the struct members. >=20 > Regards, > Yugo Nagata >=20 Hi Yugo-san, Thank you very much for the review. Yes, the leak itself is tiny, the = main point for me is that the memory owned by the struct members is not = freed, which can be a bit confusing for code readers. As for the change = from pstrdup() to pg_strdup(), that felt too trivial to justify a = separate patch, so I took this as an opportunity to clean it up at the = same time. BTW, this is the CF entry: = https://commitfest.postgresql.org/patch/6462/, you may mark yourself as = a reviewer. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/