postgresql/src/backend/tsearch
Tom Lane 0b618ddf8b 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
2021-03-18 21:44:43 -04:00
..
dicts Fix whitespace and remove obsolete gitattributes entry 2016-03-13 16:03:13 -04:00
dict.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
dict_ispell.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
dict_simple.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
dict_synonym.c Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
dict_thesaurus.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
Makefile Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
regis.c Initial pgindent run with pg_bsd_indent version 2.0. 2017-06-21 14:39:04 -04:00
spell.c Don't leak compiled regex(es) when an ispell cache entry is dropped. 2021-03-18 21:44:43 -04:00
to_tsany.c Improve make_tsvector() to handle empty input, and simplify its callers. 2017-07-18 13:13:47 -04:00
ts_locale.c Avoid possible dangling-pointer access in tsearch_readline_callback. 2020-09-23 11:36:13 -04:00
ts_parse.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
ts_selfuncs.c Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed. 2017-05-13 15:14:39 -04:00
ts_typanalyze.c Reduce memory usage of tsvector type analyze function. 2017-07-12 22:06:13 +03:00
ts_utils.c Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
wparser.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
wparser_def.c Fix recently-introduced performance problem in ts_headline(). 2020-07-31 11:43:12 -04:00