]> granicus.if.org Git - postgresql/commitdiff
Fix two small bugs in json's populate_record_worker
authorAndrew Dunstan <andrew@dunslane.net>
Mon, 4 May 2015 16:38:58 +0000 (12:38 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Mon, 4 May 2015 16:43:16 +0000 (12:43 -0400)
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.

src/backend/utils/adt/jsonfuncs.c

index 076b00f213cb919a1796d67b6f86a1dcbeeb2c15..1a9a060d4eb1482c792d78dc074b4d1eb3a63656 100644 (file)
@@ -2099,6 +2099,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);
                }
        }
@@ -2107,8 +2108,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;