diff options
author | Richard Mudgett <rmudgett@digium.com> | 2013-09-10 18:05:47 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2013-09-10 18:05:47 +0000 |
commit | 83bf017db9804c9274608ded72d70a72c086d756 (patch) | |
tree | a2f9a38495c75235101c86a3572529098fc5800f /res | |
parent | 87cf916cdbcf16d244bd71d91ec5b849cc186923 (diff) |
Fix incorrect usages of ast_realloc().
There are several locations in the code base where this is done:
buf = ast_realloc(buf, new_size);
This is going to leak the original buf contents if the realloc fails.
Review: https://reviewboard.asterisk.org/r/2832/
........
Merged revisions 398757 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 398758 from http://svn.asterisk.org/svn/asterisk/branches/11
........
Merged revisions 398759 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@398760 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r-- | res/res_musiconhold.c | 16 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_configuration.c | 19 |
2 files changed, 23 insertions, 12 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 70c985eb9..086139ab8 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -1055,20 +1055,26 @@ static struct ast_generator mohgen = { static int moh_add_file(struct mohclass *class, const char *filepath) { if (!class->allowed_files) { - if (!(class->filearray = ast_calloc(1, INITIAL_NUM_FILES * sizeof(*class->filearray)))) + class->filearray = ast_calloc(1, INITIAL_NUM_FILES * sizeof(*class->filearray)); + if (!class->filearray) { return -1; + } class->allowed_files = INITIAL_NUM_FILES; } else if (class->total_files == class->allowed_files) { - if (!(class->filearray = ast_realloc(class->filearray, class->allowed_files * sizeof(*class->filearray) * 2))) { - class->allowed_files = 0; - class->total_files = 0; + char **new_array; + + new_array = ast_realloc(class->filearray, class->allowed_files * sizeof(*class->filearray) * 2); + if (!new_array) { return -1; } + class->filearray = new_array; class->allowed_files *= 2; } - if (!(class->filearray[class->total_files] = ast_strdup(filepath))) + class->filearray[class->total_files] = ast_strdup(filepath); + if (!class->filearray[class->total_files]) { return -1; + } class->total_files++; diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index eb34675af..14b122c22 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -290,6 +290,7 @@ void ast_sip_auth_array_destroy(struct ast_sip_auth_array *auths) ast_free((char *) auths->names[i]); } ast_free(auths->names); + auths->names = NULL; auths->num = 0; } @@ -300,22 +301,26 @@ int ast_sip_auth_array_init(struct ast_sip_auth_array *auths, const char *value) char *auth_names = ast_strdupa(value); char *val; int num_alloced = 0; - const char **alloced_auths = NULL; + const char **alloced_auths; + + ast_assert(auths != NULL); + ast_assert(auths->names == NULL); + ast_assert(!auths->num); while ((val = strsep(&auth_names, ","))) { if (auths->num >= num_alloced) { - size_t size; num_alloced += AUTH_INCREMENT; - size = num_alloced * sizeof(char *); - auths->names = ast_realloc(alloced_auths, size); - if (!auths->names) { + alloced_auths = ast_realloc(auths->names, num_alloced * sizeof(char *)); + if (!alloced_auths) { goto failure; } + auths->names = alloced_auths; } - auths->names[auths->num] = ast_strdup(val); - if (!auths->names[auths->num]) { + val = ast_strdup(val); + if (!val) { goto failure; } + auths->names[auths->num] = val; ++auths->num; } return 0; |