Fixed potential failures while setting exceptions attributes

This commit is contained in:
Daniele Varrazzo 2012-02-23 19:48:46 +00:00
parent 7d67ecbed3
commit 09be4dc5d1

View File

@ -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);