Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: src/gpu/GrAutoLocaleSetter.h

Issue 1514083002: Fix intermittent GrAutoLocaleSetter crashes on Windows (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review comment Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAutoLocaleSetter.h
diff --git a/src/gpu/GrAutoLocaleSetter.h b/src/gpu/GrAutoLocaleSetter.h
index 51164e9813a056016a4a71a26855cc315a4ad6e4..08196debf61ba30d9109add414e68253a732995f 100644
--- a/src/gpu/GrAutoLocaleSetter.h
+++ b/src/gpu/GrAutoLocaleSetter.h
@@ -10,6 +10,10 @@
#include "GrTypes.h"
+#if defined(SK_BUILD_FOR_WIN)
+#include "SkString.h"
+#endif
+
#if !defined(SK_BUILD_FOR_ANDROID)
#include <locale.h>
#endif
@@ -26,8 +30,14 @@ class GrAutoLocaleSetter : public SkNoncopyable {
public:
GrAutoLocaleSetter (const char* name) {
#if defined(SK_BUILD_FOR_WIN)
- fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
- fOldLocale = setlocale(LC_ALL, name);
+ fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
+ char* oldLocale = setlocale(LC_ALL, name);
+ if (oldLocale) {
+ fOldLocale = oldLocale;
+ fShouldRestoreLocale = true;
+ } else {
+ fShouldRestoreLocale = false;
+ }
#elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
fLocale = newlocale(LC_ALL, name, 0);
if (fLocale) {
@@ -42,8 +52,8 @@ public:
~GrAutoLocaleSetter () {
#if defined(SK_BUILD_FOR_WIN)
- if (fOldLocale) {
- setlocale(LC_ALL, fOldLocale);
+ if (fShouldRestoreLocale) {
+ setlocale(LC_ALL, fOldLocale.c_str());
}
_configthreadlocale(fOldPerThreadLocale);
#elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
@@ -57,7 +67,8 @@ public:
private:
#if defined(SK_BUILD_FOR_WIN)
int fOldPerThreadLocale;
- const char* fOldLocale;
+ bool fShouldRestoreLocale;
+ SkString fOldLocale;
#elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
locale_t fOldLocale;
locale_t fLocale;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698