[asterisk-commits] rmudgett: trunk r394623 - in /trunk: addons/ apps/ include/asterisk/ main/ te...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 17 17:30:32 CDT 2013


Author: rmudgett
Date: Wed Jul 17 17:30:28 2013
New Revision: 394623

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394623
Log:
Change ast_hangup() to return void and be NULL safe.

Since ast_hangup() is effectively a channel destructor, it should be a
void function.

* Make the few silly callers checking the return value no longer do so.
Only the CDR and CEL unit tests checked the return value.

* Make all callers take advantage of the NULL safe change and remove the
NULL check before the call.

Modified:
    trunk/addons/chan_mobile.c
    trunk/apps/app_meetme.c
    trunk/apps/app_voicemail.c
    trunk/include/asterisk/channel.h
    trunk/main/channel.c
    trunk/main/dial.c
    trunk/main/features.c
    trunk/tests/test_app.c
    trunk/tests/test_cdr.c
    trunk/tests/test_cel.c
    trunk/tests/test_stasis_endpoints.c
    trunk/tests/test_voicemail_api.c

Modified: trunk/addons/chan_mobile.c
URL: http://svnview.digium.com/svn/asterisk/trunk/addons/chan_mobile.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/addons/chan_mobile.c (original)
+++ trunk/addons/chan_mobile.c Wed Jul 17 17:30:28 2013
@@ -1339,9 +1339,7 @@
 
 static int mbl_ast_hangup(struct mbl_pvt *pvt)
 {
-	if (pvt->owner) {
-		ast_hangup(pvt->owner);
-	}
+	ast_hangup(pvt->owner);
 	return 0;
 }
 

Modified: trunk/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_meetme.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Wed Jul 17 17:30:28 2013
@@ -2368,10 +2368,8 @@
 
 	if (conf->origframe)
 		ast_frfree(conf->origframe);
-	if (conf->lchan)
-		ast_hangup(conf->lchan);
-	if (conf->chan)
-		ast_hangup(conf->chan);
+	ast_hangup(conf->lchan);
+	ast_hangup(conf->chan);
 	if (conf->fd >= 0)
 		close(conf->fd);
 	if (conf->recordingfilename) {

Modified: trunk/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Wed Jul 17 17:30:28 2013
@@ -13780,9 +13780,7 @@
 
 exit_vmsayname_test:
 
-	if (test_channel1) {
-		ast_hangup(test_channel1);
-	}
+	ast_hangup(test_channel1);
 
 	return res ? AST_TEST_FAIL : AST_TEST_PASS;
 }

Modified: trunk/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Wed Jul 17 17:30:28 2013
@@ -1427,9 +1427,9 @@
  * performs all stream stopping, etc, on the channel that needs to end.
  * chan is no longer valid after this call.
  * \param chan channel to hang up
- * \return Returns 0 on success, -1 on failure.
- */
-int ast_hangup(struct ast_channel *chan);
+ * \return Nothing
+ */
+void ast_hangup(struct ast_channel *chan);
 
 /*!
  * \brief Softly hangup up a channel

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Wed Jul 17 17:30:28 2013
@@ -2640,8 +2640,13 @@
 }
 
 /*! \brief Hangup a channel */
-int ast_hangup(struct ast_channel *chan)
-{
+void ast_hangup(struct ast_channel *chan)
+{
+	/* Be NULL safe for RAII_VAR() usage. */
+	if (!chan) {
+		return;
+	}
+
 	ast_autoservice_stop(chan);
 
 	ast_channel_lock(chan);
@@ -2669,7 +2674,7 @@
 		ast_set_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE);
 		destroy_hooks(chan);
 		ast_channel_unlock(chan);
-		return 0;
+		return;
 	}
 
 	/* Mark as a zombie so a masquerade cannot be setup on this channel. */
@@ -2733,8 +2738,6 @@
 	ast_cc_offer(chan);
 
 	ast_channel_unref(chan);
-
-	return 0;
 }
 
 int ast_raw_answer(struct ast_channel *chan)

Modified: trunk/main/dial.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/dial.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/main/dial.c (original)
+++ trunk/main/dial.c Wed Jul 17 17:30:28 2013
@@ -942,10 +942,8 @@
 
 	AST_LIST_LOCK(&dial->channels);
 	AST_LIST_TRAVERSE(&dial->channels, channel, list) {
-		if (channel->owner) {
-			ast_hangup(channel->owner);
-			channel->owner = NULL;
-		}
+		ast_hangup(channel->owner);
+		channel->owner = NULL;
 	}
 	AST_LIST_UNLOCK(&dial->channels);
 
@@ -976,11 +974,11 @@
 				option_types[i].disable(channel->options[i]);
 			channel->options[i] = NULL;
 		}
+
 		/* Hang up channel if need be */
-		if (channel->owner) {
-			ast_hangup(channel->owner);
-			channel->owner = NULL;
-		}
+		ast_hangup(channel->owner);
+		channel->owner = NULL;
+
 		/* Free structure */
 		ast_free(channel->tech);
 		ast_free(channel->device);

Modified: trunk/main/features.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/features.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/main/features.c (original)
+++ trunk/main/features.c Wed Jul 17 17:30:28 2013
@@ -2547,9 +2547,7 @@
 		 * is up, hang it up as it has no one to talk to.
 		 */
 		ast_debug(1, "Everyone is hungup.\n");
-		if (newchan) {
-			ast_hangup(newchan);
-		}
+		ast_hangup(newchan);
 		ast_party_connected_line_free(&connected_line);
 		return -1;
 	}
@@ -5586,18 +5584,14 @@
 	/* find the real channel */
 	parked_chan = ast_channel_get_by_name("TestChannel1");
 	if (unpark_test_channel(parked_chan, &args)) {
-		if (parked_chan) {
-			ast_hangup(parked_chan);
-		}
+		ast_hangup(parked_chan);
 		res = -1;
 	}
 
 
 exit_features_test:
 
-	if (test_channel1) {
-		ast_hangup(test_channel1);
-	}
+	ast_hangup(test_channel1);
 
 	force_reload_load = 1;
 	ast_features_reload();

Modified: trunk/tests/test_app.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_app.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/tests/test_app.c (original)
+++ trunk/tests/test_app.c Wed Jul 17 17:30:28 2013
@@ -212,18 +212,10 @@
 	}
 
 exit_group_test:
-	if (test_channel1) {
-		ast_hangup(test_channel1);
-	}
-	if (test_channel2) {
-		ast_hangup(test_channel2);
-	}
-	if (test_channel3) {
-		ast_hangup(test_channel3);
-	}
-	if (test_channel4) {
-		ast_hangup(test_channel4);
-	}
+	ast_hangup(test_channel1);
+	ast_hangup(test_channel2);
+	ast_hangup(test_channel3);
+	ast_hangup(test_channel4);
 	return res;
 }
 

Modified: trunk/tests/test_cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_cdr.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/tests/test_cdr.c (original)
+++ trunk/tests/test_cdr.c Wed Jul 17 17:30:28 2013
@@ -278,11 +278,12 @@
 	} while (0)
 
 /*! \brief Hang up a test channel safely */
-#define HANGUP_CHANNEL(channel, cause) do { \
-	ast_channel_hangupcause_set((channel), (cause)); \
-	if (!ast_hangup((channel))) { \
+#define HANGUP_CHANNEL(channel, cause) \
+	do { \
+		ast_channel_hangupcause_set((channel), (cause)); \
+		ast_hangup(channel); \
 		channel = NULL; \
-	} } while (0)
+	} while (0)
 
 static enum ast_test_result_state verify_mock_cdr_record(struct ast_test *test, struct ast_cdr *expected, int record)
 {
@@ -2201,9 +2202,8 @@
 
 	/* Hang up and verify */
 	ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL);
-	if (!ast_hangup(chan)) {
-		chan = NULL;
-	}
+	ast_hangup(chan);
+	chan = NULL;
 	result = verify_mock_cdr_record(test, expected, 3);
 
 	return result;
@@ -2272,9 +2272,8 @@
 	ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
 
 	ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL);
-	if (!ast_hangup(chan)) {
-		chan = NULL;
-	}
+	ast_hangup(chan);
+	chan = NULL;
 	result = verify_mock_cdr_record(test, &expected, 1);
 
 	return result;
@@ -2395,9 +2394,8 @@
 	ast_test_validate(test, strcmp(fork_answer_time, answer_time) != 0);
 
 	ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL);
-	if (!ast_hangup(chan)) {
-		chan = NULL;
-	}
+	ast_hangup(chan);
+	chan = NULL;
 	result = verify_mock_cdr_record(test, expected, 3);
 
 	return result;

Modified: trunk/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_cel.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/tests/test_cel.c (original)
+++ trunk/tests/test_cel.c Wed Jul 17 17:30:28 2013
@@ -139,23 +139,17 @@
 	} while (0)
 
 /*! \brief Hang up a test channel safely */
-#define HANGUP_CHANNEL(channel, cause, hangup_extra) do { \
-	ast_channel_hangupcause_set((channel), (cause)); \
-	ao2_ref(channel, +1); \
-	if (!ast_hangup((channel))) { \
+#define HANGUP_CHANNEL(channel, cause, hangup_extra) \
+	do { \
+		ast_channel_hangupcause_set((channel), (cause)); \
+		ao2_ref(channel, +1); \
+		ast_hangup(channel); \
 		APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, hangup_extra, NULL); \
 		APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL, NULL); \
 		ao2_cleanup(stasis_cache_get_extended(ast_channel_topic_all_cached(), \
 			ast_channel_snapshot_type(), ast_channel_uniqueid(channel), 1)); \
 		ao2_cleanup(channel); \
 		channel = NULL; \
