fix file and socket handle leak