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/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@413894 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/98/198/1
Walter Doekes 11 years ago
parent adb0ee2dcd
commit 76a57fcbc4

@ -155,13 +155,11 @@ 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];
format_t origwfmt; format_t origwfmt;
int samples; int samples;
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];
}; };
@ -379,7 +377,8 @@ 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 /* We need to be sure that we unlock
* the channel prior to calling * the channel prior to calling
* ast_write. Otherwise, the recursive locking * ast_write. Otherwise, the recursive locking
@ -387,6 +386,10 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in
* indirect channels, like local channels * indirect channels, like local channels
*/ */
ast_channel_unlock(chan); ast_channel_unlock(chan);
if (!f) {
return -1;
}
state->samples += f->samples; state->samples += f->samples;
state->sample_queue -= f->samples; state->sample_queue -= f->samples;
res = ast_write(chan, f); res = ast_write(chan, f);
@ -395,10 +398,6 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno)); ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno));
return -1; return -1;
} }
} else {
ast_channel_unlock(chan);
return -1;
}
} }
return res; return res;
} }
@ -422,12 +421,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;
@ -436,9 +434,6 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params)
state->class = mohclass_ref(class, "Reffing music class for channel"); state->class = mohclass_ref(class, "Reffing music class for channel");
state->origwfmt = chan->writeformat; state->origwfmt = chan->writeformat;
/* For comparison on restart of MOH (see above) */
ast_copy_string(state->name, class->name, sizeof(state->name));
state->save_total = class->total_files;
ast_verb(3, "Started music on hold, class '%s', on %s\n", class->name, chan->name); ast_verb(3, "Started music on hold, class '%s', on %s\n", class->name, chan->name);
@ -1146,13 +1141,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;
} }
@ -1572,7 +1560,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);
@ -1633,9 +1621,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;
} }

Loading…
Cancel
Save