Index: pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py
===================================================================
--- pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py	(revision 925)
+++ pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py	(revision 926)
@@ -73,4 +73,18 @@
 		write_log(3, "Account successfully (un)registered")
 
+
+def on_buddy_state(buddy_id):
+	write_log(3, "On Buddy state called")
+	buddy_info = py_pjsua.buddy_get_info(buddy_id)
+	if buddy_info.status != 0 and buddy_info.status != 200:
+		write_log(3, "Status of " + `buddy_info.uri` + " is " + `buddy_info.status_text`)
+	else:
+		write_log(3, "Status : " + `buddy_info.status`)
+		
+def on_pager(call_id, strfrom, strto, contact, mime_type, text):
+	write_log(3, "MESSAGE from " + `strfrom` + " : " + `text`)
+	
+def on_pager_status(call_id, strto, body, user_data, status, reason):
+	write_log(3, "MESSAGE to " + `strto` + " status " + `status` + " reason " + `reason`)
 
 # Utility: display PJ error and exit
@@ -118,4 +132,8 @@
 	ua_cfg.cb.on_reg_state = on_reg_state
 	ua_cfg.cb.on_call_state = on_call_state
+	ua_cfg.cb.on_buddy_state = on_buddy_state
+	ua_cfg.cb.on_pager = on_pager
+	ua_cfg.cb.on_pager_status = on_pager_status
+	
 
 	# Create and initialize media config
Index: pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c	(revision 925)
+++ pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c	(revision 926)
@@ -24,4 +24,5 @@
 #define POOL_SIZE    4000
 #define SND_DEV_NUM  64
+#define SND_NAME_LEN  64
 
 /* LIB BASE */
@@ -404,5 +405,5 @@
 /*
  * cb_on_pager
- * * declares method on_pager for callback struct
+ * declares method on_pager for callback struct
  */
 static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
@@ -3161,5 +3162,8 @@
     obj->stun_srv2 = 
         PyString_FromStringAndSize(cfg->stun_srv2.ptr, cfg->stun_srv2.slen);
-    free(cfg);
+    if (cfg != NULL)
+    {
+        free(cfg);
+    }
     Py_INCREF(Py_None);
     return Py_None;
@@ -5025,5 +5029,5 @@
     int status;
     int acc_id;
-    pj_str_t * mime_type;
+    pj_str_t * mime_type, tmp_mime_type;
     pj_str_t to, content;
     PyObject * st;
@@ -5043,9 +5047,9 @@
         return NULL;
     }
-    if (smt != NULL)
-    {
-        mime_type = (pj_str_t *)malloc(sizeof(pj_str_t));
-        mime_type->ptr = PyString_AsString(smt);
-        mime_type->slen = strlen(PyString_AsString(smt));
+    if (smt != Py_None)
+    {
+        mime_type = &tmp_mime_type;
+        tmp_mime_type.ptr = PyString_AsString(smt);
+        tmp_mime_type.slen = strlen(PyString_AsString(smt));
     } else {
         mime_type = NULL;
@@ -5076,8 +5080,5 @@
 			&content, NULL, NULL);	
     }
-    if (mime_type != NULL)
-    {
-        free(mime_type);
-    }
+    
     return Py_BuildValue("i",status);
 }
@@ -5511,5 +5512,5 @@
     unsigned  output_count;
     unsigned  default_samples_per_sec;    
-    PyListObject * name;
+    PyObject * name;
 
 } pjmedia_snd_dev_info_Object;
