postgresql/src/backend
Tom Lane bf34ae930d 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
..
access Fix missing fsync of SLRU directories. 2020-09-24 10:36:27 +12:00
bootstrap Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:15 -07:00
catalog Fix misleading error message about inconsistent moving-aggregate types. 2020-09-06 12:56:10 -04:00
commands Revise RelationBuildRowSecurity() to avoid memory leaks. 2020-09-26 16:04:06 -04:00
executor Be more careful about the shape of hashable subplan clauses. 2020-08-14 22:14:03 -04:00
foreign Code review for foreign/custom join pushdown patch. 2015-05-10 14:36:36 -04:00
lib Revert "Permit dump/reload of not-too-large >1GB tuples" 2016-12-06 12:45:49 -03:00
libpq Avoid logging complaints about abandoned connections when using PAM. 2019-11-05 14:27:37 -05:00
main Install Windows crash dump handler before all else. 2017-11-12 14:31:04 -08:00
nodes Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:15 -07:00
optimizer Avoid pushing quals down into sub-queries that have grouping sets. 2020-08-22 14:46:40 -04:00
parser Fix handling of CREATE TABLE LIKE with inheritance. 2020-08-21 15:00:43 -04:00
po Translation updates 2020-08-10 15:36:46 +02:00
port Fix race condition in our Windows signal emulation. 2019-12-09 15:03:52 -05:00
postmaster Use _exit(2) for SIGQUIT during ProcessStartupPacket, too. 2020-09-10 12:06:26 -04:00
regex Fix misoptimization of "{1,1}" quantifiers in regular expressions. 2019-05-12 18:53:43 -04:00
replication walsnd: Don't set waiting_for_ping_response spuriously 2020-08-08 12:31:55 -04:00
rewrite Make rewriter prevent auto-updates on views with conditional INSTEAD rules. 2020-01-14 09:48:44 +00:00
snowball Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
storage Prevent concurrent SimpleLruTruncate() for any given SLRU. 2020-08-15 10:15:57 -07:00
tcop Use the properly transformed RangeVar for expandTableLikeClause(). 2020-09-13 12:51:21 -04:00
tsearch Avoid possible dangling-pointer access in tsearch_readline_callback. 2020-09-23 11:36:13 -04:00
utils Move new LOCKTAG_DATABASE_FROZEN_IDS to end of enum LockTagType. 2020-08-15 16:16:42 -07:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:45:38 -04:00
nls.mk Translation updates 2015-02-01 23:23:40 -05:00