We can fix this by checking whether ourDIR is zero before calling opendir. If not, either generate an error or silently call closedir. I'd tend to favor the former, for while that might break some existing code, it hints at the user that something is wrong. But I could live with either.