Fix finalization for json_objectagg and friends
authorAndrew Dunstan <[email protected]>
Wed, 13 Apr 2022 14:26:38 +0000 (10:26 -0400)
committerAndrew Dunstan <[email protected]>
Wed, 13 Apr 2022 14:37:43 +0000 (10:37 -0400)
commit112fdb3528465cc14a2f1dff3dc27f100326d885
tree37b0a7f1e7dfa558737a2e6eb2bbb0c846c05ca7
parenta038679cd876f63e17a08f64fafad27cd5bc23fe
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
src/backend/utils/adt/json.c
src/test/regress/expected/sqljson.out
src/test/regress/sql/sqljson.sql