Skip to content
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

Asserting we're not freeing active event #1642

Merged
merged 2 commits into from May 18, 2024

Conversation

Coeur
Copy link
Contributor

@Coeur Coeur commented May 4, 2024

Fix #1638.

Although, could be done differently if you have suggestions.

Conditions:

  • evcb_flags & EVLIST_INIT to set ev
  • ! (ev->ev_events & EV_PERSIST) to skip event_queue_remove_active
  • ! (ev->ev_flags & EVLIST_FINALIZING) to skip event_queue_remove_active
  • eventually ev->ev_base == NULL to skip event_queue_remove_active in event_del_nolock_
  • or ! (ev->ev_flags & EVLIST_ACTIVE) to skip event_queue_remove_active in event_del_nolock_
  • evcb->evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE for the free to occur
  • ! base->event_break to continue the loop
  • ! base->event_continue to continue the loop

When those conditions are met, we free an event without removing it from the queue.
If you know that one of those conditions is strictly impossible, then we could add a specific assert instead my current proposal.
Another alternative to "not free" when it's in the queue, is to remove that event from the queue when above conditions arise, but I wouldn't know the side effects of such change.

@azat
Copy link
Member

azat commented May 4, 2024

evcb_flags & EVLIST_INIT to set ev

Ok

! (ev->ev_events & EV_PERSIST) to skip event_queue_remove_active

Ok

! (ev->ev_flags & EVLIST_FINALIZING) to skip event_queue_remove_active

Ok

eventually ev->ev_base == NULL to skip event_queue_remove_active in event_del_nolock_

Not possible, since if you have EV_LIST, then event_assign() is called and base should be set, otherwise it cannot be run

or ! (ev->ev_flags & EVLIST_ACTIVE) to skip event_queue_remove_active in event_del_nolock_

This is also should not be possible, since only EVLIST_ACTIVE should be triggered from event_process_active_single_queue

We can add an assert here for base and EVLIST_ACTIVE

evcb->evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE for the free to occur
! base->event_break to continue the loop
! base->event_continue to continue the loop

So this should not be possible.

@Coeur Coeur force-pushed the coeur/EV_CLOSURE_EVENT_FINALIZE_FREE branch from 835888f to ae17ef2 Compare May 4, 2024 12:16
@Coeur
Copy link
Contributor Author

Coeur commented May 4, 2024

We can add an assert here for base and EVLIST_ACTIVE

14e284f

@Coeur Coeur force-pushed the coeur/EV_CLOSURE_EVENT_FINALIZE_FREE branch from ae17ef2 to 19deb9f Compare May 4, 2024 12:18
@Coeur Coeur changed the title Avoiding freeing active event Asserting we're not freeing active event May 4, 2024
event.c Show resolved Hide resolved
@Coeur Coeur force-pushed the coeur/EV_CLOSURE_EVENT_FINALIZE_FREE branch from 19deb9f to 83c5750 Compare May 6, 2024 15:32
Coeur added 2 commits May 18, 2024 16:17
…ue()

It should not be possible, since only EVLIST_ACTIVE should be triggered
from event_process_active_single_queue, but adding assert will not hurt.
@azat azat force-pushed the coeur/EV_CLOSURE_EVENT_FINALIZE_FREE branch from 83c5750 to 66ee086 Compare May 18, 2024 14:19
@azat azat merged commit 66ee086 into libevent:master May 18, 2024
59 of 70 checks passed
@azat
Copy link
Member

azat commented May 18, 2024

LGTM, thanks!

P.S. next time please try to fit commit subject into 80 chars (I've adjusted the commit messages by myself this time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

event_process_active_single_queue: Use of memory after it is freed
2 participants