Fix file descriptor leak

On linux, diod uses fdopendir to "convert" a file descriptor into a
DIR*, which consumes the fd.

Mac doesn't have fdopendir so code was using normal opendir to produce
the DIR* but was not closing the file descriptor. Close code would only
close fd if it didn't have a DIR so file descriptor would leak
eventually causing too many open files errors.

Fix is to just close the fd before calling opendir.