Re: [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ... - Mailing list pgsql-hackers

From VASUKI M
Subject Re: [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ...
Date
Msg-id CAE2r8H7h0gknvZHBcYJSzqC=DL3yZXfjfH3BvfnNbBxwh6dexg@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] psql: tab completion for ALTER ROLE ... IN DATABASE ...  ("zengman" <zengman@halodbtech.com>)
List pgsql-hackers

Hi zeng,

Thanks for pointing this out. You’re absolutely right — PQescapeLiteral() allocates memory using libpq’s allocator, so the returned buffers must be released with PQfreemem() rather than pfree(). Using pfree() here would be incorrect, since it expects memory allocated via PostgreSQL’s memory context APIs (palloc/psprintf).

I’ll update the patch to replace pfree() with PQfreemem() for the buffers returned by PQescapeLiteral(),while continuing to use pfree() for memory allocated via psprintf().

Thanks again for catching this.

Best regards,
Vasuki M
C-DAC,Chennai


On Mon, 22 Dec 2025, 8:18 pm zengman, <zengman@halodbtech.com> wrote:
Hi

I noticed that in the code, the variables `q_role` and `q_dbname` are processed with the `PQescapeLiteral` function,
so `PQfreemem` – instead of `pfree` – should be used here to free the memory.

--
Regards,
Man Zeng
www.openhalo.org

pgsql-hackers by date:

Previous
From: Yugo Nagata
Date:
Subject: Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM
Next
From: Dilip Kumar
Date:
Subject: Re: Proposal: Conflict log history table for Logical Replication