Changeset: 1cad3a94fca8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1cad3a94fca8
Modified Files:
monetdb5/extras/pyapi/connection.c
monetdb5/extras/pyapi/pyapi.c
Branch: pythonudf
Log Message:
Fixed issues with incorrect reference counting of Python objects sometimes
causing segfaults.
diffs (50 lines):
diff --git a/monetdb5/extras/pyapi/connection.c
b/monetdb5/extras/pyapi/connection.c
--- a/monetdb5/extras/pyapi/connection.c
+++ b/monetdb5/extras/pyapi/connection.c
@@ -69,6 +69,7 @@ static PyObject *
return NULL;
}
PyDict_SetItem(result,
PyString_FromString(output->cols[i].name), numpy_array);
+ Py_DECREF(numpy_array);
}
_connection_cleanup_result(output);
return result;
@@ -163,6 +164,7 @@ static PyObject *
return NULL;
}
PyDict_SetItem(result, PyString_FromString(colname),
numpy_array);
+ Py_DECREF(numpy_array);
}
release_mmap_memory(ptr, self->query_ptr->memsize,
self->query_ptr->mmapid);
return result;
diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -1549,7 +1549,9 @@ wrapup:
// First clean up any return values
if (!ret->multidimensional) {
// Clean up numpy arrays, if they are there
- if (ret->numpy_array != NULL) Py_DECREF(ret->numpy_array);
+ if (ret->numpy_array != NULL && ret->numpy_array->ob_refcnt > 1) {
+ Py_DECREF(ret->numpy_array);
+ }
if (ret->numpy_mask != NULL) Py_DECREF(ret->numpy_mask);
}
}
@@ -2114,6 +2116,7 @@ PyObject *PyDict_CheckForConversion(PyOb
msg = createException(MAL, "pyapi.eval", "Expected a return value
with name \"%s\", but this key was not present in the dictionary.",
retcol_names[i]);
goto wrapup;
}
+ Py_INCREF(object);
object = PyObject_CheckForConversion(object, 1, NULL, return_message);
if (object == NULL) {
msg = createException(MAL, "pyapi.eval", "Error converting dict
return value \"%s\": %s.", retcol_names[i], *return_message);
@@ -2127,6 +2130,8 @@ PyObject *PyDict_CheckForConversion(PyOb
goto wrapup;
}
}
+ Py_DECREF(keys);
+ Py_DECREF(pResult);
return result;
wrapup:
*return_message = msg;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list