From: Andrew Tridgell Date: Wed, 15 Jan 2025 20:09:12 +0000 (+1100) Subject: popt: remove dependency on alloca X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fpr-remove-alloca-dep;p=thirdparty%2Frsync.git popt: remove dependency on alloca --- diff --git a/popt/findme.c b/popt/findme.c index ac4cbaed..49fc9f6f 100644 --- a/popt/findme.c +++ b/popt/findme.c @@ -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;