Re: closing file in adjust_data_dir - Mailing list pgsql-hackers

From Ted Yu
Subject Re: closing file in adjust_data_dir
Date
Msg-id CALte62wyMNVH3_92uGGJ5RarWdF+EYsVALggJ+xbZiRa4dUNBw@mail.gmail.com
Whole thread Raw
In response to Re: closing file in adjust_data_dir  (Japin Li <japinli@hotmail.com>)
Responses Re: closing file in adjust_data_dir
List pgsql-hackers


On Tue, Nov 15, 2022 at 7:26 PM Japin Li <japinli@hotmail.com> wrote:

On Wed, 16 Nov 2022 at 11:15, Ted Yu <yuzhihong@gmail.com> wrote:
> On Tue, Nov 15, 2022 at 7:12 PM Japin Li <japinli@hotmail.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:

 
Quote: If the failure has been caused by some other error, sets the error indicator (see 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

pgsql-hackers by date:

Previous
From: Japin Li
Date:
Subject: Re: closing file in adjust_data_dir
Next
From: 成之焕
Date:
Subject: contrib: auth_delay module