Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa40f92

Browse files
izbyshevzhangyangyu
authored andcommitted
[2.7] bpo-32903: Fix a memory leak in os.chdir() on Windows (pythonGH-5801). (python#5947)
(cherry picked from commit3e197c7)Co-authored-by: Alexey Izbyshev <izbyshev@users.noreply.github.com>
1 parentc20c97f commitaa40f92

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a memory leak in os.chdir() on Windows if the current directory is set
2+
to a UNC path.

‎Modules/posixmodule.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ win32_wchdir(LPCWSTR path)
984984
wchar_t_new_path[MAX_PATH+1],*new_path=_new_path;
985985
intresult;
986986
wchar_tenv[4]=L"=x:";
987+
intis_unc_like_path;
987988

988989
if(!SetCurrentDirectoryW(path))
989990
return FALSE;
@@ -1002,15 +1003,15 @@ win32_wchdir(LPCWSTR path)
10021003
return FALSE;
10031004
}
10041005
}
1005-
if (wcsncmp(new_path,L"\\\\",2)==0||
1006-
wcsncmp(new_path,L"//",2)==0)
1007-
/* UNC path, nothing to do. */
1008-
return TRUE;
1009-
env[1]=new_path[0];
1010-
result=SetEnvironmentVariableW(env,new_path);
1006+
is_unc_like_path= (wcsncmp(new_path,L"\\\\",2)==0||
1007+
wcsncmp(new_path,L"//",2)==0);
1008+
if (!is_unc_like_path) {
1009+
env[1]=new_path[0];
1010+
result=SetEnvironmentVariableW(env,new_path);
1011+
}
10111012
if (new_path!=_new_path)
10121013
free(new_path);
1013-
returnresult;
1014+
returnresult ? TRUE : FALSE;
10141015
}
10151016
#endif
10161017

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp