Re: closing file in adjust_data_dir
От
Japin Li
Тема
Re: closing file in adjust_data_dir
Дата
Msg-id
MEYP282MB1669689E3C19E1EB73AB440FB6079@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Ответ на
Re: closing file in adjust_data_dir (Ted Yu)
Список
Дерево обсуждения
closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Japin Li <japinli@hotmail.com>
Re: closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Japin Li <japinli@hotmail.com>
Re: closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Japin Li <japinli@hotmail.com>
Re: closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Japin Li <japinli@hotmail.com>
Re: closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Re: closing file in adjust_data_dir Ted Yu <yuzhihong@gmail.com>
Re: closing file in adjust_data_dir Japin Li <japinli@hotmail.com>
On Wed, 16 Nov 2022 at 10:52, Ted Yu wrote:
> On Tue, Nov 15, 2022 at 6:35 PM Japin Li wrote:
>>
>> 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.
>>
>
> That means we're going back to v1 of the patch.
>
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.
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
В списке pgsql-hackers по дате отправления