mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 561 forks source link

Fix memory leak for strings passed to TVP #1339

Closed mavxg closed 5 months ago

mavxg commented 6 months ago

Fixes #1338

gordthompson commented 6 months ago

Looks okay to me, and it does appear to plug the leak. Thanks!

Should we include the Py_XDECREF call from here as well?

(My C++ skills are way too rusty to accept this PR myself.)

mavxg commented 6 months ago

Yes. It fixes another leak for the first row/tuple in the sequence. For TVP, BindParameters is getting just the first row (not sure what the reason behind the PySequence_Size(info.pObject) - info.ColumnSize to get the first item in the sequence). PyObject *param = PySequence_GetItem(row, i); will increase the ref count of the items in the first tuple in the sequence and the Py_XDECREF would then decrease it again.