Fixed use-afer-free in the event queue