core/loader: Don't call dlclose in a while loop