Skip to content

Commit c4c2fd1

Browse files
committed
Dropped possible wrong code path in conn_decode
It shouldn't happen for both cdecoder and pydecoder to be null, but just in case...
1 parent 8108c59 commit c4c2fd1

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

psycopg/connection_int.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,33 +121,35 @@ conn_encode(connectionObject *self, PyObject *u)
121121
PyObject *
122122
conn_decode(connectionObject *self, const char *str, Py_ssize_t len)
123123
{
124-
PyObject *b = NULL;
125-
PyObject *t = NULL;
126-
PyObject *rv = NULL;
127-
128124
if (len < 0) { len = strlen(str); }
129125

130126
if (self) {
131127
if (self->cdecoder) {
132128
return self->cdecoder(str, len, NULL);
133129
}
134130
else if (self->pydecoder) {
135-
if (!(b = Bytes_FromStringAndSize(str, len))) { goto exit; }
131+
PyObject *b = NULL;
132+
PyObject *t = NULL;
133+
PyObject *rv = NULL;
134+
135+
if (!(b = Bytes_FromStringAndSize(str, len))) { goto error; }
136136
if (!(t = PyObject_CallFunctionObjArgs(self->pydecoder, b, NULL))) {
137-
goto exit;
137+
goto error;
138138
}
139-
rv = PyTuple_GetItem(t, 0);
140-
Py_XINCREF(rv);
139+
if (!(rv = PyTuple_GetItem(t, 0))) { goto error; }
140+
Py_INCREF(rv); /* PyTuple_GetItem gives a borrowes one */
141+
error:
142+
Py_XDECREF(t);
143+
Py_XDECREF(b);
144+
return rv;
145+
}
146+
else {
147+
return PyUnicode_FromStringAndSize(str, len);
141148
}
142149
}
143150
else {
144151
return PyUnicode_FromStringAndSize(str, len);
145152
}
146-
147-
exit:
148-
Py_XDECREF(t);
149-
Py_XDECREF(b);
150-
return rv;
151153
}
152154

153155
/* conn_notice_callback - process notices */

0 commit comments

Comments
 (0)