Re: closing file in adjust_data_dir

From: Ted Yu <yuzhihong(at)gmail(dot)com>
To: Japin Li <japinli(at)hotmail(dot)com>, peter(at)eisentraut(dot)org
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: closing file in adjust_data_dir
Date: 2022-11-16 03:31:55
Message-ID: CALte62wyMNVH3_92uGGJ5RarWdF+EYsVALggJ+xbZiRa4dUNBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 15, 2022 at 7:26 PM Japin Li <japinli(at)hotmail(dot)com> wrote:

>
> On Wed, 16 Nov 2022 at 11:15, Ted Yu <yuzhihong(at)gmail(dot)com> wrote:
> > On Tue, Nov 15, 2022 at 7:12 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
> >> After some rethinking, I find the origin code do not have problems.
> >>
> >> If fd is NULL or fgets() returns NULL, the process exits. Otherwise, we
> >> call
> >> pclose() to close fd. The code isn't straightforward, however, it is
> >> correct.
>
> Hi,
Please take a look at the following:

https://en.cppreference.com/w/c/io/fgets

Quote: If the failure has been caused by some other error, sets the
*error* indicator
(see ferror() <https://en.cppreference.com/w/c/io/ferror>) on stream. The
contents of the array pointed to by str are indeterminate (it may not even
be null-terminated).

I think we shouldn't assume that the fd doesn't need to be closed when NULL
is returned from fgets().

Cheers

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message ζˆδΉ‹η„• 2022-11-16 03:37:25 contrib: auth_delay module
Previous Message Japin Li 2022-11-16 03:26:25 Re: closing file in adjust_data_dir