Fix tons of memleaks and memory management problems

This commit is contained in:
Jason Paryani
2013-12-11 22:25:57 -08:00
parent 2f0f03d1a8
commit a880994a6b
4 changed files with 115 additions and 48 deletions

View File

@@ -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));
}

View File

@@ -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 *)