Re: jsonapi: scary new warnings with LTO enabled

Daniel Gustafsson <daniel@yesql.se>

From: Daniel Gustafsson <daniel@yesql.se>
To: Jacob Champion <jacob.champion@enterprisedb.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2025-04-19T21:15:24Z
Lists: pgsql-hackers

Attachments

> On 17 Apr 2025, at 17:48, Jacob Champion <jacob.champion@enterprisedb.com> wrote:
> 
> On Thu, Apr 17, 2025 at 8:20 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I confirm this silences those warnings on my Fedora 41 box.
> 
> Instead of doing
> 
>    lex = calloc(...);
>    /* (error out on NULL return) */
>    makeJsonLexContextCstringLen(lex, ...);
> 
> we need to do
> 
>    lex = makeJsonLexContextCstringLen(NULL, ...);
>    /* (error out on NULL return) */
> 
> so that JSONLEX_FREE_STRUCT is set correctly. Otherwise we'll leak the
> main allocation:

Since there is no way to determine if the allocation succeeded from outside of
the JSON api it might be better to keep the calloc and explicitly free it?

(Could a JsonLexContextBroken() function be useful perhaps?)

--
Daniel Gustafsson

Commits

  1. Allocate JsonLexContexts on the heap to avoid warnings