Author: sayer
Date: 2009-04-24 16:33:34 +0200 (Fri, 24 Apr 2009)
New Revision: 1356
Modified:
trunk/apps/ivr/Ivr.cpp
trunk/apps/ivr/IvrDialogBase.cpp
trunk/apps/ivr/IvrSipReply.cpp
trunk/apps/ivr/IvrSipRequest.cpp
trunk/apps/ivr/IvrSipRequest.h
Log:
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
Modified: trunk/apps/ivr/Ivr.cpp
===================================================================
--- trunk/apps/ivr/Ivr.cpp 2009-04-23 14:13:32 UTC (rev 1355)
+++ trunk/apps/ivr/Ivr.cpp 2009-04-24 14:33:34 UTC (rev 1356)
@@ -750,26 +750,26 @@
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);
}
Modified: trunk/apps/ivr/IvrDialogBase.cpp
===================================================================
--- trunk/apps/ivr/IvrDialogBase.cpp 2009-04-23 14:13:32 UTC (rev 1355)
+++ trunk/apps/ivr/IvrDialogBase.cpp 2009-04-24 14:33:34 UTC (rev 1356)
@@ -53,8 +53,8 @@
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");
Modified: trunk/apps/ivr/IvrSipReply.cpp
===================================================================
--- trunk/apps/ivr/IvrSipReply.cpp 2009-04-23 14:13:32 UTC (rev 1355)
+++ trunk/apps/ivr/IvrSipReply.cpp 2009-04-24 14:33:34 UTC (rev 1356)
@@ -64,6 +64,7 @@
static void
IvrSipReply_dealloc(IvrSipReply* self)
{
+ delete self->p_req;
self->ob_type->tp_free((PyObject*)self);
}
Modified: trunk/apps/ivr/IvrSipRequest.cpp
===================================================================
--- trunk/apps/ivr/IvrSipRequest.cpp 2009-04-23 14:13:32 UTC (rev 1355)
+++ trunk/apps/ivr/IvrSipRequest.cpp 2009-04-24 14:33:34 UTC (rev 1356)
@@ -30,6 +30,7 @@
PyObject_HEAD
AmSipRequest* p_req;
+ bool own_p_req;
} IvrSipRequest;
@@ -56,15 +57,50 @@
}
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 @@
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;
+}
Modified: trunk/apps/ivr/IvrSipRequest.h
===================================================================
--- trunk/apps/ivr/IvrSipRequest.h 2009-04-23 14:13:32 UTC (rev 1355)
+++ trunk/apps/ivr/IvrSipRequest.h 2009-04-24 14:33:34 UTC (rev 1356)
@@ -31,5 +31,6 @@
extern PyTypeObject IvrSipRequestType;
PyObject* IvrSipRequest_FromPtr(AmSipRequest* req);
+PyObject* IvrSipRequest_BorrowedFromPtr(AmSipRequest* req);
#endif
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev