From e1e0b34343dff015a948e2728b8356ade685c43e Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sun, 15 May 2005 10:29:59 +0000 Subject: [PATCH] Fixed wrong refcnt on None. --- ChangeLog | 5 +++++ psycopg/microprotocols.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1c423311..ea9be31f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-05-15 Federico Di Gregorio + + * psycopg/microprotocols.c (microprotocols_adapt): fixed memory + leak on None as suggested by gh (bug #16.) + 2005-05-10 Federico Di Gregorio * lib/extras.py (DictRow): we now save a reference to the index diff --git a/psycopg/microprotocols.c b/psycopg/microprotocols.c index 6f75f250..4f97279c 100644 --- a/psycopg/microprotocols.c +++ b/psycopg/microprotocols.c @@ -93,6 +93,7 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) if (PyObject_HasAttrString(proto, "__adapt__")) { PyObject *adapted = PyObject_CallMethod(proto, "__adapt__", "O", obj); if (adapted && adapted != Py_None) return adapted; + Py_XDECREF(adapted); if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_TypeError)) return NULL; } @@ -101,6 +102,7 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) if (PyObject_HasAttrString(obj, "__conform__")) { PyObject *adapted = PyObject_CallMethod(obj, "__conform__","O", proto); if (adapted && adapted != Py_None) return adapted; + Py_XDECREF(adapted); if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_TypeError)) return NULL; }