summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-12-28 04:39:15 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-01-21 02:41:58 +0000
commit5b28d7b9c9bca78bcd8b46bfea94dd2e209ec1f4 (patch)
tree48f4c30e8c2df4568e6d18fa8f08e7da9a2837e0
parent117f7d33f87a377008ef706f9e167cf4fcab57bf (diff)
downloadpsycopg2-5b28d7b9c9bca78bcd8b46bfea94dd2e209ec1f4.tar.gz
Dropped possible wrong code path in conn_decode
It shouldn't happen for both cdecoder and pydecoder to be null, but just in case...
-rw-r--r--psycopg/connection_int.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index a60c4a9..7f6b755 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -121,10 +121,6 @@ exit:
PyObject *
conn_decode(connectionObject *self, const char *str, Py_ssize_t len)
{
- PyObject *b = NULL;
- PyObject *t = NULL;
- PyObject *rv = NULL;
-
if (len < 0) { len = strlen(str); }
if (self) {
@@ -132,22 +128,28 @@ conn_decode(connectionObject *self, const char *str, Py_ssize_t len)
return self->cdecoder(str, len, NULL);
}
else if (self->pydecoder) {
- if (!(b = Bytes_FromStringAndSize(str, len))) { goto exit; }
+ PyObject *b = NULL;
+ PyObject *t = NULL;
+ PyObject *rv = NULL;
+
+ if (!(b = Bytes_FromStringAndSize(str, len))) { goto error; }
if (!(t = PyObject_CallFunctionObjArgs(self->pydecoder, b, NULL))) {
- goto exit;
+ goto error;
}
- rv = PyTuple_GetItem(t, 0);
- Py_XINCREF(rv);
+ if (!(rv = PyTuple_GetItem(t, 0))) { goto error; }
+ Py_INCREF(rv); /* PyTuple_GetItem gives a borrowes one */
+error:
+ Py_XDECREF(t);
+ Py_XDECREF(b);
+ return rv;
+ }
+ else {
+ return PyUnicode_FromStringAndSize(str, len);
}
}
else {
return PyUnicode_FromStringAndSize(str, len);
}
-
-exit:
- Py_XDECREF(t);
- Py_XDECREF(b);
- return rv;
}
/* conn_notice_callback - process notices */