From c547e7bcc59be4036a24ec81ed5b6f9d60ec5088 Mon Sep 17 00:00:00 2001 From: Davis King Date: Thu, 3 Feb 2011 22:45:24 +0000 Subject: [PATCH] Applied a patch from Nils Labugt which fixes a bug in the gui_core component (Bug ID: 3171720). The bug details are below: dlib GUI applications don't work anymore after I upgraded to Ubuntu 10.10 (AMD64). They consistently crash in base_window::set_title. XwcTextListToTextProperty returns XLocaleNotSupported instead of initializing 'property', but dlib ignores the return value, resulting in a crash in XLib when XSetWMName is called with garbage input or when property.value is XFreed without having been allocated. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404120 --- dlib/gui_core/gui_core_kernel_2.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dlib/gui_core/gui_core_kernel_2.cpp b/dlib/gui_core/gui_core_kernel_2.cpp index f3bc20341..1a2936693 100644 --- a/dlib/gui_core/gui_core_kernel_2.cpp +++ b/dlib/gui_core/gui_core_kernel_2.cpp @@ -183,7 +183,7 @@ namespace dlib { // You are supposed to call this if using XLib in a threaded program. Note - // however that at one point I nocied that calling this causes a dead-lock + // however that at one point I noticed that calling this causes a dead-lock // when using XIM. But I can't reproduce that anymore and not calling it // sometimes causes XCloseDisplay() to hang. if (XInitThreads() == 0) @@ -225,9 +225,11 @@ namespace dlib xim = NULL; window_table.get_mutex().lock(); - if (setlocale( LC_CTYPE, "" ) && XSupportsLocale() && XSetLocaleModifiers("")){ + std::string saved_locale(setlocale (LC_CTYPE, NULL)); + if (setlocale( LC_CTYPE, "" ) && XSupportsLocale() && XSetLocaleModifiers("")) xim = XOpenIM(disp, NULL, NULL, NULL); - } + else + setlocale( LC_CTYPE, saved_locale.c_str() ); window_table.get_mutex().unlock(); if (xim)