added cf_close(fd) in OnClose()