Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 87137) +++ Modules/posixmodule.c (working copy) @@ -2763,29 +2763,32 @@ if(hFile == INVALID_HANDLE_VALUE) { return win32_error_unicode("GetFinalPathNamyByHandle", path); - return PyErr_Format(PyExc_RuntimeError, - "Could not get a handle to file."); } /* We have a good handle to the target, use it to determine the target path name. */ buf_size = Py_GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT); - if(!buf_size) + if(!buf_size) { + CloseHandle(hFile); return win32_error_unicode("GetFinalPathNameByHandle", path); + } target_path = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t)); - if(!target_path) + if(!target_path) { + CloseHandle(hFile); return PyErr_NoMemory(); + } result_length = Py_GetFinalPathNameByHandleW(hFile, target_path, buf_size, VOLUME_NAME_DOS); - if(!result_length) + CloseHandle(hFile); + + if(!result_length) { + free(target_path); return win32_error_unicode("GetFinalPathNamyByHandle", path); + } - if(!CloseHandle(hFile)) - return win32_error_unicode("GetFinalPathNameByHandle", path); - target_path[result_length] = 0; result = PyUnicode_FromUnicode(target_path, result_length); free(target_path);