Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea80d8d

Browse files
committed
Fix thinko in plpgsql memory leak fix.
Commita6b1f53 intended to place the transient "target" list ofa CALL statement in the function's statement-lifespan context,but I fat-fingered that and used get_eval_mcontext() instead ofget_stmt_mcontext(). The eval_mcontext belongs to the "simpleexpression" infrastructure, which is destroyed at transaction end.The net effect is that a CALL in a procedure to another procedurethat has OUT or INOUT parameters would fail if the called proceduredid a COMMIT.Per report from Peter Eisentraut. Back-patch to v11, like theprior patch.Discussion:https://postgr.es/m/f075f7be-c654-9aa8-3ffc-e9214622f02a@enterprisedb.com
1 parent643428c commitea80d8d

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

‎src/pl/plpgsql/src/expected/plpgsql_call.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ CALL test_proc7(100, -1, -1);
152152
0 | 1
153153
(1 row)
154154

155+
-- inner COMMIT with output arguments
156+
CREATE PROCEDURE test_proc7c(x int, INOUT a int, INOUT b numeric)
157+
LANGUAGE plpgsql
158+
AS $$
159+
BEGIN
160+
a := x / 10;
161+
b := x / 2;
162+
COMMIT;
163+
END;
164+
$$;
165+
CREATE PROCEDURE test_proc7cc(_x int)
166+
LANGUAGE plpgsql
167+
AS $$
168+
DECLARE _a int; _b numeric;
169+
BEGIN
170+
CALL test_proc7c(_x, _a, _b);
171+
RAISE NOTICE '_x: %,_a: %, _b: %', _x, _a, _b;
172+
END
173+
$$;
174+
CALL test_proc7cc(10);
175+
NOTICE: _x: 10,_a: 1, _b: 5
155176
-- named parameters and defaults
156177
CREATE PROCEDURE test_proc8a(INOUT a int, INOUT b int)
157178
LANGUAGE plpgsql

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,8 +2235,8 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
22352235
inti;
22362236
ListCell*lc;
22372237

2238-
/* Useeval_mcontext for any cruft accumulated here */
2239-
oldcontext=MemoryContextSwitchTo(get_eval_mcontext(estate));
2238+
/* Usestmt_mcontext for any cruft accumulated here */
2239+
oldcontext=MemoryContextSwitchTo(get_stmt_mcontext(estate));
22402240

22412241
/*
22422242
* Get the parsed CallStmt, and look up the called procedure

‎src/pl/plpgsql/src/sql/plpgsql_call.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,30 @@ $$;
141141

142142
CALL test_proc7(100,-1,-1);
143143

144+
-- inner COMMIT with output arguments
145+
146+
CREATE PROCEDURE test_proc7c(xint, INOUT aint, INOUT bnumeric)
147+
LANGUAGE plpgsql
148+
AS $$
149+
BEGIN
150+
a := x/10;
151+
b := x/2;
152+
COMMIT;
153+
END;
154+
$$;
155+
156+
CREATE PROCEDURE test_proc7cc(_xint)
157+
LANGUAGE plpgsql
158+
AS $$
159+
DECLARE _aint; _bnumeric;
160+
BEGIN
161+
CALL test_proc7c(_x, _a, _b);
162+
RAISE NOTICE'_x: %,_a: %, _b: %', _x, _a, _b;
163+
END
164+
$$;
165+
166+
CALL test_proc7cc(10);
167+
144168

145169
-- named parameters and defaults
146170

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp