Fix file descriptors leaks
Merge pull request #893 from lpefferkorn/fix_fd_leaks

Fix file descriptors leaks