pgsql: Don't leak compiled regex(es) when an ispell cache entry is drop - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Don't leak compiled regex(es) when an ispell cache entry is drop
Date
Msg-id E1lN4nd-0001oZ-Kn@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Don't leak compiled regex(es) when an ispell cache entry is dropped.

The text search cache mechanisms assume that we can clean up
an invalidated dictionary cache entry simply by resetting the
associated long-lived memory context.  However, that does not work
for ispell affixes that make use of regular expressions, because
the regex library deals in plain old malloc.  Hence, we leaked
compiled regex(es) any time we dropped such a cache entry.  That
could quickly add up, since even a fairly trivial regex can use up
tens of kB, and a large one can eat megabytes.  Add a memory context
callback to ensure that a regex gets freed when its owning cache
entry is cleared.

Found via valgrind testing.
This problem is ancient, so back-patch to all supported branches.

Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/099d2914f30b8c1c9d7aa09a8fa1e1ca3474866e

Modified Files
--------------
src/backend/tsearch/spell.c       | 34 ++++++++++++++++++++++++++++++----
src/include/tsearch/dicts/spell.h | 13 ++++++++++++-
2 files changed, 42 insertions(+), 5 deletions(-)


pgsql-committers by date:

Previous
From: Tomas Vondra
Date:
Subject: pgsql: Fix TAP test for remove_temp_files_after_crash
Next
From: Fujii Masao
Date:
Subject: pgsql: Fix comments in postmaster.c.