]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix memory corruption and leakage related reloads of non files mode MoH classes.
authorRussell Bryant <russell@russellbryant.com>
Thu, 18 Jun 2009 15:24:31 +0000 (15:24 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 18 Jun 2009 15:24:31 +0000 (15:24 +0000)
For Music on Hold classes that are not files mode, meaning that we are executing
an application that will feed us audio data, we use a thread to monitor the
external application and read audio from it.  This thread also makes use of the
MoH class object.  In the MoH class destructor, we used pthread_cancel() to ask
the thread to exit.  Unfortunately, the code did not wait to ensure that the
thread actually went away.  What needed to be done is a pthread_join() to ensure
that the thread fully cleans up before we proceed.  By adding this one line, we
resolve two significant problems:

  1) Since the thread was never joined, it never fully goes away.  So, on every
     reload of non-files mode MoH, an unused thread was sticking around.

  2) There was a race condition here where the application monitoring thread
     could still try to access the MoH class, even though the thread executing
     the MoH reload has already destroyed it.

(issue #15109)
Reported by: jvandal

(issue #15123)
Reported by: axisinternet

(issue #15195)
Reported by: amorsen

(issue AST-208)

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

res/res_musiconhold.c

index 4ec9e648f3da00cd59a471b0b48eb01a98b5f61d..141f89c01ade5a7692205bf5918a1a1b4c1bb283 100644 (file)
@@ -1103,9 +1103,10 @@ static void moh_class_destructor(void *obj)
        while ((member = AST_LIST_REMOVE_HEAD(&class->members, list))) {
                free(member);
        }
-       
+
        if (class->thread) {
                pthread_cancel(class->thread);
+               pthread_join(class->thread, NULL);
                class->thread = AST_PTHREADT_NULL;
        }