@@ -5539,5 +5540,5 @@
     if (self != NULL)
     {
-        self->name = (PyListObject *)PyList_New(SND_DEV_NUM);
+        self->name = PyString_FromString("");
         if (self->name == NULL)
     	{
@@ -6376,4 +6377,6 @@
         int ret;
         int j;
+        char * str;
+	
         pjmedia_snd_dev_info_Object * obj;
         obj = (pjmedia_snd_dev_info_Object *)pjmedia_snd_dev_info_new
@@ -6382,14 +6385,12 @@
         obj->input_count = info[i].input_count;
         obj->output_count = info[i].output_count;
-        for (j = 0; j < SND_DEV_NUM; j++)
+        str = (char *)malloc(SND_NAME_LEN * sizeof(char));
+        memset(str, 0, SND_NAME_LEN);
+        for (j = 0; j < SND_NAME_LEN; j++)
 	{
-            PyObject * ostr;
-            char * str;
-            str = (char *)malloc(sizeof(char));
-            str[0] = info[i].name[j];
-            ostr = PyString_FromStringAndSize(str,1);
-            PyList_SetItem((PyObject *)obj->name, j, ostr);
-            free(str);
+            str[j] = info[i].name[j];
 	}
+        obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
+        free(str);
         ret = PyList_SetItem(list, i, (PyObject *)obj);
         if (ret == -1) 
@@ -7448,5 +7449,5 @@
     int status;
     int call_id;
-    pj_str_t * reason;
+    pj_str_t * reason, tmp_reason;
     PyObject * sr;
     unsigned code;
@@ -7464,7 +7465,7 @@
         reason = NULL;
     } else {
-	reason = (pj_str_t *)malloc(sizeof(pj_str_t));
-        reason->ptr = PyString_AsString(sr);
-        reason->slen = strlen(PyString_AsString(sr));
+	reason = &tmp_reason;
+        tmp_reason.ptr = PyString_AsString(sr);
+        tmp_reason.slen = strlen(PyString_AsString(sr));
     }
     if (omdObj != Py_None) 
@@ -7486,8 +7487,5 @@
         status = pjsua_call_answer(call_id, code, reason, NULL);	
     }
-    if (reason != NULL)
-    {
-        free(reason);
-    }
+    
     return Py_BuildValue("i",status);
 }
@@ -7501,5 +7499,5 @@
     int status;
     int call_id;
-    pj_str_t * reason;
+    pj_str_t * reason, tmp_reason;
     PyObject * sr;
     unsigned code;
@@ -7517,7 +7515,7 @@
         reason = NULL;
     } else {
-        reason = (pj_str_t *)malloc(sizeof(pj_str_t));
-        reason->ptr = PyString_AsString(sr);
-        reason->slen = strlen(PyString_AsString(sr));
+        reason = &tmp_reason;
+        tmp_reason.ptr = PyString_AsString(sr);
+        tmp_reason.slen = strlen(PyString_AsString(sr));
     }
     if (omdObj != Py_None) 
@@ -7536,8 +7534,5 @@
         status = pjsua_call_hangup(call_id, code, reason, NULL);	
     }
-    if (reason != NULL)
-    {
-        free(reason);
-    }
+    
     return Py_BuildValue("i",status);
 }
@@ -7728,5 +7723,5 @@
     int call_id;
     pj_str_t content;
-    pj_str_t * mime_type;
+    pj_str_t * mime_type, tmp_mime_type;
     PyObject * sm;
     PyObject * sc;
@@ -7746,7 +7741,7 @@
         mime_type = NULL;
     } else {
-        mime_type = (pj_str_t *)malloc(sizeof(pj_str_t));
-        mime_type->ptr = PyString_AsString(sm);
-        mime_type->slen = strlen(PyString_AsString(sm));
+        mime_type = &tmp_mime_type;
+        tmp_mime_type.ptr = PyString_AsString(sm);
+        tmp_mime_type.slen = strlen(PyString_AsString(sm));
     }
     content.ptr = PyString_AsString(sc);
@@ -7770,8 +7765,5 @@
 			(call_id, mime_type, &content, NULL, (void *)user_data);	
     }
-    if (mime_type != NULL)
-    {
-        free(mime_type);
-    }
+    
     return Py_BuildValue("i",status);
 }
