postgresql/src/backend/commands
Tom Lane e55f718fc4 Revise RelationBuildRowSecurity() to avoid memory leaks.
This function leaked some memory while loading qual clauses for
an RLS policy.  While ordinarily negligible, that could build up
in some repeated-reload cases, as reported by Konstantin Knizhnik.
We can improve matters by borrowing the coding long used in
RelationBuildRuleLock: build stringToNode's result directly in
the target context, and remember to explicitly pfree the
input string.

This patch by no means completely guarantees zero leaks within
this function, since we have no real guarantee that the catalog-
reading subroutines it calls don't leak anything.  However,
practical tests suggest that this is enough to resolve the issue.
In any case, any remaining leaks are similar to those risked by
RelationBuildRuleLock and other relcache-loading subroutines.
If we need to fix them, we should adopt a more global approach
such as that used by the RECOVER_RELATION_BUILD_MEMORY hack.

While here, let's remove the need for an expensive PG_TRY block by
using MemoryContextSetParent to reparent an initially-short-lived
context for the RLS data.

Back-patch to all supported branches.

Discussion: https://postgr.es/m/21356c12-8917-8249-b35f-1c447231922b@postgrespro.ru
2020-09-26 16:04:06 -04:00
..
Makefile Revert 0f5ca02f53 2020-04-08 11:37:27 +03:00
aggregatecmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
alter.c Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
amcmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
analyze.c snapshot scalability: Don't compute global horizons while building snapshots. 2020-08-12 16:03:49 -07:00
async.c Defer flushing of SLRU files. 2020-09-25 19:00:15 +12:00
cluster.c Set cutoff xmin more aggressively when vacuuming a temporary table. 2020-09-01 18:40:43 -04:00
collationcmds.c Remove utils/acl.h from catalog/objectaddress.h 2020-03-10 10:27:00 +01:00
comment.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
constraint.c Fix bogus CALLED_AS_TRIGGER() defenses. 2020-04-03 11:24:56 -04:00
conversioncmds.c Remove utils/acl.h from catalog/objectaddress.h 2020-03-10 10:27:00 +01:00
copy.c Don't fetch partition check expression during InitResultRelInfo. 2020-09-16 14:28:18 -04:00
createas.c Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
dbcommands.c Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
define.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
discard.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
dropcmds.c Remove utils/acl.h from catalog/objectaddress.h 2020-03-10 10:27:00 +01:00
event_trigger.c Fix use-after-free bug with event triggers in an extension script 2020-09-15 21:03:14 -03:00
explain.c Rework EXPLAIN for planner's buffer usage. 2020-08-21 20:48:59 +09:00
extension.c Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
foreigncmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
functioncmds.c Switch to multi-inserts when registering dependencies for many code paths 2020-09-05 21:33:53 +09:00
indexcmds.c Add support for partitioned tables and indexes in REINDEX 2020-09-08 10:09:22 +09:00
lockcmds.c Make inherited LOCK TABLE perform access permission checks on parent table only. 2020-02-18 13:13:15 +09:00
matview.c Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
opclasscmds.c Message fixes and style improvements 2020-09-14 06:42:30 +02:00
operatorcmds.c Remove support for postfix (right-unary) operators. 2020-09-17 19:38:05 -04:00
policy.c Revise RelationBuildRowSecurity() to avoid memory leaks. 2020-09-26 16:04:06 -04:00
portalcmds.c Avoid using a cursor in plpgsql's RETURN QUERY statement. 2020-06-12 12:14:32 -04:00
prepare.c Add generic_plans and custom_plans fields into pg_prepared_statements. 2020-07-20 11:55:50 +09:00
proclang.c Switch to multi-inserts when registering dependencies for many code paths 2020-09-05 21:33:53 +09:00
publicationcmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
schemacmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
seclabel.c Grammar object type refactoring 2020-06-13 09:19:30 +02:00
sequence.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statscmds.c Replace remaining StrNCpy() by strlcpy() 2020-08-10 23:20:37 +02:00
subscriptioncmds.c Add support for streaming to built-in logical replication. 2020-09-03 07:54:07 +05:30
tablecmds.c Improve error cursor positions for problems with partition bounds. 2020-09-23 18:04:53 -04:00
tablespace.c Fix temporary tablespaces for shared filesets some more. 2020-07-03 17:01:34 -04:00
trigger.c Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
tsearchcmds.c Switch to multi-inserts when registering dependencies for many code paths 2020-09-05 21:33:53 +09:00
typecmds.c Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
user.c Change default of password_encryption to scram-sha-256 2020-06-10 16:42:55 +02:00
vacuum.c Set cutoff xmin more aggressively when vacuuming a temporary table. 2020-09-01 18:40:43 -04:00
variable.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
view.c Restructure ALTER TABLE execution to fix assorted bugs. 2020-01-15 18:49:24 -05:00