get_controlfile() can leak fds in the backend - Mailing list pgsql-hackers

From Michael Paquier
Subject get_controlfile() can leak fds in the backend
Date
Msg-id 20190227074728.GA15710@paquier.xyz
Whole thread Raw
Responses Re: get_controlfile() can leak fds in the backend
Re: get_controlfile() can leak fds in the backend
List pgsql-hackers
Hi all,
(CC-ing Joe as of dc7d70e)

I was just looking at the offline checksum patch, and noticed some
sloppy coding in controldata_utils.c.  The control file gets opened in
get_controlfile(), and if it generates an error then the file
descriptor remains open.  As basic code rule in the backend we should
only use BasicOpenFile() when opening files, so I think that the issue
should be fixed as attached, even if this requires including fd.h for
the backend compilation which is kind of ugly.

Another possibility would be to just close the file descriptor before
any error, saving appropriately errno before issuing any %m portion,
but that still does not respect the backend policy regarding open().

We also do not have a wait event for the read() call, maybe we should
have one, but knowing that this gets called only for the SQL-level
functions accessing the control file, I don't really think that's
worth it.

Thoughts?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Remove Deprecated Exclusive Backup Mode
Next
From: Peter Eisentraut
Date:
Subject: Re: psql show URL with help