Skip to content

Commit 76f219d

Browse files
committed
string returned by function plpgsql_check_get_const_string should not be released, because the the const string can be used more times
1 parent 1482592 commit 76f219d

File tree

6 files changed

+123
-2
lines changed

6 files changed

+123
-2
lines changed

expected/plpgsql_check_active.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9544,3 +9544,28 @@ select * from plpgsql_check_function('test_proc_composite');
95449544
drop function test_proc_composite;
95459545
drop procedure proc_composite;
95469546
drop type ct;
9547+
create or replace function double_usage_of_const_str()
9548+
returns void
9549+
as $$
9550+
declare
9551+
p_id_arr integer[];
9552+
r_id integer;
9553+
begin
9554+
p_id_arr := '{1,2,3}'::integer[];
9555+
foreach r_id in array p_id_arr
9556+
loop
9557+
raise notice 'id: %', r_id;
9558+
end loop;
9559+
--the following loop causes an error
9560+
foreach r_id in array p_id_arr
9561+
loop
9562+
raise notice 'id: %', r_id;
9563+
end loop;
9564+
end;
9565+
$$ language plpgsql;
9566+
-- should not to raise false alarm #195
9567+
select * from plpgsql_check_function('double_usage_of_const_str');
9568+
plpgsql_check_function
9569+
------------------------
9570+
(0 rows)
9571+

expected/plpgsql_check_active_2.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9543,3 +9543,28 @@ select * from plpgsql_check_function('test_proc_composite');
95439543
drop function test_proc_composite;
95449544
drop procedure proc_composite;
95459545
drop type ct;
9546+
create or replace function double_usage_of_const_str()
9547+
returns void
9548+
as $$
9549+
declare
9550+
p_id_arr integer[];
9551+
r_id integer;
9552+
begin
9553+
p_id_arr := '{1,2,3}'::integer[];
9554+
foreach r_id in array p_id_arr
9555+
loop
9556+
raise notice 'id: %', r_id;
9557+
end loop;
9558+
--the following loop causes an error
9559+
foreach r_id in array p_id_arr
9560+
loop
9561+
raise notice 'id: %', r_id;
9562+
end loop;
9563+
end;
9564+
$$ language plpgsql;
9565+
-- should not to raise false alarm #195
9566+
select * from plpgsql_check_function('double_usage_of_const_str');
9567+
plpgsql_check_function
9568+
------------------------
9569+
(0 rows)
9570+

expected/plpgsql_check_active_3.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9544,3 +9544,28 @@ select * from plpgsql_check_function('test_proc_composite');
95449544
drop function test_proc_composite;
95459545
drop procedure proc_composite;
95469546
drop type ct;
9547+
create or replace function double_usage_of_const_str()
9548+
returns void
9549+
as $$
9550+
declare
9551+
p_id_arr integer[];
9552+
r_id integer;
9553+
begin
9554+
p_id_arr := '{1,2,3}'::integer[];
9555+
foreach r_id in array p_id_arr
9556+
loop
9557+
raise notice 'id: %', r_id;
9558+
end loop;
9559+
--the following loop causes an error
9560+
foreach r_id in array p_id_arr
9561+
loop
9562+
raise notice 'id: %', r_id;
9563+
end loop;
9564+
end;
9565+
$$ language plpgsql;
9566+
-- should not to raise false alarm #195
9567+
select * from plpgsql_check_function('double_usage_of_const_str');
9568+
plpgsql_check_function
9569+
------------------------
9570+
(0 rows)
9571+

expected/plpgsql_check_active_4.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9545,3 +9545,28 @@ select * from plpgsql_check_function('test_proc_composite');
95459545
drop function test_proc_composite;
95469546
drop procedure proc_composite;
95479547
drop type ct;
9548+
create or replace function double_usage_of_const_str()
9549+
returns void
9550+
as $$
9551+
declare
9552+
p_id_arr integer[];
9553+
r_id integer;
9554+
begin
9555+
p_id_arr := '{1,2,3}'::integer[];
9556+
foreach r_id in array p_id_arr
9557+
loop
9558+
raise notice 'id: %', r_id;
9559+
end loop;
9560+
--the following loop causes an error
9561+
foreach r_id in array p_id_arr
9562+
loop
9563+
raise notice 'id: %', r_id;
9564+
end loop;
9565+
end;
9566+
$$ language plpgsql;
9567+
-- should not to raise false alarm #195
9568+
select * from plpgsql_check_function('double_usage_of_const_str');
9569+
plpgsql_check_function
9570+
------------------------
9571+
(0 rows)
9572+

sql/plpgsql_check_active.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5690,3 +5690,26 @@ select * from plpgsql_check_function('test_proc_composite');
56905690
drop function test_proc_composite;
56915691
drop procedure proc_composite;
56925692
drop type ct;
5693+
5694+
create or replace function double_usage_of_const_str()
5695+
returns void
5696+
as $$
5697+
declare
5698+
p_id_arr integer[];
5699+
r_id integer;
5700+
begin
5701+
p_id_arr := '{1,2,3}'::integer[];
5702+
foreach r_id in array p_id_arr
5703+
loop
5704+
raise notice 'id: %', r_id;
5705+
end loop;
5706+
--the following loop causes an error
5707+
foreach r_id in array p_id_arr
5708+
loop
5709+
raise notice 'id: %', r_id;
5710+
end loop;
5711+
end;
5712+
$$ language plpgsql;
5713+
5714+
-- should not to raise false alarm #195
5715+
select * from plpgsql_check_function('double_usage_of_const_str');

src/check_expr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,6 @@ plpgsql_check_expr_as_rvalue(PLpgSQL_checkstate *cstate, PLpgSQL_expr *expr,
12991299

13001300
getTypeInputInfo(typeid, &infunc, &intypeioparam);
13011301
(void) OidInputFunctionCall(infunc, str, intypeioparam, -1);
1302-
1303-
pfree(str);
13041302
}
13051303
}
13061304

0 commit comments

Comments
 (0)