On 2018-Nov-17, Fabien COELHO wrote:
> Here is the updated v2
>
> - libpq internal function getHostaddr get a length,
> and I added an assert about it.
> - added a few braces on if/if/else/if/else/else
> - added an UNKNOWN_HOST macro to hide "???"
> - moved host_addr[] declaration earlier to avoid some braces
You forgot to free(conn->connip) during freePGconn().
I found the UNKNOWN_HOST business quite dubious -- not only in your
patch but also in the existing coding. I changed the getHostname API so
that instead of returning "???" it sets the output buffer to the empty
string. AFAICS the only user-visible behavior is that we no longer
display the "???" in a parenthical comment next to the server address
when a connection fails (this is pre-existing behavior, not changed by
your patch.)
Now, maybe the thinking was that upon seeing this message:
could not connect to server: some error here
Is the server running on host "pg.mines-paristech.fr" (???) and accepting
connections on port 5432?
the user was going to think "oh, my machine must have run out of memory,
I'll reboot and retry". However, I highly doubt that anybody would
reach that conclusion without reading the source code. So I deem this
useless.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services