Fixed a possible resource handle leak