fix file descriptor leak