fixed double free bug caused by two fclose() on fd