OSDN Git Service

Fix a race condition during alarm_cleanup()
authorPavlin Radoslavov <pavlin@google.com>
Mon, 25 Apr 2016 19:29:29 +0000 (12:29 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 25 Apr 2016 21:40:53 +0000 (21:40 +0000)
Fix a race condition inside function alarm_cleanup() that
could be triggered during shutdown.

Also, fix few other issues:
 * Add missing "timer_delete(akeup_timer)" statement inside
   alarm_cleanup()
 * Fix the argument when calling "timer_delete(timer)"
 * Call "semaphore_free(alarm_expired)" inside alarm_cleanup()
   after the corresponding "timer" and "wakeup_timer" have
   been deleted.
 * Fix the argument type when calling eventfd_read() inside
   semaphore_wait()

Bug: 26982349
Change-Id: I2b00cd7ee7f56f755775f8e7b370006e31c6eb08

osi/src/alarm.c
osi/src/semaphore.c

index f28843e..669366d 100644 (file)
@@ -292,21 +292,23 @@ void alarm_cleanup(void) {
   if (!alarms)
     return;
 
-  pthread_mutex_lock(&monitor);
-
   dispatcher_thread_active = false;
   semaphore_post(alarm_expired);
   thread_free(dispatcher_thread);
   dispatcher_thread = NULL;
 
+  pthread_mutex_lock(&monitor);
+
   fixed_queue_free(default_callback_queue, NULL);
   default_callback_queue = NULL;
   thread_free(default_callback_thread);
   default_callback_thread = NULL;
 
+  timer_delete(wakeup_timer);
+  timer_delete(timer);
   semaphore_free(alarm_expired);
   alarm_expired = NULL;
-  timer_delete(&timer);
+
   list_free(alarms);
   alarms = NULL;
 
index 0318401..45a9150 100644 (file)
@@ -64,7 +64,7 @@ void semaphore_wait(semaphore_t *semaphore) {
   assert(semaphore != NULL);
   assert(semaphore->fd != INVALID_FD);
 
-  uint64_t value;
+  eventfd_t value;
   if (eventfd_read(semaphore->fd, &value) == -1)
     LOG_ERROR(LOG_TAG, "%s unable to wait on semaphore: %s", __func__, strerror(errno));
 }