fix: memory leak in read_events

It looks like memory leaked in `thr_main` because of `env` allocated, but not freed.

Also, fixed unused variable warning.