Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6fc3fd9 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Andre Eisenbach
Browse files

Fix a race condition during alarm_cleanup()

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
parent bcb9e778
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -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;

+1 −1
Original line number Diff line number Diff line
@@ -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));
}