summaryrefslogtreecommitdiff
path: root/manager.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2006-07-23 02:41:02 +0000
committerRussell Bryant <russell@russellbryant.com>2006-07-23 02:41:02 +0000
commit5830e9cb4f6f3f134a467c071c8786872f051c1f (patch)
tree759d89ae99b452d97b095a69dcb11042ffdad849 /manager.c
parentf21d43ad5e06772f2eecef1e0ec0705a96653564 (diff)
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) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38088 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'manager.c')
-rw-r--r--manager.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/manager.c b/manager.c
index 7d4de6bdd..f0817f474 100644
--- a/manager.c
+++ b/manager.c
@@ -280,7 +280,7 @@ static char *xml_translate(char *in, struct ast_variable *vars)
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 @@ static char *html_translate(char *in)
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 @@ static int action_originate(struct mansession *s, struct message *m)
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 void *accept_thread(void *ignore)
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;
+ 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;
}
- return -1;
+
+ tmp->usecount = num_sessions;
+
+ return 0;
}
/*! \brief manager_event: Send AMI event to client */
@@ -2218,11 +2221,10 @@ int ast_manager_register2(const char *action, int auth, int (*func)(struct manse
{
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;