10000 Fix multiple memory leaks in PLy_spi_execute_fetch_result: it would leak · danielcode/postgres@0920c29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0920c29

Browse files
committed
Fix multiple memory leaks in PLy_spi_execute_fetch_result: it would leak
memory if the result had zero rows, and also if there was any sort of error while converting the result tuples into Python data. Reported and partially fixed by Andres Freund. Back-patch to all supported versions. Note: I haven't tested the 7.4 fix. 7.4's configure check for python is so obsolete it doesn't work on my current machines :-(. The logic change is pretty straightforward though.
1 parent 7c853ee commit 0920c29

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/pl/plpython/plpython.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.58.4.10 2010/02/18 23:50:41 tgl Exp $
32+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.58.4.11 2010/04/30 19:16:19 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -2209,9 +2209,9 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status)
22092209
PLyTypeInfo args;
22102210
int i;
22112211

2212-
PLy_typeinfo_init(&args);
22132212
Py_DECREF(result->nrows);
22142213
result->nrows = PyInt_FromLong(rows);
2214+
PLy_typeinfo_init(&args);
22152215

22162216
oldcontext = CurrentMemoryContext;
22172217
PG_TRY();
@@ -2229,9 +2229,6 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status)
22292229

22302230
PyList_SetItem(result->rows, i, row);
22312231
}
2232-
PLy_typeinfo_dealloc(&args);
2233-
2234-
SPI_freetuptable(tuptable);
22352232
}
22362233
}
22372234
PG_CATCH();
@@ -2242,11 +2239,15 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status)
22422239
if (!PyErr_Occurred())
22432240
PyErr_SetString(PLy_exc_error,
22442241
"Unknown error in PLy_spi_execute_fetch_result");
2245-
Py_DECREF(result);
22462242
PLy_typeinfo_dealloc(&args);
2243+
SPI_freetuptable(tuptable);
2244+
Py_DECREF(result);
22472245
return NULL;
22482246
}
22492247
PG_END_TRY();
2248+
2249+
PLy_typeinfo_dealloc(&args);
2250+
SPI_freetuptable(tuptable);
22502251
}
22512252

22522253
return (PyObject *) result;

0 commit comments

Comments
 (0)
0