Skip to content

Commit 8d6da04

Browse files
committed
popt: remove dependency on alloca
1 parent 68e9add commit 8d6da04

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

popt/findme.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ const char * findProgramPath(const char * argv0)
2525
if (path == NULL) return NULL;
2626

2727
bufsize = strlen(path) + 1;
28-
start = pathbuf = alloca(bufsize);
28+
start = pathbuf = malloc(bufsize);
2929
if (pathbuf == NULL) return NULL; /* XXX can't happen */
3030
strlcpy(pathbuf, path, bufsize);
3131
bufsize += sizeof "/" - 1 + strlen(argv0);
3232
buf = malloc(bufsize);
33-
if (buf == NULL) return NULL; /* XXX can't happen */
33+
if (buf == NULL) {
34+
free(pathbuf);
35+
return NULL; /* XXX can't happen */
36+
}
3437

3538
chptr = NULL;
3639
/*@-branchstate@*/
@@ -39,8 +42,10 @@ const char * findProgramPath(const char * argv0)
3942
*chptr = '\0';
4043
snprintf(buf, bufsize, "%s/%s", start, argv0);
4144

42-
if (!access(buf, X_OK))
45+
if (!access(buf, X_OK)) {
46+
free(pathbuf);
4347
return buf;
48+
}
4449

4550
if (chptr)
4651
start = chptr + 1;
@@ -49,6 +54,7 @@ const char * findProgramPath(const char * argv0)
4954
} while (start && *start);
5055
/*@=branchstate@*/
5156

57+
free(pathbuf);
5258
free(buf);
5359

5460
return NULL;

0 commit comments

Comments
 (0)