|
8 | 8 |
|
9 | 9 | #include "access/xact.h" |
10 | 10 | #include "mb/pg_wchar.h" |
| 11 | +#include "utils/memutils.h" |
11 | 12 |
|
12 | 13 | #include "plpython.h" |
13 | 14 |
|
@@ -111,7 +112,12 @@ PLy_cursor_query(const char *query) |
111 | 112 | return NULL; |
112 | 113 | cursor->portalname = NULL; |
113 | 114 | cursor->closed = false; |
114 | | - PLy_typeinfo_init(&cursor->result); |
| 115 | + cursor->mcxt = AllocSetContextCreate(TopMemoryContext, |
| 116 | + "PL/Python cursor context", |
| 117 | + ALLOCSET_DEFAULT_MINSIZE, |
| 118 | + ALLOCSET_DEFAULT_INITSIZE, |
| 119 | + ALLOCSET_DEFAULT_MAXSIZE); |
| 120 | + PLy_typeinfo_init(&cursor->result, cursor->mcxt); |
115 | 121 |
|
116 | 122 | oldcontext = CurrentMemoryContext; |
117 | 123 | oldowner = CurrentResourceOwner; |
@@ -139,7 +145,7 @@ PLy_cursor_query(const char *query) |
139 | 145 | elog(ERROR, "SPI_cursor_open() failed: %s", |
140 | 146 | SPI_result_code_string(SPI_result)); |
141 | 147 |
|
142 | | - cursor->portalname = PLy_strdup(portal->name); |
| 148 | + cursor->portalname = MemoryContextStrdup(cursor->mcxt, portal->name); |
143 | 149 |
|
144 | 150 | PLy_spi_subtransaction_commit(oldcontext, oldowner); |
145 | 151 | } |
@@ -200,7 +206,12 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) |
200 | 206 | return NULL; |
201 | 207 | cursor->portalname = NULL; |
202 | 208 | cursor->closed = false; |
203 | | - PLy_typeinfo_init(&cursor->result); |
| 209 | + cursor->mcxt = AllocSetContextCreate(TopMemoryContext, |
| 210 | + "PL/Python cursor context", |
| 211 | + ALLOCSET_DEFAULT_MINSIZE, |
| 212 | + ALLOCSET_DEFAULT_INITSIZE, |
| 213 | + ALLOCSET_DEFAULT_MAXSIZE); |
| 214 | + PLy_typeinfo_init(&cursor->result, cursor->mcxt); |
204 | 215 |
|
205 | 216 | oldcontext = CurrentMemoryContext; |
206 | 217 | oldowner = CurrentResourceOwner; |
@@ -261,7 +272,7 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) |
261 | 272 | elog(ERROR, "SPI_cursor_open() failed: %s", |
262 | 273 | SPI_result_code_string(SPI_result)); |
263 | 274 |
|
264 | | - cursor->portalname = PLy_strdup(portal->name); |
| 275 | + cursor->portalname = MemoryContextStrdup(cursor->mcxt, portal->name); |
265 | 276 |
|
266 | 277 | PLy_spi_subtransaction_commit(oldcontext, oldowner); |
267 | 278 | } |
@@ -315,12 +326,13 @@ PLy_cursor_dealloc(PyObject *arg) |
315 | 326 |
|
316 | 327 | if (PortalIsValid(portal)) |
317 | 328 | SPI_cursor_close(portal); |
| 329 | + cursor->closed = true; |
| 330 | + } |
| 331 | + if (cursor->mcxt) |
| 332 | + { |
| 333 | + MemoryContextDelete(cursor->mcxt); |
| 334 | + cursor->mcxt = NULL; |
318 | 335 | } |
319 | | - |
320 | | - PLy_free(cursor->portalname); |
321 | | - cursor->portalname = NULL; |
322 | | - |
323 | | - PLy_typeinfo_dealloc(&cursor->result); |
324 | 336 | arg->ob_type->tp_free(arg); |
325 | 337 | } |
326 | 338 |
|
|
0 commit comments