X11 msgbox: try to protect the existing setlocale() state.

This commit is contained in:
Ryan C. Gordon 2012-12-07 23:26:28 -05:00
parent 2c1f08ae4b
commit f34e7b4ce0

View file

@ -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;
}