Close fd 3 eailier
Fix linking issue under Ubuntu 12.04