Fixed bug of too many open file handles from mkstemp