[PATCH] Add error message for out-of-memory in passwordFromFile()

From: Joshua Shanks <jjshanks(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] Add error message for out-of-memory in passwordFromFile()
Date: 2025-11-01 23:49:02
Message-ID: CAOxqWDfihFRmhNVdfu8epYTXQRxkCHSOrg+=-ij2c_X3gW=o3g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I noticed a XXX comment in fe-connect.c at line 8064 indicating that
an error message would be nice when strdup() fails while reading the
password file. Currently, passwordFromFile() silently returns NULL on
allocation failure, leaving users without feedback on what went wrong.

This patch adds proper error reporting by:

1. Adding a PGconn *conn parameter to passwordFromFile() to enable
error reporting via libpq_append_conn_error()
2. Reporting "out of memory" when strdup() fails, following the
pattern used by other OOM handlers in fe-connect.c

The conn parameter is placed first, consistent with the object-oriented
convention used throughout libpq (see connectOptions1,
fillPGconn, store_conn_addrinfo, etc.).

Cheers,
Joshua

Attachment Content-Type Size
0001-Add-error-message-for-out-of-memory-in-passwordFromF.patch application/octet-stream 2.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-11-02 00:09:55 Re: [PATCH] Add error message for out-of-memory in passwordFromFile()
Previous Message Tom Lane 2025-11-01 22:28:26 Re: Improving the names generated for indexes on expressions