mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
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
This commit is contained in:
@ -21,6 +21,8 @@ LINE 1: SELECT ptest1('x');
|
||||
^
|
||||
HINT: To call a procedure, use CALL.
|
||||
CALL ptest1('a'); -- ok
|
||||
CALL ptest1('xy' || 'zzy'); -- ok, constant-folded arg
|
||||
CALL ptest1(substring(random()::text, 1, 1)); -- ok, volatile arg
|
||||
\df ptest1
|
||||
List of functions
|
||||
Schema | Name | Result data type | Argument data types | Type
|
||||
@ -28,11 +30,13 @@ CALL ptest1('a'); -- ok
|
||||
public | ptest1 | | x text | proc
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM cp_test ORDER BY a;
|
||||
a | b
|
||||
---+---
|
||||
SELECT * FROM cp_test ORDER BY b COLLATE "C";
|
||||
a | b
|
||||
---+-------
|
||||
1 | 0
|
||||
1 | a
|
||||
(1 row)
|
||||
1 | xyzzy
|
||||
(3 rows)
|
||||
|
||||
CREATE PROCEDURE ptest2()
|
||||
LANGUAGE SQL
|
||||
|
@ -13,10 +13,12 @@ $$;
|
||||
|
||||
SELECT ptest1('x'); -- error
|
||||
CALL ptest1('a'); -- ok
|
||||
CALL ptest1('xy' || 'zzy'); -- ok, constant-folded arg
|
||||
CALL ptest1(substring(random()::text, 1, 1)); -- ok, volatile arg
|
||||
|
||||
\df ptest1
|
||||
|
||||
SELECT * FROM cp_test ORDER BY a;
|
||||
SELECT * FROM cp_test ORDER BY b COLLATE "C";
|
||||
|
||||
|
||||
CREATE PROCEDURE ptest2()
|
||||
|
Reference in New Issue
Block a user