]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
popt: remove dependency on alloca
authorAndrew Tridgell <andrew@tridgell.net>
Wed, 15 Jan 2025 20:09:12 +0000 (07:09 +1100)
committerAndrew Tridgell <andrew@tridgell.net>
Wed, 15 Jan 2025 20:27:46 +0000 (07:27 +1100)
popt/findme.c

index ac4cbaed203a9c889c962a9429a4b075730bd645..49fc9f6f095d4d686f454b42028c7d21e868139e 100644 (file)
@@ -25,12 +25,15 @@ const char * findProgramPath(const char * argv0)
     if (path == NULL) return NULL;
 
     bufsize = strlen(path) + 1;
-    start = pathbuf = alloca(bufsize);
+    start = pathbuf = malloc(bufsize);
     if (pathbuf == NULL) return NULL;  /* XXX can't happen */
     strlcpy(pathbuf, path, bufsize);
     bufsize += sizeof "/" - 1 + strlen(argv0);
     buf = malloc(bufsize);
-    if (buf == NULL) return NULL;      /* XXX can't happen */
+    if (buf == NULL) {
+           free(pathbuf);
+           return NULL;        /* XXX can't happen */
+    }
 
     chptr = NULL;
     /*@-branchstate@*/
@@ -39,8 +42,10 @@ const char * findProgramPath(const char * argv0)
            *chptr = '\0';
        snprintf(buf, bufsize, "%s/%s", start, argv0);
 
-       if (!access(buf, X_OK))
+       if (!access(buf, X_OK)) {
+           free(pathbuf);
            return buf;
+       }
 
        if (chptr) 
            start = chptr + 1;
@@ -49,6 +54,7 @@ const char * findProgramPath(const char * argv0)
     } while (start && *start);
     /*@=branchstate@*/
 
+    free(pathbuf);
     free(buf);
 
     return NULL;