pgsql: Avoid premature free of pass-by-reference CALL arguments.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid premature free of pass-by-reference CALL arguments.
Date: 2018-02-10 18:37:17
Message-ID: E1eka1V-0002Ed-A3@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Avoid premature free of pass-by-reference CALL arguments.

Prematurely freeing the EState used to evaluate CALL arguments led, in some
cases, to passing dangling pointers to the procedure. This was masked in
trivial cases because the argument pointers would point to Const nodes in
the original expression tree, and in some other cases because the result
value would end up in the standalone ExprContext rather than in memory
belonging to the EState --- but that wasn't exactly high quality
programming either, because the standalone ExprContext was never
explicitly freed, breaking assorted API contracts.

In addition, using a separate EState for each argument was just silly.

So let's use just one EState, and one ExprContext, and make the latter
belong to the former rather than be standalone, and clean up the EState
(and hence the ExprContext) post-call.

While at it, improve the function's commentary a bit.

Discussion: https://postgr.es/m/29173.1518282748@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d02d4a6d4f27c223f48b03a5e651a22c8460b3c4

Modified Files
--------------
src/backend/commands/functioncmds.c | 28 ++++++++++++++++++++------
src/test/regress/expected/create_procedure.out | 12 +++++++----
src/test/regress/sql/create_procedure.sql | 4 +++-
3 files changed, 33 insertions(+), 11 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-02-11 18:24:35 pgsql: Fix assorted errors in pg_dump's handling of extended statistics
Previous Message Tom Lane 2018-02-10 18:05:19 pgsql: Fix oversight in CALL argument handling, and do some minor clean

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-02-10 18:46:40 Re: CALL stmt, ERROR: unrecognized node type: 113 bug
Previous Message Tom Lane 2018-02-10 17:12:28 Re: CALL stmt, ERROR: unrecognized node type: 113 bug