aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-12 17:15:56 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-12 17:15:56 +0000
commit12ebe404df9258470759a135da05a69999b97a04 (patch)
treebb9cdfe66001453f0342b986c8eea22ae464f472 /main
parentae8659d7badea8e83bc046463376d0063a6b29e1 (diff)
Correctly handle possible memory allocation failure
Reported by: eliel Patch by: eliel (Closes issue #11512) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@92507 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/asterisk.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 3c134e207..95778bfe4 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -1983,7 +1983,7 @@ static char *cli_prompt(EditLine *el)
static char **ast_el_strtoarr(char *buf)
{
- char **match_list = NULL, *retstr;
+ char **match_list = NULL, **match_list_tmp, *retstr;
size_t match_list_len;
int matches = 0;
@@ -1994,8 +1994,12 @@ static char **ast_el_strtoarr(char *buf)
break;
if (matches + 1 >= match_list_len) {
match_list_len <<= 1;
- if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
- /* TODO: Handle memory allocation failure */
+ if ((match_list_tmp = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
+ match_list = match_list_tmp;
+ } else {
+ if (match_list)
+ ast_free(match_list);
+ return (char **) NULL;
}
}
@@ -2006,8 +2010,12 @@ static char **ast_el_strtoarr(char *buf)
return (char **) NULL;
if (matches >= match_list_len) {
- if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
- /* TODO: Handle memory allocation failure */
+ if ((match_list_tmp = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
+ match_list = match_list_tmp;
+ } else {
+ if (match_list)
+ ast_free(match_list);
+ return (char **) NULL;
}
}