Fix resource leaks
Initialize all fields in events

to make coverity happy
Fix use-after-free complained by coverity

It's not really use-after-use, because the pointer is not dereferenced
Fix a memory leak

Found by coverity
Check parameter to avoid uninitialized var

reported by coverity
Add coverity annotation for abort like functions
Include string.h for memset
Shut off compiler complains
Avoid out-of-bound writing

Not sure if this is the correct fix
Avoid uninitialized variable
Avoid uninitialized pointer
Avoid uninitialized pointer
Avoid undefined behavior caused by malloc(0)

Found by clang-analyzer
Fix memory leaks

Found by clang-analyzer