Re: json_populate_record issue - TupleDesc reference leak - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: json_populate_record issue - TupleDesc reference leak
Date
Msg-id 54EF8DF0.7090705@dunslane.net
Whole thread Raw
In response to Re: json_populate_record issue - TupleDesc reference leak  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: json_populate_record issue - TupleDesc reference leak  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 02/23/2015 12:56 PM, Pavel Stehule wrote:
> by the way - this feature is undocumented - I though so only value 
> used as type holder is not used.
>
> Should be documented better, - if I understand - it is base stone for 
> implementation #= hstore operator
>
> some nice example
>
> postgres=# select json_populate_record('(10,20)'::pt, '{"a":30}');
>  json_populate_record
> ----------------------
>  (30,20)
> (1 row)
>
> a mentioned bug is corner case - bugfix is simple
>
> diff --git a/src/backend/utils/adt/jsonfuncs.c 
> b/src/backend/utils/adt/jsonfuncs.c
> new file mode 100644
> index a8cdeaa..6e83f78
> *** a/src/backend/utils/adt/jsonfuncs.c
> --- b/src/backend/utils/adt/jsonfuncs.c
> *************** populate_record_worker(FunctionCallInfo
> *** 2114,2119 ****
> --- 2114,2122 ----
>                  */
>                 if (hash_get_num_entries(json_hash) == 0 && rec)
>                 {
> +                       if (have_record_arg)
> +                               ReleaseTupleDesc(tupdesc);
> +
>                         hash_destroy(json_hash);
>                         PG_RETURN_POINTER(rec);
>                 }
>
>
>
>


This doesn't look quite right. Shouldn't we unconditionally release the 
Tupledesc before the returns at lines 2118 and 2127, just as we do at 
the bottom of the function at line 2285?

cheers

andrew



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Precedence of standard comparison operators
Next
From: Peter Eisentraut
Date:
Subject: Re: Precedence of standard comparison operators