From 764e9157f53444d3a25b350f8f62cec5352c7866 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 16 Jan 2025 07:09:12 +1100 Subject: [PATCH] popt: remove dependency on alloca --- popt/findme.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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; -- 2.47.2