Author: sayer
Date: 2010-02-26 14:23:14 +0100 (Fri, 26 Feb 2010)
New Revision: 1645
Modified:
branches/1.1/apps/ivr/Ivr.cpp
branches/1.1/apps/ivr/IvrDialogBase.cpp
branches/1.1/apps/ivr/IvrSipReply.cpp
branches/1.1/apps/ivr/IvrSipRequest.cpp
branches/1.1/apps/ivr/IvrSipRequest.h
Log:
ivr memory leak and high load crash fixes. backport of r1356 and r1632.
Modified: branches/1.1/apps/ivr/Ivr.cpp
===================================================================
--- branches/1.1/apps/ivr/Ivr.cpp 2010-02-25 16:08:49 UTC (rev 1644)
+++ branches/1.1/apps/ivr/Ivr.cpp 2010-02-26 13:23:14 UTC (rev 1645)
@@ -750,26 +750,31 @@
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;
+ return IvrSipRequest_FromPtr(new AmSipRequest(r));
+}
- AmSipRequest* req_cpy = new AmSipRequest(r);
- return IvrSipRequest_FromPtr(req_cpy);
+void safe_Py_DECREF(PyObject* pyo) {
+ PYLOCK;
+ Py_DECREF(pyo);
}
void IvrDialog::onSipReply(const AmSipReply& r) {
- callPyEventHandler("onSipReply","O",getPySipReply(r));
+ PyObject* pyo = getPySipReply(r);
+ callPyEventHandler("onSipReply","(O)", pyo);
+ safe_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);
+ safe_Py_DECREF(pyo);
AmB2BSession::onSipRequest(r);
}
Modified: branches/1.1/apps/ivr/IvrDialogBase.cpp
===================================================================
--- branches/1.1/apps/ivr/IvrDialogBase.cpp 2010-02-25 16:08:49 UTC (rev
1644)
+++ branches/1.1/apps/ivr/IvrDialogBase.cpp 2010-02-26 13:23:14 UTC (rev
1645)
@@ -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: branches/1.1/apps/ivr/IvrSipReply.cpp
===================================================================
--- branches/1.1/apps/ivr/IvrSipReply.cpp 2010-02-25 16:08:49 UTC (rev
1644)
+++ branches/1.1/apps/ivr/IvrSipReply.cpp 2010-02-26 13:23:14 UTC (rev
1645)
@@ -61,11 +61,12 @@
return (PyObject *)self;
}
-// static void
-// IvrSipRequest_dealloc(IvrSipRequest* self)
-// {
-// self->ob_type->tp_free((PyObject*)self);
-// }
+static void
+IvrSipReply_dealloc(IvrSipReply* self)
+{
+ delete self->p_req;
+ self->ob_type->tp_free((PyObject*)self);
+}
#define def_IvrSipReply_GETTER(getter_name, attr) \
static PyObject* \
@@ -123,7 +124,7 @@
"ivr.IvrSipReply", /*tp_name*/
sizeof(IvrSipReply), /*tp_basicsize*/
0, /*tp_itemsize*/
- 0, /*tp_dealloc*/
+ (destructor)IvrSipReply_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
Modified: branches/1.1/apps/ivr/IvrSipRequest.cpp
===================================================================
--- branches/1.1/apps/ivr/IvrSipRequest.cpp 2010-02-25 16:08:49 UTC (rev
1644)
+++ branches/1.1/apps/ivr/IvrSipRequest.cpp 2010-02-26 13:23:14 UTC (rev
1645)
@@ -30,6 +30,7 @@
PyObject_HEAD
AmSipRequest* p_req;
+ bool own_p_req;
} IvrSipRequest;
@@ -56,18 +57,53 @@
}
self->p_req = (AmSipRequest*)PyCObject_AsVoidPtr(o_req);
+ self->own_p_req = true;
}
DBG("IvrSipRequest_new\n");
return (PyObject *)self;
}
-// static void
-// IvrSipRequest_dealloc(IvrSipRequest* self)
-// {
-// self->ob_type->tp_free((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);
+}
+
#define def_IvrSipRequest_GETTER(getter_name, attr) \
static PyObject* \
getter_name(IvrSipRequest *self, void *closure) \
@@ -155,7 +191,7 @@
"ivr.IvrSipRequest", /*tp_name*/
sizeof(IvrSipRequest), /*tp_basicsize*/
0, /*tp_itemsize*/
- 0, /*tp_dealloc*/
+ (destructor)IvrSipRequest_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
@@ -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: branches/1.1/apps/ivr/IvrSipRequest.h
===================================================================
--- branches/1.1/apps/ivr/IvrSipRequest.h 2010-02-25 16:08:49 UTC (rev
1644)
+++ branches/1.1/apps/ivr/IvrSipRequest.h 2010-02-26 13:23:14 UTC (rev
1645)
@@ -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