]> granicus.if.org Git - python/commitdiff
Issue #14125: Fix refleak in timemodule.c on Windows. Thanks sbt for pointing
authorStefan Krah <skrah@bytereef.org>
Mon, 27 Feb 2012 15:30:26 +0000 (16:30 +0100)
committerStefan Krah <skrah@bytereef.org>
Mon, 27 Feb 2012 15:30:26 +0000 (16:30 +0100)
out the location of the problem. MS_WINDOWS currently implies !HAVE_WCSFTIME,
so the addition of !defined(HAVE_WCSFTIME) is for readability.

Modules/timemodule.c

index 34c701984c946db7ab95fc14aa14f9489950bfe7..59fe3eef03e2650b0efd4c0424622cb2da2a4ba4 100644 (file)
@@ -540,7 +540,7 @@ time_strftime(PyObject *self, PyObject *args)
     fmt = PyBytes_AS_STRING(format);
 #endif
 
-#if defined(MS_WINDOWS)
+#if defined(MS_WINDOWS) && !defined(HAVE_WCSFTIME)
     /* check that the format string contains only valid directives */
     for(outbuf = strchr(fmt, '%');
         outbuf != NULL;
@@ -552,7 +552,8 @@ time_strftime(PyObject *self, PyObject *args)
             !strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
         {
             PyErr_SetString(PyExc_ValueError, "Invalid format string");
-            return 0;
+            Py_DECREF(format);
+            return NULL;
         }
     }
 #endif