Skip to content

Commit

Permalink
Fix reference counting issue in cast_array/record (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Nov 29, 2020
1 parent c515f04 commit df10437
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pgmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,12 +1055,10 @@ pg_cast_array(PyObject *self, PyObject *args, PyObject *dict)
return NULL;
}

if (!cast_obj || cast_obj == Py_None) {
if (cast_obj) {
Py_DECREF(cast_obj); cast_obj = NULL;
}
if (cast_obj == Py_None) {
cast_obj = NULL;
}
else if (!PyCallable_Check(cast_obj)) {
else if (cast_obj && !PyCallable_Check(cast_obj)) {
PyErr_SetString(
PyExc_TypeError,
"Function cast_array() expects a callable as second argument");
Expand Down Expand Up @@ -1116,12 +1114,12 @@ pg_cast_record(PyObject *self, PyObject *args, PyObject *dict)
len = 0;
}
else if (cast_obj == Py_None) {
Py_DECREF(cast_obj); cast_obj = NULL; len = 0;
cast_obj = NULL; len = 0;
}
else if (PyTuple_Check(cast_obj) || PyList_Check(cast_obj)) {
len = PySequence_Size(cast_obj);
if (!len) {
Py_DECREF(cast_obj); cast_obj = NULL;
cast_obj = NULL;
}
}
else {
Expand Down

0 comments on commit df10437

Please sign in to comment.