summaryrefslogtreecommitdiff
path: root/libs/pbd/locale_guard.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pbd/locale_guard.cc')
-rw-r--r--libs/pbd/locale_guard.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/libs/pbd/locale_guard.cc b/libs/pbd/locale_guard.cc
index 7d6c0708b8..30fdeadeba 100644
--- a/libs/pbd/locale_guard.cc
+++ b/libs/pbd/locale_guard.cc
@@ -8,15 +8,22 @@ using namespace PBD;
LocaleGuard::LocaleGuard (const char* str)
{
- old = strdup (setlocale (LC_NUMERIC, NULL));
- if (strcmp (old, str)) {
- setlocale (LC_NUMERIC, str);
- }
+ old = setlocale (LC_NUMERIC, NULL);
+
+ if (old) {
+ old = strdup (old);
+ if (strcmp (old, str)) {
+ setlocale (LC_NUMERIC, str);
+ }
+ }
}
LocaleGuard::~LocaleGuard ()
{
setlocale (LC_NUMERIC, old);
- free ((char*)old);
+
+ if (old) {
+ free ((char*)old);
+ }
}