[asterisk-commits] russell: branch 1.4 r85649 - /branches/1.4/main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 15 14:22:45 CDT 2007


Author: russell
Date: Mon Oct 15 14:22:45 2007
New Revision: 85649

URL: http://svn.digium.com/view/asterisk?view=rev&rev=85649
Log:
Be pedantic about handling memory allocation failure.

Modified:
    branches/1.4/main/utils.c

Modified: branches/1.4/main/utils.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/utils.c?view=diff&rev=85649&r1=85648&r2=85649
==============================================================================
--- branches/1.4/main/utils.c (original)
+++ branches/1.4/main/utils.c Mon Oct 15 14:22:45 2007
@@ -720,13 +720,16 @@
 				"=== <file> <line num> <function> <lock name> <lock addr> (times locked)\n"
 				"===\n");
 
+	if (!str)
+		return RESULT_FAILURE;
+
 	pthread_mutex_lock(&lock_infos_lock.mutex);
 	AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
 		int i;
 		ast_dynamic_str_append(&str, 0, "=== Thread ID: %u (%s)\n", (int) lock_info->thread_id,
 			lock_info->thread_name);
 		pthread_mutex_lock(&lock_info->lock);
-		for (i = 0; i < lock_info->num_locks; i++) {
+		for (i = 0; str && i < lock_info->num_locks; i++) {
 			ast_dynamic_str_append(&str, 0, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n", 
 				lock_info->locks[i].pending > 0 ? "Waiting for " : 
 					lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
@@ -738,13 +741,23 @@
 				lock_info->locks[i].times_locked);
 		}
 		pthread_mutex_unlock(&lock_info->lock);
+		if (!str)
+			break;
 		ast_dynamic_str_append(&str, 0, "=== -------------------------------------------------------------------\n"
 		            "===\n");
+		if (!str)
+			break;
 	}
 	pthread_mutex_unlock(&lock_infos_lock.mutex);
+
+	if (!str)
+		return RESULT_FAILURE;
 
 	ast_dynamic_str_append(&str, 0, "=======================================================================\n"
 	            "\n");
+
+	if (!str)
+		return RESULT_FAILURE;
 
 	ast_cli(fd, "%s", str->str);
 




More information about the asterisk-commits mailing list