avoid memory leak

Although fd is always the smallest number which haven't been allocated, which means memory leak is quite small. but the worst situation may consume lots of memory.
Merge branch 'sybblow-patch-1' into dev