Re: closing file in adjust_data_dir

From: Japin Li <japinli(at)hotmail(dot)com>
To: Ted Yu <yuzhihong(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: closing file in adjust_data_dir
Date: 2022-11-16 02:35:37
Message-ID: MEYP282MB16691A83E67D045D48FFC52BB6079@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Wed, 16 Nov 2022 at 10:06, Ted Yu <yuzhihong(at)gmail(dot)com> wrote:
>> Hi,
> That check is a few line above:
>
> + if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL)
> {
>
> Cheers

Thanks for the explanation. Comment on v2 patch.

fd = popen(cmd, "r");
- if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL || pclose(fd) != 0)
+ if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL)
{
+ pclose(fd);
write_stderr(_("%s: could not determine the data directory using command \"%s\"\n"), progname, cmd);
exit(1);
}

Here, segfault maybe occurs if fd is NULL. I think we can remove pclose()
safely since the process will exit.

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2022-11-16 02:40:47 Re: Slow standby snapshot
Previous Message Amit Langote 2022-11-16 02:35:08 Re: List of Bitmapset (was Re: ExecRTCheckPerms() and many prunable partitions)