diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2022-04-13 10:26:38 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2022-04-13 10:37:43 -0400 |
commit | 112fdb3528465cc14a2f1dff3dc27f100326d885 (patch) | |
tree | 37b0a7f1e7dfa558737a2e6eb2bbb0c846c05ca7 /src/backend/utils/adt/json.c | |
parent | a038679cd876f63e17a08f64fafad27cd5bc23fe (diff) | |
download | postgresql-112fdb3528465cc14a2f1dff3dc27f100326d885.tar.gz postgresql-112fdb3528465cc14a2f1dff3dc27f100326d885.zip |
Fix finalization for json_objectagg and friends
Commit f4fb45d15c misguidedly tried to free some state during aggregate
finalization for json_objectagg. This resulted in attempts to access
freed memory, especially when the function is used as a window function.
Commit 4eb9798879 attempted to ameliorate that, but in fact it should
just be ripped out, which is done here. Also add some regression tests
for json_objectagg in various flavors as a window function.
Original report from Jaime Casanova, diagnosis by Andres Freund.
Discussion: https://postgr.es/m/YkfeMNYRCGhySKyg@ahch-to
Diffstat (limited to 'src/backend/utils/adt/json.c')
-rw-r--r-- | src/backend/utils/adt/json.c | 12 |
1 files changed, 0 insertions, 12 deletions
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index 4cf01300d8b..da3f1b97004 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -1002,13 +1002,6 @@ json_unique_builder_init(JsonUniqueBuilderState *cxt) cxt->skipped_keys.data = NULL; } -static void -json_unique_builder_clean(JsonUniqueBuilderState *cxt) -{ - if (cxt->skipped_keys.data) - resetStringInfo(&cxt->skipped_keys); -} - /* On-demand initialization of skipped_keys StringInfo structure */ static StringInfo json_unique_builder_get_skipped_keys(JsonUniqueBuilderState *cxt) @@ -1216,8 +1209,6 @@ json_object_agg_finalfn(PG_FUNCTION_ARGS) if (state == NULL) PG_RETURN_NULL(); - json_unique_builder_clean(&state->unique_check); - /* Else return state with appropriate object terminator added */ PG_RETURN_TEXT_P(catenate_stringinfo_string(state->str, " }")); } @@ -1324,9 +1315,6 @@ json_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, appendStringInfoChar(result, '}'); - if (unique_keys) - json_unique_builder_clean(&unique_check); - return PointerGetDatum(cstring_to_text_with_len(result->data, result->len)); } |