mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 16:21:01 +00:00
Correctly handle possible memory allocation failure
Reported by: eliel Patch by: eliel (Closes issue #11512) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@92507 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1983,7 +1983,7 @@ static char *cli_prompt(EditLine *el)
|
|||||||
|
|
||||||
static char **ast_el_strtoarr(char *buf)
|
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;
|
size_t match_list_len;
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
|
|
||||||
@@ -1994,8 +1994,12 @@ static char **ast_el_strtoarr(char *buf)
|
|||||||
break;
|
break;
|
||||||
if (matches + 1 >= match_list_len) {
|
if (matches + 1 >= match_list_len) {
|
||||||
match_list_len <<= 1;
|
match_list_len <<= 1;
|
||||||
if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
|
if ((match_list_tmp = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
|
||||||
/* TODO: Handle memory allocation failure */
|
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;
|
return (char **) NULL;
|
||||||
|
|
||||||
if (matches >= match_list_len) {
|
if (matches >= match_list_len) {
|
||||||
if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
|
if ((match_list_tmp = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
|
||||||
/* TODO: Handle memory allocation failure */
|
match_list = match_list_tmp;
|
||||||
|
} else {
|
||||||
|
if (match_list)
|
||||||
|
ast_free(match_list);
|
||||||
|
return (char **) NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user