[asterisk-commits] russell: trunk r38088 - /trunk/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Jul 22 19:41:03 MST 2006


Author: russell
Date: Sat Jul 22 21:41:02 2006
New Revision: 38088

URL: http://svn.digium.com/view/asterisk?rev=38088&view=rev
Log:
various cleanups regarding coding guidelines issues
 - malloc to ast_malloc
 - malloc + memset to ast_calloc
 - sizeof(struct foo) to sizeof(*bar)
 - remove indentation of the entire body of a function by returning immediately
   on an allocation failure
(issue #7581, tempest1)

Modified:
    trunk/manager.c

Modified: trunk/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/manager.c?rev=38088&r1=38087&r2=38088&view=diff
==============================================================================
--- trunk/manager.c (original)
+++ trunk/manager.c Sat Jul 22 21:41:02 2006
@@ -280,7 +280,7 @@
 			escaped++;
 	}
 	len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
-	out = malloc(len);
+	out = ast_malloc(len);
 	if (!out)
 		return 0;
 	tmp = out;
@@ -338,7 +338,7 @@
 			breaks++;
 	}
 	len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
-	out = malloc(len);
+	out = ast_malloc(len);
 	if (!out)
 		return 0;
 	tmp = out;
@@ -1555,11 +1555,10 @@
 			l = NULL;
 	}
 	if (ast_true(async)) {
-		struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper));
+		struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
 		if (!fast) {
 			res = -1;
 		} else {
-			memset(fast, 0, sizeof(struct fast_originate_helper));
 			if (!ast_strlen_zero(id))
 				snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
 			ast_copy_string(fast->tech, tech, sizeof(fast->tech));
@@ -2080,24 +2079,28 @@
 static int append_event(const char *str, int category)
 {
 	struct eventqent *tmp, *prev = NULL;
-	tmp = malloc(sizeof(struct eventqent) + strlen(str));
-	if (tmp) {
-		ast_mutex_init(&tmp->lock);
-		tmp->next = NULL;
-		tmp->category = category;
-		strcpy(tmp->eventdata, str);
-		if (master_eventq) {
-			prev = master_eventq;
-			while (prev->next) 
-				prev = prev->next;
-			prev->next = tmp;
-		} else {
-			master_eventq = tmp;
-		}
-		tmp->usecount = num_sessions;
-		return 0;
-	}
-	return -1;
+	tmp = ast_malloc(sizeof(*tmp) + strlen(str));
+
+	if (!tmp)
+		return -1;
+
+	ast_mutex_init(&tmp->lock);
+	tmp->next = NULL;
+	tmp->category = category;
+	strcpy(tmp->eventdata, str);
+	
+	if (master_eventq) {
+		prev = master_eventq;
+		while (prev->next) 
+			prev = prev->next;
+		prev->next = tmp;
+	} else {
+		master_eventq = tmp;
+	}
+	
+	tmp->usecount = num_sessions;
+	
+	return 0;
 }
 
 /*! \brief  manager_event: Send AMI event to client */
@@ -2218,11 +2221,10 @@
 {
 	struct manager_action *cur;
 
-	cur = malloc(sizeof(struct manager_action));
-	if (!cur) {
-		ast_log(LOG_WARNING, "Manager: out of memory trying to register action\n");
+	cur = ast_malloc(sizeof(*cur));
+	if (!cur)
 		return -1;
-	}
+	
 	cur->action = action;
 	cur->authority = auth;
 	cur->func = func;



More information about the asterisk-commits mailing list