I'm glad you are bringing up this issue. By the way, there are two more annoying places in postmaster.c for pg16 and older. See, strdup() also may fail if insufficient memory available.
PFA patch for a REL_16_STABLE. It also applies to older versions. -- Best regards, Maxim Orlov.
v2-0001-Use-pstrdup-for-remote_host-and-remote_port-save-.patch
Description: Binary data