Re: json_populate_record issue - TupleDesc reference leak

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: json_populate_record issue - TupleDesc reference leak
Date: 2015-02-26 21:19:44
Message-ID: 54EF8DF0.7090705@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2015-02-26 21:29:18 Re: Precedence of standard comparison operators
Previous Message Tom Lane 2015-02-26 20:51:07 Re: Precedence of standard comparison operators