Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e890b8

Browse files
committed
Save static pointer to malloc'ed buffer
1 parent a440310 commit 6e890b8

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Modules/config.c.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,27 @@ extern char *getenv();
149149
char *
150150
getpythonpath()
151151
{
152-
#ifdef macintosh
153-
return PYTHONPATH;
154-
#else /* !macintosh */
155152
char *path = getenv("PYTHONPATH");
156153
char *defpath = PYTHONPATH;
157-
char *buf;
154+
static char *buf = NULL;
158155
char *p;
159156
int n;
160157

161-
if (path == 0 || *path == '\0')
162-
return defpath;
158+
if (path == NULL)
159+
path = "";
163160
n = strlen(path) + strlen(defpath) + 2;
161+
if (buf != NULL) {
162+
free(buf);
163+
buf = NULL;
164+
}
164165
buf = malloc(n);
165166
if (buf == NULL)
166-
return path; /* XXX too bad -- but not likely */
167+
fatal("not enough memory to copy module search path");
167168
strcpy(buf, path);
168169
p = buf + strlen(buf);
169170
*p++ = DELIM;
170171
strcpy(p, defpath);
171172
return buf;
172-
#endif /* !macintosh */
173173
}
174174

175175

0 commit comments

Comments
 (0)