Fix leaking handles from wait event