> On 17 Apr 2025, at 17:48, Jacob Champion <jacob.champ...@enterprisedb.com> 
> wrote:
> 
> On Thu, Apr 17, 2025 at 8:20 AM Tom Lane <t...@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

Attachment: v2-0001-Allocate-JsonLexContexts-on-the-heap-to-avoid-war.patch
Description: Binary data

Reply via email to