aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-12-28 11:41:25 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-12-28 11:41:25 -0500
commitfd1347f9d8def3a892a7335ec026bff0227db1af (patch)
treeb2fe24fe3c0cd57d80cb72fd874c2404cbbdff20 /src
parent190f0af0d1277429467ef28332818952c1fd395f (diff)
downloadpostgresql-fd1347f9d8def3a892a7335ec026bff0227db1af.tar.gz
postgresql-fd1347f9d8def3a892a7335ec026bff0227db1af.zip
Fix thinko in plpgsql memory leak fix.
Commit a6b1f5365 intended to place the transient "target" list of a CALL statement in the function's statement-lifespan context, but I fat-fingered that and used get_eval_mcontext() instead of get_stmt_mcontext(). The eval_mcontext belongs to the "simple expression" infrastructure, which is destroyed at transaction end. The net effect is that a CALL in a procedure to another procedure that has OUT or INOUT parameters would fail if the called procedure did a COMMIT. Per report from Peter Eisentraut. Back-patch to v11, like the prior patch. Discussion: https://postgr.es/m/f075f7be-c654-9aa8-3ffc-e9214622f02a@enterprisedb.com
Diffstat (limited to 'src')
-rw-r--r--src/pl/plpgsql/src/expected/plpgsql_call.out21
-rw-r--r--src/pl/plpgsql/src/pl_exec.c4
-rw-r--r--src/pl/plpgsql/src/sql/plpgsql_call.sql24
3 files changed, 47 insertions, 2 deletions
diff --git a/src/pl/plpgsql/src/expected/plpgsql_call.out b/src/pl/plpgsql/src/expected/plpgsql_call.out
index d9c88e85c8d..fbe8a046067 100644
--- a/src/pl/plpgsql/src/expected/plpgsql_call.out
+++ b/src/pl/plpgsql/src/expected/plpgsql_call.out
@@ -152,6 +152,27 @@ CALL test_proc7(100, -1, -1);
0 | 1
(1 row)
+-- inner COMMIT with output arguments
+CREATE PROCEDURE test_proc7c(x int, INOUT a int, INOUT b numeric)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ a := x / 10;
+ b := x / 2;
+ COMMIT;
+END;
+$$;
+CREATE PROCEDURE test_proc7cc(_x int)
+LANGUAGE plpgsql
+AS $$
+DECLARE _a int; _b numeric;
+BEGIN
+ CALL test_proc7c(_x, _a, _b);
+ RAISE NOTICE '_x: %,_a: %, _b: %', _x, _a, _b;
+END
+$$;
+CALL test_proc7cc(10);
+NOTICE: _x: 10,_a: 1, _b: 5
-- named parameters and defaults
CREATE PROCEDURE test_proc8a(INOUT a int, INOUT b int)
LANGUAGE plpgsql
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 0046efa141a..e0c49c1e266 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -2212,8 +2212,8 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
int i;
ListCell *lc;
- /* Use eval_mcontext for any cruft accumulated here */
- oldcontext = MemoryContextSwitchTo(get_eval_mcontext(estate));
+ /* Use stmt_mcontext for any cruft accumulated here */
+ oldcontext = MemoryContextSwitchTo(get_stmt_mcontext(estate));
/*
* Get the parsed CallStmt, and look up the called procedure
diff --git a/src/pl/plpgsql/src/sql/plpgsql_call.sql b/src/pl/plpgsql/src/sql/plpgsql_call.sql
index 4702bd14d12..21b4a37e59b 100644
--- a/src/pl/plpgsql/src/sql/plpgsql_call.sql
+++ b/src/pl/plpgsql/src/sql/plpgsql_call.sql
@@ -141,6 +141,30 @@ $$;
CALL test_proc7(100, -1, -1);
+-- inner COMMIT with output arguments
+
+CREATE PROCEDURE test_proc7c(x int, INOUT a int, INOUT b numeric)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ a := x / 10;
+ b := x / 2;
+ COMMIT;
+END;
+$$;
+
+CREATE PROCEDURE test_proc7cc(_x int)
+LANGUAGE plpgsql
+AS $$
+DECLARE _a int; _b numeric;
+BEGIN
+ CALL test_proc7c(_x, _a, _b);
+ RAISE NOTICE '_x: %,_a: %, _b: %', _x, _a, _b;
+END
+$$;
+
+CALL test_proc7cc(10);
+
-- named parameters and defaults