aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/jsonfuncs.h
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2023-10-05 10:59:08 +0200
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2023-10-05 10:59:08 +0200
commit1c99cde2f3440c59f582d45b251412c9a9b54f62 (patch)
treeb50d690b8c52dbe74ea8e8f14d9051708df20523 /src/include/utils/jsonfuncs.h
parenta8a968a8212ee3ef7f22795c834b33d871fac262 (diff)
downloadpostgresql-1c99cde2f3440c59f582d45b251412c9a9b54f62.tar.gz
postgresql-1c99cde2f3440c59f582d45b251412c9a9b54f62.zip
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
Diffstat (limited to 'src/include/utils/jsonfuncs.h')
-rw-r--r--src/include/utils/jsonfuncs.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/include/utils/jsonfuncs.h b/src/include/utils/jsonfuncs.h
index c677ac8ff78..1c6d2be0252 100644
--- a/src/include/utils/jsonfuncs.h
+++ b/src/include/utils/jsonfuncs.h
@@ -36,8 +36,8 @@ typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, in
/* an action that will be applied to each value in transform_json(b)_values functions */
typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
-/* build a JsonLexContext from a text datum */
-extern JsonLexContext *makeJsonLexContext(text *json, bool need_escapes);
+/* build a JsonLexContext from a text datum; see also freeJsonLexContext */
+extern JsonLexContext *makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes);
/* try to parse json, and errsave(escontext) on failure */
extern bool pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem,