[asterisk-commits] rmudgett: branch 1.8 r329333 - /branches/1.8/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 22 16:10:43 CDT 2011


Author: rmudgett
Date: Fri Jul 22 16:10:40 2011
New Revision: 329333

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=329333
Log:
Fix memory leak in an allocation error path of handle_statechange().

* Make use buffer accessor function in handle_statechange() rather than
directly accessing the struct member.

* Make use less redundant loop construct for iterating over hints.

Modified:
    branches/1.8/main/pbx.c

Modified: branches/1.8/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/pbx.c?view=diff&rev=329333&r1=329332&r2=329333
==============================================================================
--- branches/1.8/main/pbx.c (original)
+++ branches/1.8/main/pbx.c Fri Jul 22 16:10:40 2011
@@ -4280,12 +4280,13 @@
 
 	hint_app = ast_str_create(1024);
 	if (!hint_app) {
+		ast_free(sc);
 		return -1;
 	}
 
 	ast_mutex_lock(&context_merge_lock);/* Hold off ast_merge_contexts_and_delete */
 	i = ao2_iterator_init(hints, 0);
-	for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) {
+	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		struct ast_state_cb *state_cb;
 		char *cur, *parse;
 		int state;
@@ -4299,7 +4300,7 @@
 
 		/* Does this hint monitor the device that changed state? */
 		ast_str_set(&hint_app, 0, "%s", ast_get_extension_app(hint->exten));
-		parse = hint_app->str;
+		parse = ast_str_buffer(hint_app);
 		while ((cur = strsep(&parse, "&"))) {
 			if (!strcasecmp(cur, sc->dev)) {
 				/* The hint monitors the device. */
@@ -4321,7 +4322,6 @@
 			sizeof(context_name));
 		ast_copy_string(exten_name, ast_get_extension_name(hint->exten),
 			sizeof(exten_name));
-
 		ast_str_set(&hint_app, 0, "%s", ast_get_extension_app(hint->exten));
 		ao2_unlock(hint);
 
@@ -5917,7 +5917,7 @@
 	ast_cli(a->fd, "\n    -= Registered Asterisk Dial Plan Hints =-\n");
 
 	i = ao2_iterator_init(hints, 0);
-	for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) {
+	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		ao2_lock(hint);
 		if (!hint->exten) {
 			/* The extension has already been destroyed */
@@ -5956,7 +5956,7 @@
 
 	/* walk through all hints */
 	i = ao2_iterator_init(hints, 0);
-	for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) {
+	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		ao2_lock(hint);
 		if (!hint->exten) {
 			/* The extension has already been destroyed */
@@ -6005,7 +6005,7 @@
 	
 	extenlen = strlen(a->argv[3]);
 	i = ao2_iterator_init(hints, 0);
-	for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) {
+	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		ao2_lock(hint);
 		if (!hint->exten) {
 			/* The extension has already been destroyed */
@@ -7247,7 +7247,7 @@
 
 	/* preserve all watchers for hints */
 	i = ao2_iterator_init(hints, AO2_ITERATOR_DONTLOCK);
-	for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) {
+	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		if (ao2_container_count(hint->callbacks)) {
 			ao2_lock(hint);
 			if (!hint->exten) {
@@ -10040,7 +10040,7 @@
 	}
 
 	i = ao2_iterator_init(hints, 0);
-	for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) {
+	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		watchers = ao2_container_count(hint->callbacks);
 		data_hint = ast_data_add_node(data_root, "hint");
 		if (!data_hint) {




More information about the asterisk-commits mailing list