Fixes a file descriptor leak