Skip to content

EventQueue: Old pointers of sibling were not cleared #9144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions events/equeue/equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ void equeue_destroy(equeue_t *q)
{
// call destructors on pending events
for (struct equeue_event *es = q->queue; es; es = es->next) {
for (struct equeue_event *e = q->queue; e; e = e->sibling) {
for (struct equeue_event *e = es->sibling; e; e = e->sibling) {
if (e->dtor) {
e->dtor(e + 1);
}
}
if (es->dtor) {
es->dtor(es + 1);
}
}

// notify background timer
if (q->background.update) {
q->background.update(q->background.timer, -1);
Expand Down Expand Up @@ -239,8 +241,8 @@ static int equeue_enqueue(equeue_t *q, struct equeue_event *e, unsigned tick)
if (e->next) {
e->next->ref = &e->next;
}

e->sibling = *p;
e->sibling->next = 0;
e->sibling->ref = &e->sibling;
} else {
e->next = *p;
Expand Down
25 changes: 24 additions & 1 deletion events/equeue/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,29 @@ void break_request_cleared_on_timeout(void)
equeue_destroy(&q);
}

void sibling_test(void)
{
equeue_t q;
int err = equeue_create(&q, 1024);
test_assert(!err);

int id0 = equeue_call_in(&q, 1, pass_func, 0);
int id1 = equeue_call_in(&q, 1, pass_func, 0);
int id2 = equeue_call_in(&q, 1, pass_func, 0);

struct equeue_event *e = q.queue;

for (; e; e = e->next) {
for (struct equeue_event *s = e->sibling; s; s = s->sibling) {
test_assert(!s->next);
}
}
equeue_cancel(&q, id0);
equeue_cancel(&q, id1);
equeue_cancel(&q, id2);
equeue_destroy(&q);
}

int main()
{
printf("beginning tests...\n");
Expand Down Expand Up @@ -806,7 +829,7 @@ int main()
test_run(fragmenting_barrage_test, 20);
test_run(multithreaded_barrage_test, 20);
test_run(break_request_cleared_on_timeout);

test_run(sibling_test);
printf("done!\n");
return test_failure;
}