Fixed possible release of uninitialized event pointer.
Added missing include for malloc.