diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2015-05-04 12:38:58 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2015-05-04 12:38:58 -0400 |
commit | 3c000fd9a68dae9ebd9d1507ab3995cc178de1e5 (patch) | |
tree | 6ef7993c115a0d6443d805e7fc29675cc5515e7a /src/backend/utils/adt/jsonfuncs.c | |
parent | c90b85e4d9e4ae3bc26459cc54697e1adaa4315f (diff) | |
download | postgresql-3c000fd9a68dae9ebd9d1507ab3995cc178de1e5.tar.gz postgresql-3c000fd9a68dae9ebd9d1507ab3995cc178de1e5.zip |
Fix two small bugs in json's populate_record_worker
The first bug is not releasing a tupdesc when doing an early return out
of the function. The second bug is a logic error in choosing when to do
an early return if given an empty jsonb object.
Bug reports from Pavel Stehule and Tom Lane respectively.
Backpatch to 9.4 where these were introduced.
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r-- | src/backend/utils/adt/jsonfuncs.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 274f64c95f8..5f61cfcb73a 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -2115,6 +2115,7 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname, if (hash_get_num_entries(json_hash) == 0 && rec) { hash_destroy(json_hash); + ReleaseTupleDesc(tupdesc); PG_RETURN_POINTER(rec); } } @@ -2123,8 +2124,11 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname, jb = PG_GETARG_JSONB(json_arg_num); /* same logic as for json */ - if (!have_record_arg && rec) + if (JB_ROOT_COUNT(jb) == 0 && rec) + { + ReleaseTupleDesc(tupdesc); PG_RETURN_POINTER(rec); + } } ncolumns = tupdesc->natts; |