From 215dbaa28929026a6d933c8167dad6240201e92e Mon Sep 17 00:00:00 2001 From: Michael Kleehammer Date: Tue, 10 Oct 2023 09:31:00 -0500 Subject: [PATCH] params: Move xdecrefs after last use 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. --- src/params.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/params.cpp b/src/params.cpp index efb55a3a..1a0547ea 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -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; @@ -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;