summaryrefslogtreecommitdiff
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2013-09-10 18:05:47 +0000
committerRichard Mudgett <rmudgett@digium.com>2013-09-10 18:05:47 +0000
commit83bf017db9804c9274608ded72d70a72c086d756 (patch)
treea2f9a38495c75235101c86a3572529098fc5800f /res/res_musiconhold.c
parent87cf916cdbcf16d244bd71d91ec5b849cc186923 (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/res_musiconhold.c')
-rw-r--r--res/res_musiconhold.c16
1 files changed, 11 insertions, 5 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++;