]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_registrar_expire: Fix race condition at shutdown. 43/2543/3
authorJoshua Colp <jcolp@digium.com>
Thu, 7 Apr 2016 16:05:26 +0000 (13:05 -0300)
committerJoshua Colp <jcolp@digium.com>
Thu, 7 Apr 2016 16:42:01 +0000 (13:42 -0300)
When shutting down, the PJSIP sorcery is destroyed. The registrar
expiration module queries the PJSIP sorcery to determine what
to expire. As there was no synchronization between termination
of the expiration thread and the unloading of the module it was
possible for the thread to try to access the PJSIP sorcery after
it had been destroyed.

This change ensures that the thread is shut down before allowing
the module to be considered unloaded.

Change-Id: I69fd239edbaaf160c2d37ae00d3ac06e5596fe8b

res/res_pjsip_registrar_expire.c

index bdb86e50e1b3fb864a9b7946bba6b1ff1831c88f..97f2ca1c01d9c4b7587c5e7b3e62229af03f84bc 100644 (file)
@@ -91,6 +91,7 @@ static void expiration_global_loaded(const char *object_type)
        } else {
                if (check_thread != AST_PTHREADT_NULL) {
                        pthread_kill(check_thread, SIGURG);
+                       pthread_join(check_thread, NULL);
                        check_thread = AST_PTHREADT_NULL;
                        ast_debug(3, "Interval = 0, shutting thread down\n");
                }
@@ -105,7 +106,10 @@ static struct ast_sorcery_observer expiration_global_observer = {
 static int unload_module(void)
 {
        if (check_thread != AST_PTHREADT_NULL) {
+               check_interval = 0;
                pthread_kill(check_thread, SIGURG);
+               pthread_join(check_thread, NULL);
+
                check_thread = AST_PTHREADT_NULL;
        }