]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: memory leak on error path; bz3821
authordjm@openbsd.org <djm@openbsd.org>
Wed, 7 May 2025 04:10:21 +0000 (04:10 +0000)
committerDamien Miller <djm@mindrot.org>
Wed, 7 May 2025 04:22:40 +0000 (14:22 +1000)
OpenBSD-Commit-ID: 65577596a15ad6dd9a1ab3fc24c1c31303ee6e2b

misc-agent.c

index f13ccdf26b5dc06cd7bddf51f7925ed2eaebced2..9d96880e909094b2b8dad57d4566467a7928bb57 100644 (file)
@@ -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);
 }
-