Commit 6e890b86 authored by Guido van Rossum's avatar Guido van Rossum

Save static pointer to malloc'ed buffer

parent a4403103
...@@ -149,27 +149,27 @@ extern char *getenv(); ...@@ -149,27 +149,27 @@ extern char *getenv();
char * char *
getpythonpath() getpythonpath()
{ {
#ifdef macintosh
return PYTHONPATH;
#else /* !macintosh */
char *path = getenv("PYTHONPATH"); char *path = getenv("PYTHONPATH");
char *defpath = PYTHONPATH; char *defpath = PYTHONPATH;
char *buf; static char *buf = NULL;
char *p; char *p;
int n; int n;
if (path == 0 || *path == '\0') if (path == NULL)
return defpath; path = "";
n = strlen(path) + strlen(defpath) + 2; n = strlen(path) + strlen(defpath) + 2;
if (buf != NULL) {
free(buf);
buf = NULL;
}
buf = malloc(n); buf = malloc(n);
if (buf == NULL) if (buf == NULL)
return path; /* XXX too bad -- but not likely */ fatal("not enough memory to copy module search path");
strcpy(buf, path); strcpy(buf, path);
p = buf + strlen(buf); p = buf + strlen(buf);
*p++ = DELIM; *p++ = DELIM;
strcpy(p, defpath); strcpy(p, defpath);
return buf; return buf;
#endif /* !macintosh */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment