fix possible resource leaking