Merged fd leaks fix from the master to the 0.3 version