Always close opendir() objects if and only if successfully opened.
Ticket [d7169e51ebb3400f6]