Update dir.c

Fix file descriptors leak