From 8804e511137e9b5c27ce850aab0808281c87708c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 7 Dec 2012 23:26:28 -0500 Subject: [PATCH] X11 msgbox: try to protect the existing setlocale() state. --- src/video/x11/SDL_x11messagebox.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index afb51adef..e1fee224d 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -654,14 +654,23 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) { int ret; SDL_MessageBoxDataX11 data; + char *origlocale; SDL_zero(data); - setlocale(LC_ALL, ""); - if ( !SDL_X11_LoadSymbols() ) return -1; + origlocale = setlocale(LC_ALL, NULL); + if (origlocale != NULL) { + origlocale = SDL_strdup(origlocale); + if (origlocale == NULL) { + SDL_OutOfMemory(); + return -1; + } + setlocale(LC_ALL, ""); + } + /* This code could get called from multiple threads maybe? */ XInitThreads(); @@ -681,6 +690,12 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) } X11_MessageBoxShutdown( &data ); + + if (origlocale) { + setlocale(LC_ALL, origlocale); + SDL_free(origlocale); + } + return ret; }