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 1wFRLh-0057H2-31 for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Apr 2026 06:46:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wFRLh-00C3bp-0P for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Apr 2026 06:46:13 +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 1wFRLg-00C3bf-2h for pgsql-hackers@lists.postgresql.org; Wed, 22 Apr 2026 06:46:12 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wFRLe-00000002D5m-2gFY for pgsql-hackers@postgresql.org; Wed, 22 Apr 2026 06:46:11 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2aae146b604so33992675ad.3 for ; Tue, 21 Apr 2026 23:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776840370; x=1777445170; 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=e3LZ404O1Hla9ku3bDB/zslqthNCOXWOfoPeMSDhdAc=; b=W6Lp9VryOOnMDlHdkJ8S6MQ7JJgcc5PzEcnJZyTCB/SFhlw3/dRbdia1Tzhw9Ie4yX WlbLmrPdIdOUJoj+GQfbhiinskIRImHC0d/s/IXBF6CVpp5pTvIHG3woRvIUFP1PBx8T YhnO5kT2YhiaSUDhzPYcdpjFDpi6nwJSDLu3TcXyecUPC1hugN/0tWW3Mrkq/SrDdI3Q K6gBfwEzuihdS79S6WKBB3zpKDJZWy2pEpRKRIW7Gy+L3YunN426RM4F7j5M5WqJTF8A KoLxppUYsQ6Ata9CLVHG7EJz1bFgURjSP7MwKF4qpE51dO6yohARWEkVex98F9jIKbku VZwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776840370; x=1777445170; 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=e3LZ404O1Hla9ku3bDB/zslqthNCOXWOfoPeMSDhdAc=; b=nMWk4XsU66c+G5pdALsRnUBWJL8duuDq2EDmudBMkcxrHRe9YPJZkphUntbM3Q/Zso slkuRny9jTzkEZ7WAhk9/9WFrHvQYO+6AwCdJpooAzDs4avh9c+H1Iv2lz+0tm6Lbord xqQr2pBKI2yiyDVj4c5i/Ccru6tU9rmH1pgop234i7kO02cHIE8NmJQAb/D/KS2ZfNOH HIOC8JwBWnlhIgPHGfTFZz//e7RytiWqzlM5zngLTGWDVGPesuk30PIcXWViKTEcojyI oWt2mkqkc1xwVeXGrqAEuS9bjT4M50wgzHItyK8RCBde3K4jP65r6dnwfYtPzQUJ1+Lm dPXQ== X-Gm-Message-State: AOJu0YxkgQMARvdbga2qSube1bF2abn1xtxoWJ657E6mipuFoTmSR+U2 fJcHKLhtH0ORDUoc7IX7QyNv+8AAkITQb2H3nsGWbxSgv9VYrtEd04I5 X-Gm-Gg: AeBDievCLKXHiuDNt9zmxyYS1b9axNtVwSTU9dlsQtmKw8xdpAbp7/JqLzhhdJfjRFa BCj2U0QrtdxMcIdQ8tp2n83J18W5hot4XzpiENBK/pFXthjhPp/BpYlusgg2fzEebjyk++iUUHH KEI5BPk/TVM2wWEmo7YlMkz1qCMsRrIJOHoZXW+ZgKGcxOj3hHyP/5xEIAJoiMNSJChsVfs8EFF 3M8o7nDbiRVkwRhbeQpaxbynqi7lXVzWfqPlasdSUGTAWn3FDM06jRMRo2lh9syWbj4h936yGTs 6LCNkhjwjqYweyhS85+SI7qfVjkRCRb7KjNIUhccYoZCTlmYfv17X0zgtMHm+U+uYCTj6o/tfFa vfs0rzYHl8BbvqWSbGGp2VNII/A9G9Urq0DC7Nm8eVMvxdN10ARkJ23UNJzbBME5R9qqxQXMPex QXPFAimXgDbgm1n3JDDK8/fRgld4sVfHrhfZVufDVwWw== X-Received: by 2002:a17:902:b695:b0:2b2:cfdf:10f2 with SMTP id d9443c01a7336-2b5f9f4e6e5mr165580895ad.20.1776840370042; Tue, 21 Apr 2026 23:46:10 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab0cf3bsm182513695ad.44.2026.04.21.23.46.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2026 23:46:09 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Fix memory leak in postmasterMain From: Chao Li In-Reply-To: <3e890874-8204-e1c2-8def-3a02cbad2232@0x48.dk> Date: Wed, 22 Apr 2026 14:45:29 +0800 Cc: PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <1658D50F-A8B3-406A-94ED-FA8C7F9DA90B@gmail.com> References: <3e890874-8204-e1c2-8def-3a02cbad2232@0x48.dk> To: Henrik TJ X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 21, 2026, at 22:56, Henrik TJ wrote: >=20 > Hi >=20 > On Sat, 21 Feb 2026, Henrik TJ wrote: >=20 >> This is fairly inconsequential as memory leaks goes, but if -D is = used when starting postgres, the memory allocated by stdrup() will never = be freed. Found with valgrind. >=20 > Rebased version of this patch attached. >=20 > To see valgrind catch the leak: >=20 > 1. Compile with valgrind. > 2. Run postgres with valgrind: > valgrind --leak-check=3Dfull ./pgrun/bin/postgres -D pgdata/ >=20 > The -D argument is required, as it is the argument from there that = does not get freed. This should yield: >=20 > =3D=3D444240=3D=3D 8 bytes in 1 blocks are definitely lost in loss = record 29 of 849 > =3D=3D444240=3D=3D at 0x4840B26: malloc (vg_replace_malloc.c:447) > =3D=3D444240=3D=3D by 0x5114A2E: strdup (strdup.c:42) > =3D=3D444240=3D=3D by 0x6B7CE0: PostmasterMain = (../src/backend/postmaster/postmaster.c:656) > =3D=3D444240=3D=3D by 0x602555: main = (../src/backend/main/main.c:231) >=20 >=20 > best regards, = Henrik =46rom my experience, most of the time the postmaster is started with = -D. On Linux and macOS, that path can be quite long, PATH_MAX is often = 4096 on many Unix-like systems, and I am not sure about Windows. So I = think this leak is worth fixing. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/