Skip to content

(Windows) CloseHandle() can override GetLastError() #1370

Closed
@ReneGrellert

Description

Hi,

we've disvovered the following behaviour in the following code of psutil_proc_create_time:

if (! GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) {
    CloseHandle(hProcess);
    if (GetLastError() == ERROR_ACCESS_DENIED) {
        // usually means the process has died so we throw a
        // NoSuchProcess here
        return NoSuchProcess("");
    }
    else {
        return PyErr_SetFromWindowsErr(0);
    }
}

We think, that CloseHandle resets the error stored in "GetLastError". This leads to "return PyErr_SetFromWindowsErr(0)" returning the Error raised in CloseHandle instead of the one of "GetProcessTimes".

We got there from another error, we could not understand:

File "psutil\__init__.pyo" line 1440, in process_iter
File "psutil\__init__.pyo" line 569, in is_running
File "psutil\__init__.pyo" line 340, in __init__
File "psutil\__init__.pyo" line 367, in _init
File "psutil\__init__.pyo" line 698, in wrapper
File "psutil\__init__.pyo" line 846, in create_time
WindowsError: [Error 0]

Sometimes, there is an Error 2 instead. Maybe this comes from CloseHandle, since the handle might not
be valid any more.

This problem occures with
python 2.7
pyutil 5.4.5
On Windows 7, 64 bit

Best regards,
René

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions