Fix tons of memleaks and memory management problems
This commit is contained in:
@@ -79,13 +79,12 @@ void check_py_error() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: need to decref error_func as well on successful run
|
||||
kj::Promise<PyObject *> wrapPyFunc(PyObject * func, PyObject * arg) {
|
||||
auto arg_promise = extract_promise(arg);
|
||||
|
||||
if(arg_promise == NULL) {
|
||||
PyObject * result = PyObject_CallFunctionObjArgs(func, arg, NULL);
|
||||
Py_DECREF(func);
|
||||
Py_DECREF(arg);
|
||||
|
||||
check_py_error();
|
||||
|
||||
@@ -104,7 +103,6 @@ kj::Promise<PyObject *> wrapPyFunc(PyObject * func, PyObject * arg) {
|
||||
|
||||
kj::Promise<PyObject *> wrapPyFuncNoArg(PyObject * func) {
|
||||
PyObject * result = PyObject_CallFunctionObjArgs(func, NULL);
|
||||
Py_DECREF(func);
|
||||
|
||||
check_py_error();
|
||||
|
||||
@@ -189,6 +187,23 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class PyRefCounter {
|
||||
public:
|
||||
PyObject * obj;
|
||||
|
||||
PyRefCounter(PyObject * o) : obj(o) {
|
||||
Py_INCREF(obj);
|
||||
}
|
||||
|
||||
PyRefCounter(const PyRefCounter & ref) : obj(ref.obj) {
|
||||
Py_INCREF(obj);
|
||||
}
|
||||
|
||||
~PyRefCounter() {
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
};
|
||||
|
||||
capnp::DynamicCapability::Client new_client(capnp::InterfaceSchema & schema, PyObject * server) {
|
||||
return capnp::DynamicCapability::Client(kj::heap<PythonInterfaceDynamicImpl>(schema, server));
|
||||
}
|
||||
|
||||
@@ -5,4 +5,6 @@ cdef extern from "../helpers/capabilityHelper.h":
|
||||
PythonInterfaceDynamicImpl(PyObject *)
|
||||
|
||||
cdef extern from "../helpers/capabilityHelper.h":
|
||||
void reraise_kj_exception()
|
||||
void reraise_kj_exception()
|
||||
cdef cppclass PyRefCounter:
|
||||
PyRefCounter(PyObject *)
|
||||
Reference in New Issue
Block a user