| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Check some unchecked fclose() results |
| Date: | 2026-03-23 02:22:53 |
| Message-ID: | BFE80E46-3730-4178-B305-0AA1E6A831A9@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Mar 23, 2026, at 10:04, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> 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.
>
Forgot to attach the patch file. Here comes it.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Check-fclose-failures-in-more-places.patch | application/octet-stream | 5.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chao Li | 2026-03-23 02:48:25 | Re: Use-after-free issue in postgres_fdw |
| Previous Message | jian he | 2026-03-23 02:12:57 | Re: CREATE TABLE LIKE INCLUDING TRIGGERS |