Small clean-ups and leak fixes in the OPENDIR mechanism.

`end` is uninitialized.  You probably meant to declare end *outside* the loop body, so that it would have retained its value from last time round the loop; then the *first* time round the loop would have `start == NULL`, so initialize end, and all later times round would visit this else clause to update it.