]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix a little race condition that could cause a crash if two channels had MOH
authorRussell Bryant <russell@russellbryant.com>
Thu, 16 Aug 2007 22:32:33 +0000 (22:32 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 16 Aug 2007 22:32:33 +0000 (22:32 +0000)
stopped at the same time that were using a class that had been marked for
deletion when its use count hits zero.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@79792 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_musiconhold.c

index d1aa725c25da780e80eced9ba317c88064460aef..08dda0c5f4276b9446f94843d86c2be08a1138c4 100644 (file)
@@ -202,8 +202,6 @@ static void moh_files_release(struct ast_channel *chan, void *data)
 {
        struct moh_files_state *state = chan->music_state;
 
-       ast_atomic_fetchadd_int(&state->class->inuse, -1);
-
        if (chan && state) {
                if (chan->stream) {
                         ast_closestream(chan->stream);
@@ -217,7 +215,7 @@ static void moh_files_release(struct ast_channel *chan, void *data)
                }
                state->save_pos = state->pos;
        }
-       if (state->class->delete && !state->class->inuse)
+       if (state->class->delete && ast_atomic_dec_and_test(&state->class->inuse))
                ast_moh_destroy_one(state->class);
 }