more from the ivr mem leak hunt:

o IvrSipRequest/IvrSipReply python objects need to destroy the underlying c++ object, if they own them (so not for dlg.invite_req, which is the original c++ object owned by the AmSession)
 
 o IvrSipRequest/IvrSipReply python objects need to be DECREFd after calling the onSipRequest/onSipReply methods to free them




git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1356 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 17 years ago
parent 9128c0c7c2
commit 05ab89d4fe

@ -750,26 +750,26 @@ bool IvrDialog::onOtherReply(const AmSipReply& r)
PyObject * getPySipReply(const AmSipReply& r)
{
PYLOCK;
AmSipReply* rep_cpy = new AmSipReply(r);
return IvrSipReply_FromPtr(rep_cpy);
return IvrSipReply_FromPtr(new AmSipReply(r));
}
PyObject * getPySipRequest(const AmSipRequest& r)
{
PYLOCK;
AmSipRequest* req_cpy = new AmSipRequest(r);
return IvrSipRequest_FromPtr(req_cpy);
return IvrSipRequest_FromPtr(new AmSipRequest(r));
}
void IvrDialog::onSipReply(const AmSipReply& r) {
callPyEventHandler("onSipReply","(O)",getPySipReply(r));
PyObject* pyo = getPySipReply(r);
callPyEventHandler("onSipReply","(O)", pyo);
Py_DECREF(pyo);
AmB2BSession::onSipReply(r);
}
void IvrDialog::onSipRequest(const AmSipRequest& r){
callPyEventHandler("onSipRequest","(O)", getPySipRequest(r));
PyObject* pyo = getPySipRequest(r);
callPyEventHandler("onSipRequest","(O)", pyo);
Py_DECREF(pyo);
AmB2BSession::onSipRequest(r);
}

@ -53,8 +53,8 @@ static PyObject* IvrDialogBase_new(PyTypeObject *type, PyObject *args, PyObject
return NULL;
}
// initialize self.invite_req
self->invite_req = IvrSipRequest_FromPtr(self->p_dlg->getInviteReq());
// initialize self.invite_req - AmSipRequest is not owned!
self->invite_req = IvrSipRequest_BorrowedFromPtr(self->p_dlg->getInviteReq());
if(!self->invite_req){
PyErr_Print();
ERROR("IvrDialogBase: while creating IvrSipRequest instance for invite_req\n");

@ -64,6 +64,7 @@ static PyObject* IvrSipReply_new(PyTypeObject *type, PyObject *args, PyObject *k
static void
IvrSipReply_dealloc(IvrSipReply* self)
{
delete self->p_req;
self->ob_type->tp_free((PyObject*)self);
}

@ -30,6 +30,7 @@ typedef struct {
PyObject_HEAD
AmSipRequest* p_req;
bool own_p_req;
} IvrSipRequest;
@ -56,15 +57,50 @@ static PyObject* IvrSipRequest_new(PyTypeObject *type, PyObject *args, PyObject
}
self->p_req = (AmSipRequest*)PyCObject_AsVoidPtr(o_req);
self->own_p_req = true;
}
DBG("IvrSipRequest_new\n");
return (PyObject *)self;
}
static PyObject* IvrSipRequest_newRef(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"ivr_req", NULL};
IvrSipRequest *self;
self = (IvrSipRequest *)type->tp_alloc(type, 0);
if (self != NULL) {
PyObject* o_req = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &o_req)){
Py_DECREF(self);
return NULL;
}
if ((NULL == o_req) || !PyCObject_Check(o_req)){
Py_DECREF(self);
return NULL;
}
self->p_req = (AmSipRequest*)PyCObject_AsVoidPtr(o_req);
self->own_p_req = false;
}
DBG("IvrSipRequest_newRef\n");
return (PyObject *)self;
}
static void
IvrSipRequest_dealloc(IvrSipRequest* self)
{
DBG("IvrSipRequest_dealloc\n");
if(self->own_p_req)
delete self->p_req;
self->ob_type->tp_free((PyObject*)self);
}
@ -204,3 +240,16 @@ PyObject* IvrSipRequest_FromPtr(AmSipRequest* req)
return py_req;
}
PyObject* IvrSipRequest_BorrowedFromPtr(AmSipRequest* req)
{
PyObject* c_req = PyCObject_FromVoidPtr(req,NULL);
PyObject* args = Py_BuildValue("(O)",c_req);
PyObject* py_req = IvrSipRequest_newRef(&IvrSipRequestType,args,NULL);
Py_DECREF(args);
Py_DECREF(c_req);
return py_req;
}

@ -31,5 +31,6 @@
extern PyTypeObject IvrSipRequestType;
PyObject* IvrSipRequest_FromPtr(AmSipRequest* req);
PyObject* IvrSipRequest_BorrowedFromPtr(AmSipRequest* req);
#endif

Loading…
Cancel
Save