From: djm@openbsd.org Date: Wed, 7 May 2025 04:10:21 +0000 (+0000) Subject: upstream: memory leak on error path; bz3821 X-Git-Tag: V_10_1_P1~312 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=93e904a673a632604525fdc98b940b7996f1ce54;p=thirdparty%2Fopenssh-portable.git upstream: memory leak on error path; bz3821 OpenBSD-Commit-ID: 65577596a15ad6dd9a1ab3fc24c1c31303ee6e2b --- diff --git a/misc-agent.c b/misc-agent.c index f13ccdf26..9d96880e9 100644 --- a/misc-agent.c +++ b/misc-agent.c @@ -266,10 +266,10 @@ socket_is_stale(const char *path) 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 */ @@ -295,8 +295,7 @@ agent_cleanup_stale(const char *homedir, int ignore_hosthash) 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) @@ -334,8 +333,9 @@ agent_cleanup_stale(const char *homedir, int ignore_hosthash) } free(path); } - closedir(d); + out: + if (d != NULL) + closedir(d); free(dirpath); free(prefix); } -