pyodbc icon indicating copy to clipboard operation
pyodbc copied to clipboard

Getting a segfault when using the encoding argument in pyodbc.connect()

Open will133 opened this issue 6 years ago • 0 comments

Environment

Linux 64-bit:

  • Python: 3.6.8
  • pyodbc: 4.0.26
  • OS: Linux 64-bit
  • DB: sybase

Issue

I'm getting this really strange error when I pass in the encoding parameter to the pyodbc.connect(). However, when my program exits randomly it could segfault (it's somewhat difficult to reproduce, but it's pretty consistent). When stepping through gdb it's dying in some python string gc code. I think it may have to do with the following:

https://github.com/mkleehammer/pyodbc/blob/45395fe723b837e836643897ff3df57034c05b22/src/pyodbcmodule.cpp#L496-L505

It looks like the value when returned by the PyDict_Next doesn't increase the reference count for value when it sets the reference. However, when the "Object encoding" exits the scope, it's trying to call Py_XDECREF(p) on the value nevertheless. I think this would cause the wrong reference count on the value. I added a Py_INCREF(value) before the "encoding = value" line and it seems to get rid of the segfault problem. Do you think that's the right thing to do?

will133 avatar Apr 30 '19 14:04 will133