-	} else { \
-		APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, hangup_extra, NULL); \
-		APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL, NULL); \
-		ao2_cleanup(stasis_cache_get_extended(ast_channel_topic_all_cached(), \
-			ast_channel_snapshot_type(), ast_channel_uniqueid(channel), 1)); \
-		ao2_cleanup(channel); \
-	} \
 	} while (0)
 
 static int append_expected_event(

Modified: trunk/tests/test_stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_stasis_endpoints.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/tests/test_stasis_endpoints.c (original)
+++ trunk/tests/test_stasis_endpoints.c Wed Jul 17 17:30:28 2013
@@ -45,14 +45,6 @@
 
 static const char *test_category = "/stasis/endpoints/";
 
-static void safe_channel_hangup(struct ast_channel *chan)
-{
-	if (!chan) {
-		return;
-	}
-	ast_hangup(chan);
-}
-
 /*! \brief Message matcher looking for cache update messages */
 static int cache_update(struct stasis_message *msg, const void *data) {
 	struct stasis_cache_update *update;
@@ -79,7 +71,7 @@
 AST_TEST_DEFINE(state_changes)
 {
 	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
-	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
+	RAII_VAR(struct ast_channel *, chan, NULL, ast_hangup);
 	RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
 	struct stasis_message *msg;
@@ -135,7 +127,7 @@
 AST_TEST_DEFINE(cache_clear)
 {
 	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
-	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
+	RAII_VAR(struct ast_channel *, chan, NULL, ast_hangup);
 	RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
 	struct stasis_message *msg;
@@ -211,7 +203,7 @@
 AST_TEST_DEFINE(channel_messages)
 {
 	RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
-	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_hangup);
+	RAII_VAR(struct ast_channel *, chan, NULL, ast_hangup);
 	RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
 	struct stasis_message *msg;
@@ -261,7 +253,7 @@
 	actual_snapshot = stasis_message_data(msg);
 	ast_test_validate(test, 1 == actual_snapshot->num_channels);
 
-	safe_channel_hangup(chan);
+	ast_hangup(chan);
 	chan = NULL;
 
 	actual_count = stasis_message_sink_wait_for_count(sink, 5,

Modified: trunk/tests/test_voicemail_api.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_voicemail_api.c?view=diff&rev=394623&r1=394622&r2=394623
==============================================================================
--- trunk/tests/test_voicemail_api.c (original)
+++ trunk/tests/test_voicemail_api.c Wed Jul 17 17:30:28 2013
@@ -229,9 +229,7 @@
 #define VM_API_PLAYBACK_MESSAGE(channel, mailbox, context, folder, message, callback_fn) do { \
 	if (ast_vm_msg_play((channel), (mailbox), (context), (folder), (message), (callback_fn))) { \
 		ast_test_status_update(test, "Failed nominal playback message test\n"); \
-		if (test_channel) { \
-			ast_hangup(test_channel); \
-		} \
+		ast_hangup(test_channel); \
 		VM_API_TEST_CLEANUP; \
 		return AST_TEST_FAIL; \
 	} } while (0)
@@ -241,9 +239,7 @@
 #define VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(channel, mailbox, context, folder, message, callback_fn) do { \
 	if (!ast_vm_msg_play((channel), (mailbox), (context), (folder), (message), (callback_fn))) { \
 		ast_test_status_update(test, "Succeeded in playing back of message when expected result was to fail\n"); \
-		if (test_channel) { \
-			ast_hangup(test_channel); \
-		} \
+		ast_hangup(test_channel); \
 		VM_API_TEST_CLEANUP; \
 		return AST_TEST_FAIL; \
 	} } while (0)
@@ -1322,9 +1318,7 @@
 	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
-	if (test_channel) {
-		ast_hangup(test_channel);
-	}
+	ast_hangup(test_channel);
 	VM_API_TEST_CLEANUP;
 
 	return AST_TEST_PASS;
@@ -1382,9 +1376,7 @@
 
 	ast_test_status_update(test, "Playing back message with NULL message specifier\n");
 	VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "INBOX", NULL, NULL);
-	if (test_channel) {
-		ast_hangup(test_channel);
-	}
+	ast_hangup(test_channel);
 	VM_API_TEST_CLEANUP;
 
 	return AST_TEST_PASS;




More information about the asterisk-commits mailing list