char * path = getenv("PATH");
char * pathbuf;
char * start, * chptr;
- char * buf;
+ char * buf, *local = NULL;
/* If there is a / in the argv[0], it has to be an absolute
path */
if (!path) return NULL;
- start = pathbuf = alloca(strlen(path) + 1);
+ local = start = pathbuf = malloc(strlen(path) + 1);
buf = malloc(strlen(path) + strlen(argv0) + 2);
strcpy(pathbuf, path);
*chptr = '\0';
sprintf(buf, "%s/%s", start, argv0);
- if (!access(buf, X_OK))
- return buf;
+ if (!access(buf, X_OK)) {
+ if (local) free(local);
+ return buf;
+ }
if (chptr)
start = chptr + 1;
} while (start && *start);
free(buf);
+ if (local) free(local);
return NULL;
}
if (!con->execAbsolute && strchr(script, '/')) return;
if (!strchr(script, '/') && con->execPath) {
- char *s = alloca(strlen(con->execPath) + strlen(script) + 2);
+ char *s = malloc(strlen(con->execPath) + strlen(script) + 2);
sprintf(s, "%s/%s", con->execPath, script);
argv[pos] = s;
} else {
const struct poptOption * opt = NULL;
int done = 0;
+ /* looks a bit tricky to get rid of alloca properly in this fn */
+#if HAVE_ALLOCA_H
+#define ALLOCA(x) alloca(x)
+#else
+#define ALLOCA(x) malloc(x)
+#endif
+
+
while (!done) {
const char * origOptString = NULL;
poptCallbackType cb = NULL;
/* Make a copy we can hack at */
localOptString = optString =
- strcpy(alloca(strlen(origOptString) + 1),
+ strcpy(ALLOCA(strlen(origOptString) + 1),
origOptString);
if (!optString[0])
}
int poptReadConfigFile(poptContext con, const char * fn) {
- char * file, * chptr, * end;
- char * buf, * dst;
+ char * file=NULL, * chptr, * end;
+ char * buf=NULL, * dst;
int fd, rc;
int fileLength;
fileLength = lseek(fd, 0, SEEK_END);
(void) lseek(fd, 0, 0);
- file = alloca(fileLength + 1);
+ file = malloc(fileLength + 1);
if (read(fd, file, fileLength) != fileLength) {
rc = errno;
close(fd);
errno = rc;
+ if (file) free(file);
return POPT_ERROR_ERRNO;
}
close(fd);
- dst = buf = alloca(fileLength + 1);
+ dst = buf = malloc(fileLength + 1);
chptr = file;
end = (file + fileLength);
}
}
+ free(file);
+ free(buf);
+
return 0;
}
if (getuid() != geteuid()) return 0;
if ((home = getenv("HOME"))) {
- fn = alloca(strlen(home) + 20);
+ fn = malloc(strlen(home) + 20);
strcpy(fn, home);
strcat(fn, "/.popt");
rc = poptReadConfigFile(con, fn);
+ free(fn);
if (rc) return rc;
}
const char ** argv = malloc(sizeof(*argv) * argvAlloced);
int argc = 0;
int buflen = strlen(s) + 1;
- char * buf = memset(alloca(buflen), 0, buflen);
+ char *buf0 = calloc(buflen, 1);
+ char *buf = buf0;
argv[argc] = buf;
src++;
if (!*src) {
free(argv);
+ free(buf0);
return POPT_ERROR_BADQUOTE;
}
if (*src != quote) *buf++ = '\\';
src++;
if (!*src) {
free(argv);
+ free(buf0);
return POPT_ERROR_BADQUOTE;
}
/*@fallthrough@*/
(void) poptDupArgv(argc, argv, argcPtr, argvPtr);
free(argv);
-
+ free(buf0);
return 0;
}