Fixed possible file descriptor leak.

This is a fix for a possible file descriptor leak problem that can lead to excess maximum number of open file descriptors.
This problem can be easely reproduced on Mac OS X where default maximum number of open file descriptor is 256.