Check some unchecked fclose() results

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Check some unchecked fclose() results
Date: 2026-03-23 02:04:07
Message-ID: 191398CF-C65F-4751-B704-7C904BCBB80B@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

This morning, while reading through recent commits, I noticed that 69c57466a added a check for fclose(), with the explanation that “write errors (like ENOSPC) may not be reported until close time.” More generally, an fclose() failure can also reflect an earlier buffered write or flush failure that is only reported when the stream is closed. So it seems worth checking these calls in other file-writing paths as well.

So I did a quick search through the source tree, and I found several other fclose() calls whose results are not checked. This patch fixes some of them.

My criteria for including cases in this patch were basically:

* only output file descriptors
* code paths where the logic is relatively clear and easy to handle

If this patch gets processed, I would be happy to spend more time handling the remaining cases. Or, if committers think all remaining cases should be included in this patch, I would also be happy to expand it.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-03-23 02:12:57 Re: CREATE TABLE LIKE INCLUDING TRIGGERS
Previous Message Jianghua Yang 2026-03-23 01:36:22 Re: basebackup: add missing deflateEnd() in gzip compression sink