Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u5B4X-00DRsz-Mh for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Apr 2025 22:17:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u5B4V-006qU3-TO for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Apr 2025 22:17:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u5B4V-006qQx-El for pgsql-hackers@lists.postgresql.org; Wed, 16 Apr 2025 22:17:32 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u5B4Q-000SjO-1L for pgsql-hackers@lists.postgresql.org; Wed, 16 Apr 2025 22:17:29 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-22423adf751so1919435ad.2 for ; Wed, 16 Apr 2025 15:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744841845; x=1745446645; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DK5+emDcasGEvMmIZ2XkgUNje/ZVbAlCI1fhyXsZlX0=; b=gPBjarm64WBoK8828QH/fxgcdoXox8zDjcAC+x47CJ0ka4+XQyAXiXQYu0xCGpbG/9 hZB9HjyxJ2BYVopkpAGMCN00cNB0fAUVch0ndlDeTmDkFVLBPUdC6AktzRlv+7DYdf59 ZHOxeJ6ce5LgXztZ2NhGYs/vjg8PrZzbD6dkDfTJku9iIP3Hv7D5Er1Da3jkwmO70eKa TPxJbQ4ibXQa3aSFUBgTKB1Tvvp476WL4LmNpqWrOUA0EQKWU1JUWFkUOcMGBHhRg7Gm XQugc4FMqB9Tum99h9VE24+wvnwKyo1uedw4DwnIvKv5Ezpzw0qa5jICGUP0OGxuCJxz OyJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744841845; x=1745446645; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DK5+emDcasGEvMmIZ2XkgUNje/ZVbAlCI1fhyXsZlX0=; b=gNWNTHIvhZCrs9gN0b5xoFyZgPycqE3mOrh7Bsf0bc/XtCgHHYmVIaXGvfs+iVvyxs KphYVOU0EM7IvmkaPOBLwHDPb7kCXTYvr1MEWtej/hYaPiQWTLZIdD4uP9UgYu68PZFB IZCGR0SRpkknsh61ZGas85bwIgtOMv/OO5Xxc0nLRX4hJ2ZNH/NHaijDXkdePWA0F9qf r0w3LGVih6fm7YCDacz0W5y+KyqdzYuVM6gBahMtA4syiGo00a2gZcjCDNLzvgUWrAGS 6W4KbFuj9x/CyEago03S/zsMZd0Arw1mqZKFZ9EWOdQHlnXR0KaOvgcKjA8HJr4xOxzr dsww== X-Gm-Message-State: AOJu0YySuj1L60w3EPTlZSXjuLJN1+JynPAYphIt+MgQvCSk2AUqGlOl yojqGD/qv2hVfT8Rusq4HdzrcFPfT0jkK/CBLBfa3Zwr0z8Cv8gMPNvv+teJhDSljBtn7S8tpRd Skk0Z0HaWvjBX9kWueglT/fZvFpU= X-Gm-Gg: ASbGnctZo6IO9zuWXdNLAVRNV6C63ij8foFeHSvekro6KI1iURT+Ke5xBmO7utBlWa6 mJ+mGDAPxpOosG3ER9MuKRmspQS/7HKMmr9LJW4XL3kehesg/tNcM8CAGe1A6XU+cmMYQF8I3px dd/8L+8d3xVvB5Q8SZkmS9toO9V/VsUAZtI27cmyqVG+eaeV2RtmAyefU= X-Google-Smtp-Source: AGHT+IGmj+ohnDWDRED6NhbxAa0loDaWjYH3ePNxD0EPcpM9gcK8ewx0jkzKV27qMkWrcIOd/TDyCsffotp1d2vjuPU= X-Received: by 2002:a17:903:8c5:b0:224:2201:84da with SMTP id d9443c01a7336-22c358bfac3mr45756985ad.6.1744841845324; Wed, 16 Apr 2025 15:17:25 -0700 (PDT) MIME-Version: 1.0 References: <2074634.1744839761@sss.pgh.pa.us> In-Reply-To: <2074634.1744839761@sss.pgh.pa.us> From: Ranier Vilela Date: Wed, 16 Apr 2025 19:17:34 -0300 X-Gm-Features: ATxdqUF0l4j4P1D5OygAOchRZtvt4Txa6jAsHBmdBUSXhEmuIWO4fLV6_DBdync Message-ID: Subject: Re: jsonapi: scary new warnings with LTO enabled To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000006141050632eca6e8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006141050632eca6e8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em qua., 16 de abr. de 2025 =C3=A0s 18:42, Tom Lane esc= reveu: > I noticed some new warnings from buildfarm member chafer, > which I'm able to reproduce locally on a Fedora 41 box > by building with "meson setup build -Db_lto=3Dtrue": > > ninja: Entering directory `build' > [1515/2472] Linking target src/interfaces/libpq/libpq.so.5.18 > In function 'freeJsonLexContext', > inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:688:1, > inlined from 'handle_oauth_sasl_error' at > ../src/interfaces/libpq/fe-auth-oauth.c:547:2: > ../src/common/jsonapi.c:723:17: warning: 'free' called on unallocated > object 'lex' [-Wfree-nonheap-object] > 723 | FREE(lex); > | ^ > ../src/interfaces/libpq/fe-auth-oauth.c: In function > 'handle_oauth_sasl_error': > ../src/interfaces/libpq/fe-auth-oauth.c:479:24: note: declared here > 479 | JsonLexContext lex =3D {0}; > | ^ > [2407/2472] Linking target > src/test/modules/test_json_parser/test_json_parser_incremental_shlib > In function 'freeJsonLexContext', > inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:688:1, > inlined from 'main' at > ../src/test/modules/test_json_parser/test_json_parser_incremental.c:198:2= : > ../src/common/jsonapi.c:723:17: warning: 'free' called on unallocated > object 'lex' [-Wfree-nonheap-object] > 723 | FREE(lex); > | ^ > ../src/test/modules/test_json_parser/test_json_parser_incremental.c: In > function 'main': > ../src/test/modules/test_json_parser/test_json_parser_incremental.c:87:24= : > note: declared here > 87 | JsonLexContext lex; > | ^ > [2426/2472] Linking target > src/test/modules/test_json_parser/test_json_parser_incremental > In function 'pg_free', > inlined from 'pfree' at ../src/common/fe_memutils.c:135:2, > inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:723:3, > inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:688:1, > inlined from 'main' at > ../src/test/modules/test_json_parser/test_json_parser_incremental.c:198:2= : > ../src/common/fe_memutils.c:107:9: warning: 'free' called on unallocated > object 'lex' [-Wfree-nonheap-object] > 107 | free(ptr); > | ^ > ../src/test/modules/test_json_parser/test_json_parser_incremental.c: In > function 'main': > ../src/test/modules/test_json_parser/test_json_parser_incremental.c:87:24= : > note: declared here > 87 | JsonLexContext lex; > | ^ > > AFAICT there is no actual bug here: the FREE() call is reached only if > the JSONLEX_FREE_STRUCT flag is set, which it should not be for these > call sites. See the function *makeJsonLexContextCstringLen* (line 400) The JSONLEX_FREE_STRUCT is enabled, no? fe-auth-oauth.c (line 507) makeJsonLexContextCstringLen(&lex, msg, msglen, PG_UTF8, true); Worst, on a second call, with lex not NULL, the flags is reseted and the struct will no longer be released? best regards, Ranier Vilela --0000000000006141050632eca6e8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Em qua., 16 de = abr. de 2025 =C3=A0s 18:42, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
I noticed some new warnings from buildfarm member ch= afer,
which I'm able to reproduce locally on a Fedora 41 box
by building with "meson setup build -Db_lto=3Dtrue":

