[PATCH v2 2/3] everywhere: Change SetLastError to RestoreLastError if appropriate