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