res_musiconhold: Minor cleanup.

Fix a few free()'s that should be ast_free()'s. Reverted an old
workaround that isn't necessary. Reorder a tiny bit of code.
Remove a bit of commented-out code.

Review: https://reviewboard.asterisk.org/r/3536/
........

Merged revisions 413894 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 413895 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 413896 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@413897 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Walter Doekes 2014-05-14 15:41:42 +00:00
parent e81b873fa2
commit 8fd6a88633
1 changed files with 31 additions and 44 deletions

View File

@ -163,7 +163,6 @@ static int respawn_time = 20;
struct moh_files_state { struct moh_files_state {
/*! Holds a reference to the MOH class. */ /*! Holds a reference to the MOH class. */
struct mohclass *class; struct mohclass *class;
char name[MAX_MUSICCLASS];
struct ast_format origwfmt; struct ast_format origwfmt;
struct ast_format mohwfmt; struct ast_format mohwfmt;
int announcement; int announcement;
@ -171,7 +170,6 @@ struct moh_files_state {
int sample_queue; int sample_queue;
int pos; int pos;
int save_pos; int save_pos;
int save_total;
char save_pos_filename[PATH_MAX]; char save_pos_filename[PATH_MAX];
}; };
@ -461,28 +459,29 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in
while (state->sample_queue > 0) { while (state->sample_queue > 0) {
ast_channel_lock(chan); ast_channel_lock(chan);
if ((f = moh_files_readframe(chan))) { f = moh_files_readframe(chan);
/* We need to be sure that we unlock
* the channel prior to calling /* We need to be sure that we unlock
* ast_write. Otherwise, the recursive locking * the channel prior to calling
* that occurs can cause deadlocks when using * ast_write. Otherwise, the recursive locking
* indirect channels, like local channels * that occurs can cause deadlocks when using
*/ * indirect channels, like local channels
ast_channel_unlock(chan); */
state->samples += f->samples; ast_channel_unlock(chan);
state->sample_queue -= f->samples; if (!f) {
if (ast_format_cmp(&f->subclass.format, &state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) { return -1;
ast_format_copy(&state->mohwfmt, &f->subclass.format); }
}
res = ast_write(chan, f); state->samples += f->samples;
ast_frfree(f); state->sample_queue -= f->samples;
if (res < 0) { if (ast_format_cmp(&f->subclass.format, &state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) {
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno)); ast_format_copy(&state->mohwfmt, &f->subclass.format);
return -1; }
} res = ast_write(chan, f);
} else { ast_frfree(f);
ast_channel_unlock(chan); if (res < 0) {
return -1; ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno));
return -1;
} }
} }
return res; return res;
@ -507,12 +506,11 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params)
} }
} }
/* LOGIC: Comparing an unrefcounted pointer is a really bad idea, because /* class is reffed, so we can safely compare it against the (possibly
* malloc may allocate a different class to the same memory block. This * recently unreffed) state->class. The unref was done after the ref
* might only happen when two reloads are generated in a short period of * of class, so we're sure that they won't point to the same memory
* time, but it's still important to protect against. * by accident. */
* PROG: Compare the quick operation first, to save CPU. */ if (state->class != class) {
if (state->save_total != class->total_files || strcmp(state->name, class->name) != 0) {
memset(state, 0, sizeof(*state)); memset(state, 0, sizeof(*state));
if (ast_test_flag(class, MOH_RANDOMIZE) && class->total_files) { if (ast_test_flag(class, MOH_RANDOMIZE) && class->total_files) {
state->pos = ast_random() % class->total_files; state->pos = ast_random() % class->total_files;
@ -523,10 +521,6 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params)
ast_format_copy(&state->origwfmt, ast_channel_writeformat(chan)); ast_format_copy(&state->origwfmt, ast_channel_writeformat(chan));
ast_format_copy(&state->mohwfmt, ast_channel_writeformat(chan)); ast_format_copy(&state->mohwfmt, ast_channel_writeformat(chan));
/* For comparison on restart of MOH (see above) */
ast_copy_string(state->name, class->name, sizeof(state->name));
state->save_total = class->total_files;
moh_post_start(chan, class->name); moh_post_start(chan, class->name);
return state; return state;
@ -1238,13 +1232,6 @@ static int init_files_class(struct mohclass *class)
return -1; return -1;
} }
#if 0
/* XXX This isn't correct. Args is an application for custom mode. XXX */
if (strchr(class->args, 'r')) {
ast_set_flag(class, MOH_RANDOMIZE);
}
#endif
return 0; return 0;
} }
@ -1654,7 +1641,7 @@ static void moh_class_destructor(void *obj)
ao2_lock(class); ao2_lock(class);
while ((member = AST_LIST_REMOVE_HEAD(&class->members, list))) { while ((member = AST_LIST_REMOVE_HEAD(&class->members, list))) {
free(member); ast_free(member);
} }
ao2_unlock(class); ao2_unlock(class);
@ -1715,9 +1702,9 @@ static void moh_class_destructor(void *obj)
if (class->filearray) { if (class->filearray) {
int i; int i;
for (i = 0; i < class->total_files; i++) { for (i = 0; i < class->total_files; i++) {
free(class->filearray[i]); ast_free(class->filearray[i]);
} }
free(class->filearray); ast_free(class->filearray);
class->filearray = NULL; class->filearray = NULL;
} }