diff options
author | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-14 14:29:05 +0000 |
---|---|---|
committer | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-14 14:29:05 +0000 |
commit | 343f8b733db9b43c0d01fb8a9c377a8cf3d99048 (patch) | |
tree | 82d50f2831d76afe6cf1b2ff275ed81661a417b4 /res | |
parent | 9de01fb3abcbdb0ff3f86cf681312d069a637e62 (diff) |
Fix a potential segfault if chan (or chan->music_state) is NULL.
Closes issue #12210, credit to edantie for pointing this out.
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@108682 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r-- | res/res_musiconhold.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index b1955825a..87b327897 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -200,23 +200,26 @@ static void ast_moh_free_class(struct mohclass **mohclass) static void moh_files_release(struct ast_channel *chan, void *data) { - struct moh_files_state *state = chan->music_state; + struct moh_files_state *state; - if (chan && state) { - if (chan->stream) { - ast_closestream(chan->stream); - chan->stream = NULL; - } - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "Stopped music on hold on %s\n", chan->name); + if (chan) { + if ((state = chan->music_state)) { + if (chan->stream) { + ast_closestream(chan->stream); + chan->stream = NULL; + } + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Stopped music on hold on %s\n", chan->name); + + if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) { + ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, state->origwfmt); + } + state->save_pos = state->pos; - if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) { - ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, state->origwfmt); + if (ast_atomic_dec_and_test(&state->class->inuse) && state->class->delete) + ast_moh_destroy_one(state->class); } - state->save_pos = state->pos; } - if (ast_atomic_dec_and_test(&state->class->inuse) && state->class->delete) - ast_moh_destroy_one(state->class); } |