Index: pjproject/trunk/pjmedia/src/pjmedia/conference.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/conference.c	(revision 2581)
+++ pjproject/trunk/pjmedia/src/pjmedia/conference.c	(revision 2582)
@@ -888,6 +888,12 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
+    pj_mutex_lock(conf->mutex);
+
     /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
+    conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     conf_port = conf->ports[slot];
@@ -898,4 +904,6 @@
     if (rx != PJMEDIA_PORT_NO_CHANGE)
 	conf_port->rx_setting = rx;
+
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
@@ -919,8 +927,4 @@
 		     sink_slot<conf->max_ports, PJ_EINVAL);
 
-    /* Ports must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL);
-    PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL);
-
     /* For now, level MUST be zero. */
     PJ_ASSERT_RETURN(level == 0, PJ_EINVAL);
@@ -928,6 +932,11 @@
     pj_mutex_lock(conf->mutex);
 
+    /* Ports must be valid. */
     src_port = conf->ports[src_slot];
     dst_port = conf->ports[sink_slot];
+    if (!src_port || !dst_port) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Check if connection has been made */
@@ -981,12 +990,13 @@
 		     sink_slot<conf->max_ports, PJ_EINVAL);
 
+    pj_mutex_lock(conf->mutex);
+
     /* Ports must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL);
-    PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL);
-
-    pj_mutex_lock(conf->mutex);
-
     src_port = conf->ports[src_slot];
     dst_port = conf->ports[sink_slot];
+    if (!src_port || !dst_port) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Check if connection has been made */
@@ -1059,7 +1069,4 @@
     PJ_ASSERT_RETURN(conf && port < conf->max_ports, PJ_EINVAL);
 
-    /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[port] != NULL, PJ_EINVAL);
-
     /* Suspend the sound devices.
      * Don't want to remove port while port is being accessed by sound
@@ -1069,5 +1076,11 @@
     pj_mutex_lock(conf->mutex);
 
+    /* Port must be valid. */
     conf_port = conf->ports[port];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
+
     conf_port->tx_setting = PJMEDIA_PORT_DISABLE;
     conf_port->rx_setting = PJMEDIA_PORT_DISABLE;
@@ -1138,4 +1151,7 @@
     PJ_ASSERT_RETURN(conf && p_count && ports, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     for (i=0; i<conf->max_ports && count<*p_count; ++i) {
 	if (!conf->ports[i])
@@ -1145,4 +1161,7 @@
     }
 
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
+
     *p_count = count;
     return PJ_SUCCESS;
@@ -1161,8 +1180,13 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     info->slot = slot;
@@ -1180,4 +1204,7 @@
     info->rx_adj_level = conf_port->rx_adj_level - NORMAL_LEVEL;
 
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
+
     return PJ_SUCCESS;
 }
@@ -1192,4 +1219,7 @@
     PJ_ASSERT_RETURN(conf && size && info, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     for (i=0; i<conf->max_ports && count<*size; ++i) {
 	if (!conf->ports[i])
@@ -1199,4 +1229,7 @@
 	++count;
     }
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     *size = count;
@@ -1218,8 +1251,13 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     if (tx_level != NULL) {
@@ -1229,4 +1267,7 @@
     if (rx_level != NULL) 
 	*rx_level = conf_port->rx_level;
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
@@ -1246,7 +1287,4 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
-    /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     /* Value must be from -128 to +127 */
     /* Disabled, you can put more than +127, at your own risk: 
@@ -1255,8 +1293,19 @@
     PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
+    /* Port must be valid. */
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Set normalized adjustment level. */
     conf_port->rx_adj_level = adj_level + NORMAL_LEVEL;
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
@@ -1276,7 +1325,4 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
-    /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     /* Value must be from -128 to +127 */
     /* Disabled, you can put more than +127,, at your own risk:
@@ -1285,8 +1331,19 @@
     PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
+    /* Port must be valid. */
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Set normalized adjustment level. */
     conf_port->tx_adj_level = adj_level + NORMAL_LEVEL;
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
