postgresql/src
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
..
backend Revise RelationBuildRowSecurity() to avoid memory leaks. 2020-09-26 16:04:06 -04:00
bin Fix handling of -d "connection string" in pg_dump/pg_restore. 2020-09-24 18:19:38 -04:00
common Rethink API for pg_get_line.c, one more time. 2020-09-22 15:55:13 -04:00
fe_utils Standardize the printf format for st_size 2020-09-24 21:04:21 +02:00
include Fix the logical replication from HEAD to lower versions. 2020-09-26 10:13:51 +05:30
interfaces Remove arbitrary line length limit for libpq service files. 2020-09-22 15:59:23 -04:00
makefiles Remove libpq.rc, use win32ver.rc for libpq 2020-01-15 15:06:12 +01:00
pl Fix a few more generator scripts to produce pgindent-clean output. 2020-09-21 13:58:26 -04:00
port Add d_type to our Windows dirent emulation. 2020-09-07 23:38:19 +12:00
template Fix compiler warning for ppoll() on Cygwin 2019-12-22 23:20:00 +01:00
test Improve error cursor positions for problems with partition bounds. 2020-09-23 18:04:53 -04:00
timezone Ensure that distributed timezone abbreviation files are plain ASCII. 2020-07-17 11:03:55 -04:00
tools Defer flushing of SLRU files. 2020-09-25 19:00:15 +12:00
tutorial Remove support for postfix (right-unary) operators. 2020-09-17 19:38:05 -04:00
.gitignore
DEVELOPERS
Makefile Fix partial-build problems introduced by having more generated headers. 2018-04-09 16:42:10 -04:00
Makefile.global.in Split Makefile symbol CFLAGS_VECTOR into two symbols. 2020-09-06 21:28:16 -04:00
Makefile.shlib Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nls-global.mk NLS: Fix backend gettext triggers 2019-09-23 09:04:20 +02:00