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

Skip to content

Commit 42a9744

Browse files
committed
Fix some outdated comments (mostly by removing a large comment block
that was only causing confusing). Add free(userpath) and free(machinepath) statements to prevent some leaks.
1 parent 6eb1f6b commit 42a9744

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

PC/getpathp.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,12 @@ extern BOOL PyWin_IsWin32s();
4949
#endif /* HAVE_UNISTD_H */
5050

5151
/* Search in some common locations for the associated Python libraries.
52-
*
53-
* This version always returns "" for both prefix and exec_prefix.
5452
*
5553
* Py_GetPath() tries to return a sensible Python module search path.
5654
*
57-
* First, we look to see if the executable is in a subdirectory of
58-
* the Python build directory. We calculate the full path of the
59-
* directory containing the executable as progpath. We work backwards
60-
* along progpath and look for $dir/Modules/Setup.in, a distinctive
61-
* landmark. If found, we use $dir/Lib as $root. The returned
62-
* Python path is the compiled #define PYTHONPATH with all the initial
63-
* "./lib" replaced by $root.
64-
*
65-
* Otherwise, if there is a PYTHONPATH environment variable, we return that.
66-
*
67-
* Otherwise we try to find $progpath/lib/string.py, and if found, then
68-
* root is $progpath/lib, and we return Python path as compiled PYTHONPATH
69-
* with all "./lib" replaced by $root (as above).
70-
*
55+
* The approach is an adaptation for Windows of the strategy used in
56+
* ../Modules/getpath.c; it uses the Windows Registry as one of its
57+
* information sources.
7158
*/
7259

7360
#ifndef LANDMARK
@@ -395,6 +382,12 @@ calculate_path()
395382
fprintf(stderr, "Using environment $PYTHONPATH.\n");
396383
module_search_path = PYTHONPATH;
397384
}
385+
#ifdef MS_WIN32
386+
if (machinepath)
387+
free(machinepath);
388+
if (userpath)
389+
free(userpath);
390+
#endif /* MS_WIN32 */
398391
return;
399392
}
400393

@@ -408,11 +401,13 @@ calculate_path()
408401
strcpy(buf, machinepath);
409402
buf = strchr(buf, '\0');
410403
*buf++ = DELIM;
404+
free(machinepath);
411405
}
412406
if (userpath) {
413407
strcpy(buf, userpath);
414408
buf = strchr(buf, '\0');
415409
*buf++ = DELIM;
410+
free(userpath);
416411
}
417412
#endif
418413
if (pythonhome == NULL) {

0 commit comments

Comments
 (0)