pgsql: Revise RelationBuildRowSecurity() to avoid memory leaks.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Revise RelationBuildRowSecurity() to avoid memory leaks.
Дата
Msg-id E1kMGRG-0003Xb-Mh@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e55f718fc429fb7971eb7351debfa5931f9811bf

Modified Files
--------------
src/backend/commands/policy.c | 216 +++++++++++++++++++-----------------------
1 file changed, 98 insertions(+), 118 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Amit Kapila
Дата:
Сообщение: pgsql: Fix the logical replication from HEAD to lower versions.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Further stabilize output from rolenames regression test.