]> granicus.if.org Git - python/commitdiff
Fix [ 776721 ] locale.setlocale() leaks
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 24 Jul 2003 14:15:07 +0000 (14:15 +0000)
committerMark Hammond <mhammond@skippinet.com.au>
Thu, 24 Jul 2003 14:15:07 +0000 (14:15 +0000)
Our saved locale was not being freed.  Also check correct variable for
NULL.

Modules/_localemodule.c

index 840f8385f20668dae899d8326ce59db8be2eb77d..263e88179ef792b515655398d93b9c2f7145d69c 100644 (file)
@@ -181,7 +181,7 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
             return NULL;
         }
         result_object = PyString_FromString(result);
-        if (!result)
+        if (!result_object)
             return NULL;
         /* record changes to LC_NUMERIC */
         if (category == LC_NUMERIC || category == LC_ALL) {
@@ -199,6 +199,8 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
                 thousands_sep = PyString_FromString(lc->thousands_sep);
                 Py_XDECREF(decimal_point);
                 decimal_point = PyString_FromString(lc->decimal_point);
+                if (saved_numeric)
+                    free(saved_numeric);
                 saved_numeric = strdup(locale);
                 /* restore to "C" */
                 setlocale(LC_NUMERIC, "C");