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 1rT5Sb-000LVZ-84 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 19:32:25 +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 1rT5Rc-002nYc-44 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 19:31:24 +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 1rT5Rb-002nYU-Qy for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 19:31:23 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rT5RV-003hRg-3g for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 19:31:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 40PJV9VJ439812; Thu, 25 Jan 2024 14:31:09 -0500 From: Tom Lane To: Andrew Dunstan cc: Jeevan Chalke , Peter Eisentraut , PostgreSQL Hackers Subject: Re: More new SQL/JSON item methods In-reply-to: <5d37428e-0753-e721-8e77-81cc4d0dc9f1@dunslane.net> References: <1d092c02-8249-4e56-8b8e-ae4db95b8fde@eisentraut.org> <5d37428e-0753-e721-8e77-81cc4d0dc9f1@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Thu, 25 Jan 2024 10:40:26 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <439810.1706211069.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 25 Jan 2024 14:31:09 -0500 Message-ID: <439811.1706211069@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrew Dunstan writes: > Thanks, I have pushed this. The buildfarm is pretty widely unhappy, mostly failing on select jsonb_path_query('1.23', '$.string()'); On a guess, I tried running that under valgrind, and behold it said =3D=3D00:00:00:05.637 435530=3D=3D Conditional jump or move depends on uni= nitialised value(s) =3D=3D00:00:00:05.637 435530=3D=3D at 0x8FD131: executeItemOptUnwrapTar= get (jsonpath_exec.c:1547) =3D=3D00:00:00:05.637 435530=3D=3D by 0x8FED03: executeItem (jsonpath_e= xec.c:626) =3D=3D00:00:00:05.637 435530=3D=3D by 0x8FED03: executeNextItem (jsonpa= th_exec.c:1604) =3D=3D00:00:00:05.637 435530=3D=3D by 0x8FCA58: executeItemOptUnwrapTar= get (jsonpath_exec.c:956) =3D=3D00:00:00:05.637 435530=3D=3D by 0x8FFDE4: executeItem (jsonpath_e= xec.c:626) =3D=3D00:00:00:05.637 435530=3D=3D by 0x8FFDE4: executeJsonPath.constpr= op.30 (jsonpath_exec.c:612) =3D=3D00:00:00:05.637 435530=3D=3D by 0x8FFF8C: jsonb_path_query_intern= al (jsonpath_exec.c:438) It's fairly obviously right about that: JsonbValue jbv; ... jb =3D &jbv; Assert(tmp !=3D NULL); /* We must have set tmp above */ jb->val.string.val =3D (jb->type =3D=3D jbvString) ? tmp := pstrdup(tmp); ^^^^^^^^^^^^^^^^^^^^^ Presumably, this is a mistaken attempt to test the type of the thing previously pointed to by "jb". On the whole, what I'd be inclined to do here is get rid of this test altogether and demand that every path through the preceding "switch" deliver a value that doesn't need pstrdup(). The only path that doesn't do that already is case jbvBool: tmp =3D (jb->val.boolean) ? "true" : "false"; break; and TBH I'm not sure that we really need a pstrdup there either. The constants are immutable enough. Is something likely to try to pfree the pointer later? I tried @@ -1544,7 +1544,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt,= JsonPathItem *jsp, = jb =3D &jbv; Assert(tmp !=3D NULL); /* We must have set tmp above */ - jb->val.string.val =3D (jb->type =3D=3D jbvString) ? tmp := pstrdup(tmp); + jb->val.string.val =3D tmp; jb->val.string.len =3D strlen(jb->val.string.val); jb->type =3D jbvString; = and that quieted valgrind for this particular query and still passes regression. (The reported crashes seem to be happening later during a recursive invocation, seemingly because JsonbType(jb) is returning garbage. So there may be another bug after this one.) regards, tom lane