void
agent_cleanup_stale(const char *homedir, int ignore_hosthash)
{
- DIR *d;
+ DIR *d = NULL;
struct dirent *dp;
struct stat sb;
- char *prefix = NULL, *dirpath, *path;
+ char *prefix = NULL, *dirpath = NULL, *path;
struct timespec now, sub, *mtimp = NULL;
/* Only consider sockets last modified > 1 hour ago */
if ((d = opendir(dirpath)) == NULL) {
if (errno != ENOENT)
error_f("opendir \"%s\": %s", dirpath, strerror(errno));
- free(dirpath);
- return;
+ goto out;
}
while ((dp = readdir(d)) != NULL) {
if (dp->d_type != DT_SOCK && dp->d_type != DT_UNKNOWN)
}
free(path);
}
- closedir(d);
+ out:
+ if (d != NULL)
+ closedir(d);
free(dirpath);
free(prefix);
}
-