The point would be to have pqConnectOptions2() take its oom_error path in the case you are pointing at. It seems to me that the correct answer would be to extend passwordFromFile() with an extra "const char **errmsg", where an error is saved, assign an error string in the routine, check if the error pointer is set when exiting passwordFromFile() in pqConnectOptions2(), and consume the error properly before failing in pqConnectOptions2() with a CONNECTION_BAD.
Thank you for the detailed feedback! This is my first C project contribution, so I really appreciate you taking the time to explain the proper error handling pattern.
I've updated the patch to address your concerns:
Changes in v2: - Extended passwordFromFile() with const char **errmsg parameter to signal actual errors - Set *errmsg = "out of memory" for OOM cases (enlargePQExpBuffer and strdup failures) - Updated pqConnectOptions2() to check errmsg and fail with CONNECTION_BAD when set - Removed the PGconn *conn parameter since error reporting is now handled by the caller - Updated function comment to document the error signaling convention