diff --git a/apps/app_queue.c b/apps/app_queue.c index 3a8654b81a642b27d3e9acac8fbb51c60050b5ac..482200dad1678991517965b4cec5ea9a60b78f73 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -685,7 +685,7 @@ static struct { static void *device_state_thread(void *data) { - struct statechange *sc; + struct statechange *sc = NULL; while (!device_state.stop) { ast_mutex_lock(&device_state.lock); @@ -697,7 +697,7 @@ static void *device_state_thread(void *data) /* Check to see if we were woken up to see the request to stop */ if (device_state.stop) - return NULL; + break; if (!sc) continue; @@ -705,8 +705,15 @@ static void *device_state_thread(void *data) handle_statechange(sc); free(sc); + sc = NULL; } + if (sc) + free(sc); + + while ((sc = AST_LIST_REMOVE_HEAD(&device_state.state_change_q, entry))) + free(sc); + return NULL; }