diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-19 04:14:12 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-19 04:14:12 +0000 |
commit | c4976ddab1e3aa3385283bb403dc4bd3f08a856f (patch) | |
tree | 03cebae84fc3da01dbf5f4e336a28b53651dfce6 /main | |
parent | 8672fe3596bbadcaf8e267b267cb5a1bb8f6ae16 (diff) |
Minor coding style changes, including adding handling for memory allocation failure
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@109842 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/pbx.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/main/pbx.c b/main/pbx.c index 548e20268..b5f6ddd01 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -1091,19 +1091,30 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct static struct match_char *already_in_tree(struct match_char *current, char *pat) { struct match_char *t; + if (!current) return 0; - for (t=current; t; t=t->alt_char) { - if (strcmp(pat,t->x) == 0) /* uh, we may want to sort exploded [] contents to make matching easy */ + + for (t = current; t; t = t->alt_char) { + if (!strcmp(pat, t->x)) /* uh, we may want to sort exploded [] contents to make matching easy */ return t; } + return 0; } static struct match_char *add_pattern_node(struct ast_context *con, struct match_char *current, char *pattern, int is_pattern, int already, int specificity) { - struct match_char *m = ast_calloc(1,sizeof(struct match_char)); - m->x = ast_strdup(pattern); + struct match_char *m; + + if (!(m = ast_calloc(1, sizeof(*m)))) + return NULL; + + if (!(m->x = ast_strdup(pattern))) { + ast_free(m); + return NULL; + } + m->is_pattern = is_pattern; if (specificity == 1 && is_pattern && pattern[0] == 'N') m->specificity = 98; @@ -1133,6 +1144,7 @@ static struct match_char *add_pattern_node(struct ast_context *con, struct match } } } + return m; } |