Re: replace IDENTIFY_SYSTEM code in receivelog.c with RunIdentifySystem() - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: replace IDENTIFY_SYSTEM code in receivelog.c with RunIdentifySystem()
Date
Msg-id YS2ELywYwlkjg3OJ@paquier.xyz
Whole thread Raw
In response to Re: replace IDENTIFY_SYSTEM code in receivelog.c with RunIdentifySystem()  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
List pgsql-hackers
On Mon, Aug 30, 2021 at 01:01:16PM +0530, Bharath Rupireddy wrote:
> Shound't we fix it in master branch to keep the code in sync with
> other places where we usually follow that kind of type-casting? IMO,
> we should just make that change, because it isn't a major change or we
> aren't going to back patch it.

One thing is that this creates conflicts with back-branches, and
that's always annoying.  I'd be fine with changing new code for that,
though.

>> Here you want to free sysidentifier only if it has been set, and
>> RunIdentifySystem() may fail before doing that, so you should assign
>> NULL to sysidentifier when it is declared.
>
> Isn't the pg_free going to take care of sysidentifier being null?
>     if (ptr != NULL)
>         free(ptr);

It would, but you don't initialize the variable to begin with, so you
may finish with freeing a pointer that points to nothing, and crash
any code using ReceiveXlogStream() while some code paths should be
able to handle retries.  I guess that compilers would not complain
here because they cannot understand that RunIdentifySystem() may not
set up the variable before this function returns.  I have fixed this
initialization, and committed the patch.  Note that there is only one
other code path using RunIdentifySystem() with the system ID as of
pg_basebackup.c, but this one would just exit() if we fail to run the
command, so we don't need to care about freeing the system ID there.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Joe Conway
Date:
Subject: Re: Pg stuck at 100% cpu, for multiple days
Next
From: Michael Paquier
Date:
Subject: Re: Pg stuck at 100% cpu, for multiple days