mirror of
https://github.com/postgres/postgres.git
synced 2025-11-01 21:31:19 +03:00
Previously, plpython was in the habit of allocating a lot of stuff in TopMemoryContext, and it was very slipshod about making sure that stuff got cleaned up; in particular, use of TopMemoryContext as fn_mcxt for function calls represents an unfixable leak, since we generally don't know what the called function might have allocated in fn_mcxt. This results in session-lifespan leakage in certain usage scenarios, as for example in a case reported by Ed Behn back in July. To fix, get rid of all the retail allocations in TopMemoryContext. All long-lived allocations are now made in sub-contexts that are associated with specific objects (either pl/python procedures, or Python-visible objects such as cursors and plans). We can clean these up when the associated object is deleted. I went so far as to get rid of PLy_malloc completely. There were a couple of places where it could still have been used safely, but on the whole it was just an invitation to bad coding. Haribabu Kommi, based on a draft patch by Heikki Linnakangas; some further work by me
32 lines
935 B
C
32 lines
935 B
C
/*
|
|
* src/pl/plpython/plpy_main.h
|
|
*/
|
|
|
|
#ifndef PLPY_MAIN_H
|
|
#define PLPY_MAIN_H
|
|
|
|
#include "plpy_procedure.h"
|
|
|
|
/* the interpreter's globals dict */
|
|
extern PyObject *PLy_interp_globals;
|
|
|
|
/*
|
|
* A stack of PL/Python execution contexts. Each time user-defined Python code
|
|
* is called, an execution context is created and put on the stack. After the
|
|
* Python code returns, the context is destroyed.
|
|
*/
|
|
typedef struct PLyExecutionContext
|
|
{
|
|
PLyProcedure *curr_proc; /* the currently executing procedure */
|
|
MemoryContext scratch_ctx; /* a context for things like type I/O */
|
|
struct PLyExecutionContext *next; /* previous stack level */
|
|
} PLyExecutionContext;
|
|
|
|
/* Get the current execution context */
|
|
extern PLyExecutionContext *PLy_current_execution_context(void);
|
|
|
|
/* Get the scratch memory context for specified execution context */
|
|
extern MemoryContext PLy_get_scratch_context(PLyExecutionContext *context);
|
|
|
|
#endif /* PLPY_MAIN_H */
|