Skip to content

Commit

Permalink
params: Move xdecrefs after last use
Browse files Browse the repository at this point in the history
The code would work because the sequence still held references, but at first glance it looks
like it could be a bug.  Moving it makes it clear it is not.  An easier solution would be to
use the GET_ITEM macro which doesn't increment the reference count, but I'm hoping to move to
the stable ABI which doesn't support that.  We could also use the Object wrapper, but I want to
change as little as possible for now.
  • Loading branch information
mkleehammer committed Oct 10, 2023
1 parent 8a4555d commit 215dbaa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ static bool GetTableInfo(Cursor *cur, Py_ssize_t index, PyObject* param, ParamIn
if (nrows > 0)
{
PyObject *cell0 = PySequence_GetItem(param, 0);
Py_XDECREF(cell0);
if (cell0 == NULL)
{
return false;
Expand All @@ -977,10 +976,11 @@ static bool GetTableInfo(Cursor *cur, Py_ssize_t index, PyObject* param, ParamIn
if (nrows > 1)
{
PyObject *cell1 = PySequence_GetItem(param, 1);
Py_XDECREF(cell1);
nskip += (PyBytes_Check(cell1) || PyUnicode_Check(cell1));
Py_XDECREF(cell1);
}
}
Py_XDECREF(cell0);
}
nrows -= nskip;

Expand Down

0 comments on commit 215dbaa

Please sign in to comment.