fix file handle leak