summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorPavlin Radoslavov <pavlin@google.com>2016-04-25 12:29:29 -0700
committerAndre Eisenbach <eisenbach@google.com>2016-04-25 21:40:53 +0000
commit97ec0a56f5282ee8977bc1dcb60bb86980e757d6 (patch)
tree7245e58712df5ba57a8e48f6ce3351f6b467c742 /osi
parent3165425aff5744bf682a2887e9704e66f8d34a87 (diff)
downloadandroid-system-bt-97ec0a56f5282ee8977bc1dcb60bb86980e757d6.tar.gz
android-system-bt-97ec0a56f5282ee8977bc1dcb60bb86980e757d6.tar.xz
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
Diffstat (limited to 'osi')
-rw-r--r--osi/src/alarm.c8
-rw-r--r--osi/src/semaphore.c2
2 files changed, 6 insertions, 4 deletions
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index f28843e..669366d 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -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;
diff --git a/osi/src/semaphore.c b/osi/src/semaphore.c
index 0318401..45a9150 100644
--- a/osi/src/semaphore.c
+++ b/osi/src/semaphore.c
@@ -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));
}