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
This commit is contained in:
Richard Mudgett
2013-09-10 18:05:47 +00:00
parent 87cf916cdb
commit 83bf017db9
9 changed files with 130 additions and 59 deletions

View File

@@ -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))))
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;
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) {
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++;

View File

@@ -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;