]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Be pedantic about handling memory allocation failure.
authorRussell Bryant <russell@russellbryant.com>
Mon, 15 Oct 2007 19:22:45 +0000 (19:22 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 15 Oct 2007 19:22:45 +0000 (19:22 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@85649 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/utils.c

index 8c2c568f1bc7157a68204336c6c5ecad2b1e592a..c4abd0f372d9b2708764d7de989847e44f103e1b 100644 (file)
@@ -720,13 +720,16 @@ static int handle_show_locks(int fd, int argc, char *argv[])
                                "=== <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,14 +741,24 @@ static int handle_show_locks(int fd, int argc, char *argv[])
                                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);
 
        free(str);