From cf56054d182a676ffad34f726925c2d8606065ce Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Norrington <ben@norrington.net> Date: Fri, 29 Mar 2024 14:58:44 +0000 Subject: [PATCH 1/2] Fix memory leak for strings passed to TVP --- src/cursor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cursor.cpp b/src/cursor.cpp index 5d7d80a4..08002453 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -873,8 +873,6 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski Py_XDECREF(prevParam->pObject); newParam.BufferLength = newParam.StrLen_or_Ind; newParam.StrLen_or_Ind = SQL_DATA_AT_EXEC; - Py_INCREF(cell); - newParam.pObject = cell; *prevParam = newParam; if(prevParam->ParameterValuePtr == &newParam.Data) { From 59605912127e1f7434294c8c7ab9b58550c1d365 Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Norrington <ben@norrington.net> Date: Fri, 29 Mar 2024 16:23:16 +0000 Subject: [PATCH 2/2] Fix first item in sequence memory leak from ref count increasing Fix suggested by @v-chojas and @gordthompson --- src/params.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/params.cpp b/src/params.cpp index c17a9197..6d3e6b49 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -1266,6 +1266,7 @@ bool BindParameter(Cursor* cur, Py_ssize_t index, ParamInfo& info) { // Bind the TVP's columns --- all need to use DAE PyObject *param = PySequence_GetItem(row, i); + Py_XDECREF(param); GetParameterInfo(cur, i, param, info.nested[i], true); info.nested[i].BufferLength = info.nested[i].StrLen_or_Ind; info.nested[i].StrLen_or_Ind = SQL_DATA_AT_EXEC;