[asterisk-commits] rmudgett: trunk r392335 - in /trunk: apps/confbridge/ include/asterisk/ main/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 20 12:21:43 CDT 2013


Author: rmudgett
Date: Thu Jun 20 12:21:40 2013
New Revision: 392335

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392335
Log:
Fix potential bridge hook resource leak if the hook install fails.

Modified:
    trunk/apps/confbridge/conf_config_parser.c
    trunk/include/asterisk/bridging_features.h
    trunk/main/bridging.c
    trunk/main/features.c
    trunk/res/parking/parking_bridge_features.c

Modified: trunk/apps/confbridge/conf_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/confbridge/conf_config_parser.c?view=diff&rev=392335&r1=392334&r2=392335
==============================================================================
--- trunk/apps/confbridge/conf_config_parser.c (original)
+++ trunk/apps/confbridge/conf_config_parser.c Thu Jun 20 12:21:40 2013
@@ -2161,8 +2161,10 @@
 		ao2_ref(menu, +1);
 		pvt->menu = menu;
 
-		ast_bridge_dtmf_hook(&user->features, pvt->menu_entry.dtmf, menu_hook_callback,
-			pvt, menu_hook_destroy, 0);
+		if (ast_bridge_dtmf_hook(&user->features, pvt->menu_entry.dtmf,
+			menu_hook_callback, pvt, menu_hook_destroy, 0)) {
+			menu_hook_destroy(pvt);
+		}
 	}
 
 	ao2_unlock(menu);

Modified: trunk/include/asterisk/bridging_features.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bridging_features.h?view=diff&rev=392335&r1=392334&r2=392335
==============================================================================
--- trunk/include/asterisk/bridging_features.h (original)
+++ trunk/include/asterisk/bridging_features.h Thu Jun 20 12:21:40 2013
@@ -390,7 +390,7 @@
  * \param remove_flags Dictates what situations the hook should be removed.
  *
  * \retval 0 on success
- * \retval -1 on failure
+ * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
  *
  * Example usage:
  *
@@ -420,7 +420,7 @@
  * \param remove_flags Dictates what situations the hook should be removed.
  *
  * \retval 0 on success
- * \retval -1 on failure
+ * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
  *
  * Example usage:
  *
@@ -450,7 +450,7 @@
  * \param remove_flags Dictates what situations the hook should be removed.
  *
  * \retval 0 on success
- * \retval -1 on failure
+ * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
  *
  * Example usage:
  *
@@ -481,7 +481,7 @@
  * \param remove_flags Dictates what situations the hook should be removed.
  *
  * \retval 0 on success
- * \retval -1 on failure
+ * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
  *
  * Example usage:
  *
@@ -503,7 +503,7 @@
 	enum ast_bridge_hook_remove_flags remove_flags);
 
 /*!
- * \brief attach an interval hook to a bridge features structure
+ * \brief Attach an interval hook to a bridge features structure
  *
  * \param features Bridge features structure
  * \param interval The interval that the hook should execute at in milliseconds
@@ -513,7 +513,7 @@
  * \param remove_flags Dictates what situations the hook should be removed.
  *
  * \retval 0 on success
- * \retval -1 on failure
+ * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
  *
  * \code
  * struct ast_bridge_features features;

Modified: trunk/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/bridging.c?view=diff&rev=392335&r1=392334&r2=392335
==============================================================================
--- trunk/main/bridging.c (original)
+++ trunk/main/bridging.c Thu Jun 20 12:21:40 2013
@@ -4893,6 +4893,15 @@
 
 	/* Once done we put it in the container. */
 	res = ao2_link(features->dtmf_hooks, hook) ? 0 : -1;
+	if (res) {
+		/*
+		 * Could not link the hook into the container.
+		 *
+		 * Remove the hook_pvt destructor call from the hook since we
+		 * are returning failure to install the hook.
+		 */
+		hook->destructor = NULL;
+	}
 	ao2_ref(hook, -1);
 
 	return res;
@@ -4916,6 +4925,15 @@
 
 	/* Once done we put it in the container. */
 	res = ao2_link(features->hangup_hooks, hook) ? 0 : -1;
