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 1w89Tu-000G3U-1h for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 04:16:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w89Tt-003nhI-0o for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 04:16:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w89Ts-003nhA-36 for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 04:16:33 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w89Tq-000000008S8-3Vp8 for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 04:16:33 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2b23f90f53aso3949755ad.0 for ; Wed, 01 Apr 2026 21:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775103389; x=1775708189; darn=lists.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=rb19+YMmYoNhWKQwRVem8yXHY84cNfL0N+lCDmPZK2A=; b=awxfoibw4nAaG+mON0MUg/iyC0ZfM2c5o3+LLKm9hLGXovlA7JscDDltFD92niclvK HnwhpyFdsUoautCrAyzjKxgY0P4rtx3fw/NMVI+Ei5Fr5SKcgKD4hjYc/KVjJ6IAFaLb sDKYZuM0m/zV2aHt9sSVcJjO1WgZDW7q1JgQhTeZrWOyjMokQwOpoa04NIkE26IZkmY3 uILgqWhZuNqGBjtfWpBVPXDFxELHKD1z3N17K0t0U2ukdlLCsZYELk8TND4PrZX4/Bfq CwlEsvwdb6SoIOMiqdz8tPoley/fNNYTyrTlArCzSljVUJdkxTLEnE/5vtERCut/elFT r59g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775103389; x=1775708189; 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=rb19+YMmYoNhWKQwRVem8yXHY84cNfL0N+lCDmPZK2A=; b=fskBCr/fww5MjojQEHvzBc4FLWvOTahszWQ67d7UjDX/A6qXPsU4qOokoORfJE5nk3 wGYUF0z8oFH6gvAL1dOP0pHRuMWvYWKCWN4mytOG/7NWUZFRgaXj4b7By6pjLDBsB9Ur cm9DDntPh7wm67isQ4NU99OaGQuP94I+aOXMczX4kKo88tgk/EbEjWm8yymyi1FDUVtB OQ8+PWVh01fHQkqwXJEdhj/vGtab2wFyt5/BYapYByYTQSxBuNVIrGXgZnKB8cvZS0mu c7WMhvjZASREvrMwgAIcCpk2lMgQSL8qublN/V/fQvvNRV3fZaYSZc4Vq7Mkx0diSJjy bsMw== X-Gm-Message-State: AOJu0YyCvWKh734cVUQ19J04AZLfuxaEqCB8GiPGxRTIyOEDLx5ZGsxh uN9xX1FBUPryebejL3SRpWoHulYY1Zz9IAsEqahDrh2ZS2/8a0BvA+XEGOoyJMRb7+8= X-Gm-Gg: ATEYQzxEbbPeR2e1rKzmQEtTyY4Pvv2HvTVz4yUR4fU/WFQLBMIKVFXL6PDFTbQO+tC znEIXaBzDoVH3SYBRWHPnLjQPfbMw67RwmRkyo/+SVQdUBsPoufJC2RTx+T1h4jRWP0VK4towZ8 WZgs34jE/B8DBZZFoADM34AWkBLqToIFLPYY6tpo9Q0gghoWP8iAukf1NAp2iET1+KoOUyIg71h zcf7WESCWl0J9DiB8b0P3m3fCEah1bQcvIj5fBIisrujH6QzTkpInTPlgqoXlIo2WzmeHsn/ypT Dv1+ggSIYbu0pW78cKxzGsMhQjwBikTtB6hdIFbU59CwHyCDQENuGYWh2iAAL0tTTmOWksHh+QL DLOB1vd6Ao84/mLSDlFNXaihTlBd4o1gA6ZlE4ubZUIE4/J6OJ3W44ezm1n0na6o/jrIDlTMzlo KTJQb4JFUq8QNSHRCoDuof+r2bD8zW9aM= X-Received: by 2002:a17:903:1b6d:b0:2b0:bebb:1081 with SMTP id d9443c01a7336-2b269cffdfamr57338185ad.28.1775103388753; Wed, 01 Apr 2026 21:16:28 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b2749a4091sm12774495ad.64.2026.04.01.21.16.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2026 21:16:28 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Check some unchecked fclose() results From: Chao Li In-Reply-To: <53d0ef41-e11e-4d2a-9aaa-48e9f0cf02f9@proxel.se> Date: Thu, 2 Apr 2026 12:15:48 +0800 Cc: PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <7E8BB5B2-CECC-4D1E-AC41-5D5142629271@gmail.com> References: <191398CF-C65F-4751-B704-7C904BCBB80B@gmail.com> <53d0ef41-e11e-4d2a-9aaa-48e9f0cf02f9@proxel.se> To: Andreas Karlsson 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 2, 2026, at 09:16, Andreas Karlsson wrote: >=20 > On 3/23/26 3:22 AM, Chao Li wrote: >>> My criteria for including cases in this patch were basically: >>>=20 >>> * only output file descriptors >>> * code paths where the logic is relatively clear and easy to handle >=20 > Those criteria are not enough as can be evidenced from some of the = cases which you patched. I do not see why you would want to error out in = the following two cases: >=20 Thanks for noticing this patch. > 1. When writing to e.g. a log file and we do not call pg_fatal() if a = write fails. Then it makes no sense to die on failed fclose(). >=20 That=E2=80=99s a good point. I think you referred to the change in = pg_dumpall.c and postmaster.c. I didn=E2=80=99t consider that point when = I wrote the patch. But I think it=E2=80=99s arguable. Like in = pg_dumpall.c, there are a lot of fprintf, check results of every fprintf = might be redundant, checking a single fclose() might be cleaner. Anyway, = I don=E2=80=99t want to argue hard for that. > 2. When creating an empty file. I could be wrong here but in that case = fclose() cannot fail. Arguably maybe we should use open() and close() = then instead of fopen() and fclose() but handling an error which can = never happen does not add any value. >=20 Even if creating an empty file, fclose() could still possible fail. For = example, creating an empty on a network storage, while fclose(), the = network connection might be broken, then fclose() could fail. > Please review your patches a bit careful before submitting. You are = doing some good work with finding bugs and reviewing patches but it is = clear you do not spend enough time per mail making sure it is not a = false positive. >=20 I might have missed some points while working on the patch, but I=E2=80=99= m not sure how you concluded that I didn=E2=80=99t spend enough time on = it. I did make some =E2=80=9Ctoo quick=E2=80=9D mistakes in my first few = months working on the hacker work. Since then, I have made it a rule to = do self-review, build, and testing for every patch before sending it = out. Of course, I am still human, I cannot guarantee that I will never = make mistakes. But your comments made me realize that a cleanup patch covering all = fclose() is not a good idea. Each case needs to be evaluated separately, = so a broad cleanup patch would be hard to get processed. For that = reason, I am withdrawing this patch. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/