Re: [PATCH] Add error message for out-of-memory in passwordFromFile() - Mailing list pgsql-hackers

From Joshua Shanks
Subject Re: [PATCH] Add error message for out-of-memory in passwordFromFile()
Date
Msg-id CAOxqWDcnHgM3AEYhDjDounf56WXRhaQuuzJBYgfMyfQGH=jTXw@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Add error message for out-of-memory in passwordFromFile()  (Michael Paquier <michael@paquier.xyz>)
Responses Re: [PATCH] Add error message for out-of-memory in passwordFromFile()
List pgsql-hackers
On Mon, Nov 3, 2025 at 2:35 AM Michael Paquier <michael@paquier.xyz> wrote:
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

Cheers,
Joshua
Attachment

pgsql-hackers by date:

Previous
From: Philip Alger
Date:
Subject: [PATCH] Add pretty formatting to pg_get_triggerdef
Next
From: Thomas Munro
Date:
Subject: Re: meson's in-tree libpq header search order vs -Dextra_include_dirs