+	if (res) {
+		/*
+		 * Could not link the hook into the container.
+		 *
+		 * Remove the hook_pvt destructor call from the hook since we
+		 * are returning failure to install the hook.
+		 */
+		hook->destructor = NULL;
+	}
 	ao2_ref(hook, -1);
 
 	return res;
@@ -4939,6 +4957,15 @@
 
 	/* Once done we put it in the container. */
 	res = ao2_link(features->join_hooks, hook) ? 0 : -1;
+	if (res) {
+		/*
+		 * Could not link the hook into the container.
+		 *
+		 * Remove the hook_pvt destructor call from the hook since we
+		 * are returning failure to install the hook.
+		 */
+		hook->destructor = NULL;
+	}
 	ao2_ref(hook, -1);
 
 	return res;
@@ -4962,6 +4989,15 @@
 
 	/* Once done we put it in the container. */
 	res = ao2_link(features->leave_hooks, hook) ? 0 : -1;
+	if (res) {
+		/*
+		 * Could not link the hook into the container.
+		 *
+		 * Remove the hook_pvt destructor call from the hook since we
+		 * are returning failure to install the hook.
+		 */
+		hook->destructor = NULL;
+	}
 	ao2_ref(hook, -1);
 
 	return res;
@@ -5013,11 +5049,17 @@
 		hook, hook->parms.timer.interval, features);
 	ast_heap_wrlock(features->interval_hooks);
 	res = ast_heap_push(features->interval_hooks, hook);
+	ast_heap_unlock(features->interval_hooks);
 	if (res) {
-		/* Could not push the hook onto the heap. */
+		/*
+		 * Could not push the hook into the heap
+		 *
+		 * Remove the hook_pvt destructor call from the hook since we
+		 * are returning failure to install the hook.
+		 */
+		hook->destructor = NULL;
 		ao2_ref(hook, -1);
 	}
-	ast_heap_unlock(features->interval_hooks);
 
 	return res ? -1 : 0;
 }

Modified: trunk/main/features.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/features.c?view=diff&rev=392335&r1=392334&r2=392335
==============================================================================
--- trunk/main/features.c (original)
+++ trunk/main/features.c Thu Jun 20 12:21:40 2013
@@ -3415,6 +3415,7 @@
 	size_t len_moh = ast_strlen_zero(moh_class) ? 0 : strlen(moh_class) + 1;
 	size_t len_feature = strlen(feature_name) + 1;
 	size_t len_data = sizeof(*hook_data) + len_name + len_args + len_moh + len_feature;
+	int res;
 
 	/* Fill in application run hook data. */
 	hook_data = ast_malloc(len_data);
@@ -3434,8 +3435,12 @@
 	}
 	strcpy(&hook_data->app_name[hook_data->feature_offset], feature_name);/* Safe */
 
-	return ast_bridge_dtmf_hook(features, dtmf, dynamic_dtmf_hook_trip, hook_data,
+	res = ast_bridge_dtmf_hook(features, dtmf, dynamic_dtmf_hook_trip, hook_data,
 		ast_free_ptr, AST_BRIDGE_HOOK_REMOVE_ON_PULL);
+	if (res) {
+		ast_free(hook_data);
+	}
+	return res;
 }
 
 static int setup_dynamic_feature(void *obj, void *arg, void *data, int flags)

Modified: trunk/res/parking/parking_bridge_features.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/parking/parking_bridge_features.c?view=diff&rev=392335&r1=392334&r2=392335
==============================================================================
--- trunk/res/parking/parking_bridge_features.c (original)
+++ trunk/res/parking/parking_bridge_features.c Thu Jun 20 12:21:40 2013
@@ -542,6 +542,7 @@
 	if (ast_bridge_interval_hook(features, time_limit,
 		parking_duration_callback, user, parking_duration_cb_destroyer, AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
 		ast_log(LOG_ERROR, "Failed to apply duration limits to the parking call.\n");
+		ao2_ref(user, -1);
 	}
 }
 




More information about the asterisk-commits mailing list