This fixes a tiny memory leak as well, as the return value of opendir() wasn't passed to a closedir() after use.