-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak when passing strings within table value parameter to stored proc #1338
Comments
Could you post an ODBC trace? |
Reproduced on Ubuntu 20.04. Both .rss and .vms increase. Same behaviour if cursor is created, consumed (.fetchall()), and closed for each iteration. |
ODBC trace logs for "execute with float" and "execute with str", using 5_000 rows. (Trace logs for 1_000_000 rows were almost 500 MiB each unzipped.) |
Note also that this is not a version 5.x regression; version 4.0.39 produces the same results. |
No need to run it with that many rows since the pattern shows up with far less. I think the code is missing a Py_XDECREF(param) after this line: https://github.com/mkleehammer/pyodbc/blob/master/src/params.cpp#L1268 |
I added this to my local build but the leak persists. @@ -1264,10 +1264,11 @@ bool BindParameter(Cursor* cur, Py_ssize_t index, ParamInfo& info)
for(i=0;i<ncols;i++)
{
// 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;
Py_BEGIN_ALLOW_THREADS |
Some more testing that might help. The leak still occurs if you take the creation of the |
I have found a related memory leak (that I think may have been spotted before) when you insert a long string with Both of these memory leaks are because of the same problem but in two difference places where some coded is duplicated. The TVP issue is caused because in This is the same issue with Line 314 in ff1dd23
|
Please ignore the second memory leak. I think I may have imagined it as I cannot replicate. The line I thought was leaking is working fine and is cleaned up by this code further down in the file Line 1772 in ff1dd23
|
Environment
Issue
Memory leak when string values supplied to table valued parameter of stored proc. Same data supplied as float does not leak memory.
Example code
Following code should reproduce the error.
Output of sample code
The text was updated successfully, but these errors were encountered: