postgresql/src/pl/plpython
Tom Lane e557c82759 Avoid memory leak in validation of a PL/Python trigger function.
If we're trying to perform check_function_bodies validation
of a PL/Python trigger function, we create a new PLyProcedure,
but we don't put it into the PLy_procedure_cache hash table.
(Doing so would be useless, since we don't have the relation
OID that is part of the cache key for a trigger function, so
we could not make an entry that would be found by later uses.)
However, we didn't think through what to do instead, with the
result that the PLyProcedure was simply leaked.

It would take a pretty large number of CREATE FUNCTION operations
for this to amount to a serious problem, but it's easy to see the
memory bloat if you do CREATE OR REPLACE FUNCTION in a loop.

To fix, have PLy_procedure_get delete the new PLyProcedure
and return NULL if it's not going to cache the PLyProcedure.
I considered making plpython3_validator do the cleanup instead,
which would be more natural.  But then plpython3_validator would
have to know the rules under which PLy_procedure_get returns a
non-cached PLyProcedure, else it risks deleting something that's
pointed to by a cache entry.  On the whole it seems more robust
to deal with the case inside PLy_procedure_get.

Found by the new version of Coverity (nice catch!).  In the end
I feel this fix is more about satisfying Coverity than about
fixing a real-world problem, so I'm not going to back-patch.
2025-10-23 14:23:26 -04:00
..
expected Provide more-specific error details/hints for function lookup failures. 2025-09-16 12:17:02 -04:00
po Translation updates 2025-05-05 12:04:49 +02:00
sql PL/Python: Add event trigger support 2025-08-21 09:21:11 +02:00
.gitignore plpython: Remove regression test infrastructure for Python 2. 2022-03-07 18:20:51 -08:00
generate-spiexceptions.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
Makefile Don't put library-supplied -L/-I switches before user-supplied ones. 2025-07-29 15:17:40 -04:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
nls.mk Make formatting in nls.mk files more consistent 2024-05-14 09:21:17 +02:00
plpy_cursorobject.c Sync typedefs.list with the buildfarm. 2025-06-15 13:04:24 -04:00
plpy_cursorobject.h Make PL/Python handle domain-type conversions correctly. 2017-11-16 16:23:04 -05:00
plpy_elog.c Fix resource leaks in PL/Python error reporting, redux. 2025-10-23 11:47:46 -04:00
plpy_elog.h Mark all symbols exported from extension libraries PGDLLEXPORT. 2022-07-17 18:50:14 -07:00
plpy_exec.c Make some use of anonymous unions [plpython] 2025-09-30 12:35:50 +02:00
plpy_exec.h PL/Python: Add event trigger support 2025-08-21 09:21:11 +02:00
plpy_main.c Avoid memory leak in validation of a PL/Python trigger function. 2025-10-23 14:23:26 -04:00
plpy_main.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
plpy_planobject.c Sync typedefs.list with the buildfarm. 2025-06-15 13:04:24 -04:00
plpy_planobject.h Repair memory leaks in plpython. 2025-01-11 11:45:56 -05:00
plpy_plpymodule.c Remove useless pstrdup() calls. 2025-10-22 16:22:52 -04:00
plpy_plpymodule.h plpython: add missing plpython.h include to plpy_plpymodule.h 2022-03-08 09:47:34 -08:00
plpy_procedure.c Avoid memory leak in validation of a PL/Python trigger function. 2025-10-23 14:23:26 -04:00
plpy_procedure.h PL/Python: Add event trigger support 2025-08-21 09:21:11 +02:00
plpy_resultobject.c Sync typedefs.list with the buildfarm. 2025-06-15 13:04:24 -04:00
plpy_resultobject.h Fix assorted header files that failed to compile standalone. 2019-05-31 11:45:33 -04:00
plpy_spi.c Remove circular #include's between plpython.h and plpy_util.h. 2025-04-27 11:43:02 -04:00
plpy_spi.h Fix SPI's handling of errors during transaction commit. 2022-02-28 12:45:36 -05:00
plpy_subxactobject.c Sync typedefs.list with the buildfarm. 2025-06-15 13:04:24 -04:00
plpy_subxactobject.h Make the order of the header file includes consistent. 2019-11-25 08:08:57 +05:30
plpy_typeio.c Use CompactAttribute more often, when possible 2025-10-22 11:36:26 +13:00
plpy_typeio.h Make some use of anonymous unions [plpython] 2025-09-30 12:35:50 +02:00
plpy_util.c Remove circular #include's between plpython.h and plpy_util.h. 2025-04-27 11:43:02 -04:00
plpy_util.h Mark all symbols exported from extension libraries PGDLLEXPORT. 2022-07-17 18:50:14 -07:00
plpython.h Remove circular #include's between plpython.h and plpy_util.h. 2025-04-27 11:43:02 -04:00
plpython3u--1.0.sql Invent "trusted" extensions, and remove the pg_pltemplate catalog. 2020-01-29 18:42:43 -05:00
plpython3u.control Create extension infrastructure for the core procedural languages. 2011-03-04 21:51:14 -05:00
plpython_system.h Update copyright for 2025 2025-01-01 11:21:55 -05:00