pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve JsonLexContext's freeability
Date: Thu, 05 Oct 2023 09:04:03 +0000
Message-ID: <E1qoKH4-0008H5-IJ@gemulon.postgresql.org> (raw)

Improve JsonLexContext's freeability

Previously, the JSON code didn't have to worry too much about freeing
JsonLexContext, because it was never too long-lived.  With new features
being added for SQL/JSON this is no longer the case.  Add a routine
that knows how to free this struct and apply that to a few places, to
prevent this from becoming problematic.

At the same time, we change the API of makeJsonLexContextCstringLen to
make it receive a pointer to JsonLexContext for callers that want it to
be stack-allocated; it can also be passed as NULL to get the original
behavior of a palloc'ed one.

This also causes an ABI break due to the addition of flags to
JsonLexContext, so we can't easily backpatch it.  AFAICS that's not much
of a problem; apparently some leaks might exist in JSON usage of
text-search, for example via json_to_tsvector, but I haven't seen any
complaints about that.

Per Coverity complaint about datum_to_jsonb_internal().

Discussion: https://postgr.es/m/20230808174110.oq3iymllsv6amkih@alvherre.pgsql

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1c99cde2f3440c59f582d45b251412c9a9b54f62

Modified Files
--------------
src/backend/utils/adt/json.c             |  39 ++++++-----
src/backend/utils/adt/jsonb.c            |  13 ++--
src/backend/utils/adt/jsonfuncs.c        | 107 ++++++++++++++++---------------
src/bin/pg_verifybackup/parse_manifest.c |   4 +-
src/common/jsonapi.c                     |  46 +++++++++++--
src/include/common/jsonapi.h             |  26 ++++++--
src/include/utils/jsonfuncs.h            |   4 +-
7 files changed, 153 insertions(+), 86 deletions(-)



Message-ID: <E1qoKH4-0008H5-IJ@gemulon.postgresql.org>
Permalink:  ../E1qoKH4-0008H5-IJ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1qoKH4-0008H5-IJ@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: alvherre@alvh.no-ip.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Improve JsonLexContext's freeability
  In-Reply-To: <E1qoKH4-0008H5-IJ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox