From 2aedbedcbf7b29b1dad3eff01a46f897a48ad6de Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 22 Jan 2019 15:27:30 +0000 Subject: [PATCH] Work around refcount cpychecker bug Also increment error/code refcounts before storing in error state. --- psycopg/error_type.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/psycopg/error_type.c b/psycopg/error_type.c index ac40a0c5..fc1c941e 100644 --- a/psycopg/error_type.c +++ b/psycopg/error_type.c @@ -305,12 +305,20 @@ psyco_error_setstate(errorObject *self, PyObject *state) /* load the dict content in the structure */ Py_CLEAR(self->pgerror); - self->pgerror = PyDict_GetItemString(state, "pgerror"); - Py_XINCREF(self->pgerror); + { + PyObject *tmp; + tmp = PyDict_GetItemString(state, "pgerror"); + Py_XINCREF(tmp); + self->pgerror = TO_STATE(tmp); + } Py_CLEAR(self->pgcode); - self->pgcode = PyDict_GetItemString(state, "pgcode"); - Py_XINCREF(self->pgcode); + { + PyObject *tmp; + tmp = PyDict_GetItemString(state, "pgcode"); + Py_XINCREF(tmp); + self->pgcode = TO_STATE(tmp); + } Py_CLEAR(self->cursor); /* We never expect a cursor in the state as it's not picklable.