summaryrefslogtreecommitdiffstats
path: root/Lib/platform.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-09-18 00:27:48 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-09-18 00:27:48 (GMT)
commit74f4af7ac304baf8ea1eef95194b89982c3d683d (patch)
treeb806fd0c1a4d859f6ea6473cd8513a58a3729963 /Lib/platform.py
parent13740531279291a9f2f71dd7c7b04ddbcdda3baf (diff)
downloadcpython-74f4af7ac304baf8ea1eef95194b89982c3d683d.zip
cpython-74f4af7ac304baf8ea1eef95194b89982c3d683d.tar.gz
cpython-74f4af7ac304baf8ea1eef95194b89982c3d683d.tar.bz2
Issue #27932: Prevent memory leak in win32_ver().
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-xLib/platform.py61
1 files changed, 1 insertions, 60 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index ee315fa..e48ad0b 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -497,65 +497,6 @@ _WIN32_SERVER_RELEASES = {
(6, None): "post2012ServerR2",
}
-def _get_real_winver(maj, min, build):
- if maj < 6 or (maj == 6 and min < 2):
- return maj, min, build
-
- from ctypes import (c_buffer, POINTER, byref, create_unicode_buffer,
- Structure, WinDLL)
- from ctypes.wintypes import DWORD, HANDLE
-
- class VS_FIXEDFILEINFO(Structure):
- _fields_ = [
- ("dwSignature", DWORD),
- ("dwStrucVersion", DWORD),
- ("dwFileVersionMS", DWORD),
- ("dwFileVersionLS", DWORD),
- ("dwProductVersionMS", DWORD),
- ("dwProductVersionLS", DWORD),
- ("dwFileFlagsMask", DWORD),
- ("dwFileFlags", DWORD),
- ("dwFileOS", DWORD),
- ("dwFileType", DWORD),
- ("dwFileSubtype", DWORD),
- ("dwFileDateMS", DWORD),
- ("dwFileDateLS", DWORD),
- ]
-
- kernel32 = WinDLL('kernel32')
- version = WinDLL('version')
-
- # We will immediately double the length up to MAX_PATH, but the
- # path may be longer, so we retry until the returned string is
- # shorter than our buffer.
- name_len = actual_len = 130
- while actual_len == name_len:
- name_len *= 2
- name = create_unicode_buffer(name_len)
- actual_len = kernel32.GetModuleFileNameW(HANDLE(kernel32._handle),
- name, len(name))
- if not actual_len:
- return maj, min, build
-
- size = version.GetFileVersionInfoSizeW(name, None)
- if not size:
- return maj, min, build
-
- ver_block = c_buffer(size)
- if (not version.GetFileVersionInfoW(name, None, size, ver_block) or
- not ver_block):
- return maj, min, build
-
- pvi = POINTER(VS_FIXEDFILEINFO)()
- if not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())):
- return maj, min, build
-
- maj = pvi.contents.dwProductVersionMS >> 16
- min = pvi.contents.dwProductVersionMS & 0xFFFF
- build = pvi.contents.dwProductVersionLS >> 16
-
- return maj, min, build
-
def win32_ver(release='', version='', csd='', ptype=''):
try:
from sys import getwindowsversion
@@ -567,7 +508,7 @@ def win32_ver(release='', version='', csd='', ptype=''):
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
winver = getwindowsversion()
- maj, min, build = _get_real_winver(*winver[:3])
+ maj, min, build = winver.platform_version or winver[:3]
version = '{0}.{1}.{2}'.format(maj, min, build)
release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or