From 09be4dc5d15e64fb4dec7ef20c96168bcf860b49 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 23 Feb 2012 19:48:46 +0000 Subject: [PATCH] Fixed potential failures while setting exceptions attributes --- psycopg/psycopgmodule.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index eb8d55c9..60cc8e2d 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -635,15 +635,17 @@ psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg, } if (pgerror) { - t = conn_text_from_chars(conn, pgerror); - PyObject_SetAttrString(err, "pgerror", t); - Py_DECREF(t); + if ((t = conn_text_from_chars(conn, pgerror))) { + PyObject_SetAttrString(err, "pgerror", t); + Py_DECREF(t); + } } if (pgcode) { - t = conn_text_from_chars(conn, pgcode); - PyObject_SetAttrString(err, "pgcode", t); - Py_DECREF(t); + if ((t = conn_text_from_chars(conn, pgcode))) { + PyObject_SetAttrString(err, "pgcode", t); + Py_DECREF(t); + } } PyErr_SetObject(exc, err);