clean up our middle process during forking
fix fclose() order bug from bf8116c9