From: | Ted Yu <yuzhihong(at)gmail(dot)com> |
---|---|
To: | Japin Li <japinli(at)hotmail(dot)com> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: closing file in adjust_data_dir |
Date: | 2022-11-16 03:15:57 |
Message-ID: | CALte62wtdry5u=_Pf5AyVf4zg1hDx_6nPEmjJSg9N3oZRpD4Ug@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Nov 15, 2022 at 7:12 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
>
> On Wed, 16 Nov 2022 at 10:52, Ted Yu <yuzhihong(at)gmail(dot)com> wrote:
> > On Tue, Nov 15, 2022 at 6:35 PM Japin Li <japinli(at)hotmail(dot)com> 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.
>
>
>
> Please read this sentence from my first post:
If the fgets() call doesn't return NULL, the pclose() would be skipped.
From | Date | Subject | |
---|---|---|---|
Next Message | Justin Pryzby | 2022-11-16 03:17:28 | Re: libpq compression (part 2) |
Previous Message | Japin Li | 2022-11-16 03:11:52 | Re: closing file in adjust_data_dir |