ninja: Entering directory `build'
[1515/2472] Linking target src/interfaces/libpq/libpq.so.5.18
In function 'freeJsonLexContext',
=C2=A0 =C2=A0 inlined from 'freeJsonLexContext' at ../src/common/js= onapi.c:688:1,
=C2=A0 =C2=A0 inlined from 'handle_oauth_sasl_error' at ../src/inte= rfaces/libpq/fe-auth-oauth.c:547:2:
../src/common/jsonapi.c:723:17: warning: 'free' called on unallocat= ed object 'lex' [-Wfree-nonheap-object]
=C2=A0 723 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0F= REE(lex);
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0^
../src/interfaces/libpq/fe-auth-oauth.c: In function 'handle_oauth_sasl= _error':
../src/interfaces/libpq/fe-auth-oauth.c:479:24: note: declared here
=C2=A0 479 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0JsonLexContext lex =3D {0}; =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^
[2407/2472] Linking target src/test/modules/test_json_parser/test_json_pars= er_incremental_shlib
In function 'freeJsonLexContext',
=C2=A0 =C2=A0 inlined from 'freeJsonLexContext' at ../src/common/js= onapi.c:688:1,
=C2=A0 =C2=A0 inlined from 'main' at ../src/test/modules/test_json_= parser/test_json_parser_incremental.c:198:2:
../src/common/jsonapi.c:723:17: warning: 'free' called on unallocat= ed object 'lex' [-Wfree-nonheap-object]
=C2=A0 723 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0F= REE(lex);
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0^
../src/test/modules/test_json_parser/test_json_parser_incremental.c: In fun= ction 'main':
../src/test/modules/test_json_parser/test_json_parser_incremental.c:87:24: = note: declared here
=C2=A0 =C2=A087 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0JsonLexContext lex;
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^
[2426/2472] Linking target src/test/modules/test_json_parser/test_json_pars= er_incremental
In function 'pg_free',
=C2=A0 =C2=A0 inlined from 'pfree' at ../src/common/fe_memutils.c:1= 35:2,
=C2=A0 =C2=A0 inlined from 'freeJsonLexContext' at ../src/common/js= onapi.c:723:3,
=C2=A0 =C2=A0 inlined from 'freeJsonLexContext' at ../src/common/js= onapi.c:688:1,
=C2=A0 =C2=A0 inlined from 'main' at ../src/test/modules/test_json_= parser/test_json_parser_incremental.c:198:2:
../src/common/fe_memutils.c:107:9: warning: 'free' called on unallo= cated object 'lex' [-Wfree-nonheap-object]
=C2=A0 107 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0free(ptr);
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^
../src/test/modules/test_json_parser/test_json_parser_incremental.c: In fun= ction 'main':
../src/test/modules/test_json_parser/test_json_parser_incremental.c:87:24: = note: declared here
=C2=A0 =C2=A087 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0JsonLexContext lex;
=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^

AFAICT there is no actual bug here: the FREE() call is reached only if
the JSONLEX_FREE_STRUCT flag is set, which it should not be for these
call sites.=C2=A0=C2=A0
See the function *makeJsonLexConte= xtCstringLen* (line 400)
The=20 JSONLEX_FREE_STRUCT=C2=A0 is enabled, no?

fe-auth-= oauth.c (line 507)
makeJsonLexContextCstringLen(&lex, msg, m= sglen, PG_UTF8, true);

Worst, on a second call, with lex = not NULL, the flags is reseted
and the struct will no longer be r= eleased?

best regards,
Ranier Vilela
--0000000000006141050632eca6e8--