Skip to content

Commit

Permalink
re: issue #17 - fix possible race condition in q->mem value
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Oct 1, 2023
1 parent c4d5a42 commit 3ec73d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15851,6 +15851,7 @@ SFUNC int fio_queue_push_urgent FIO_NOOP(fio_queue_s *q,
SFUNC fio_queue_task_s fio_queue_pop(fio_queue_s *q) {
fio_queue_task_s t = {.fn = NULL};
fio___task_ring_s *to_free = NULL;
fio___task_ring_s *to_free_tst = NULL;
if (!q->count)
return t;
FIO___LOCK_LOCK(q->lock);
Expand All @@ -15871,9 +15872,10 @@ SFUNC fio_queue_task_s fio_queue_pop(fio_queue_s *q) {
q->r = q->w = &q->mem;
q->mem.w = q->mem.r = q->mem.dir = 0;
}
to_free_tst = &q->mem;
finish:
FIO___LOCK_UNLOCK(q->lock);
if (to_free && to_free != &q->mem) {
if (to_free && to_free != to_free_tst) {
FIO___LEAK_COUNTER_ON_FREE(fio_queue_task_rings);
FIO_MEM_FREE_(to_free, sizeof(*to_free));
}
Expand Down
4 changes: 3 additions & 1 deletion fio-stl/102 queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ SFUNC int fio_queue_push_urgent FIO_NOOP(fio_queue_s *q,
SFUNC fio_queue_task_s fio_queue_pop(fio_queue_s *q) {
fio_queue_task_s t = {.fn = NULL};
fio___task_ring_s *to_free = NULL;
fio___task_ring_s *to_free_tst = NULL;
if (!q->count)
return t;
FIO___LOCK_LOCK(q->lock);
Expand All @@ -489,9 +490,10 @@ SFUNC fio_queue_task_s fio_queue_pop(fio_queue_s *q) {
q->r = q->w = &q->mem;
q->mem.w = q->mem.r = q->mem.dir = 0;
}
to_free_tst = &q->mem;
finish:
FIO___LOCK_UNLOCK(q->lock);
if (to_free && to_free != &q->mem) {
if (to_free && to_free != to_free_tst) {
FIO___LEAK_COUNTER_ON_FREE(fio_queue_task_rings);
FIO_MEM_FREE_(to_free, sizeof(*to_free));
}
Expand Down

0 comments on commit 3ec73d8

Please sign in to comment.