]> granicus.if.org Git - python/commitdiff
add missing NULL check
authorBenjamin Peterson <benjamin@python.org>
Mon, 14 Apr 2014 23:57:52 +0000 (19:57 -0400)
committerBenjamin Peterson <benjamin@python.org>
Mon, 14 Apr 2014 23:57:52 +0000 (19:57 -0400)
Modules/posixmodule.c

index 7a5ef1cab3045cd4c467ca7bc8724c2000645b76..cd4672cbb159d5a5b2e1aa3330ab20fcf22f80c5 100644 (file)
@@ -6856,13 +6856,17 @@ posix_fdopen(PyObject *self, PyObject *args)
 #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
     {
         struct stat buf;
+        const char *msg;
+        PyObject *exc;
         if (fstat(fd, &buf) == 0 && S_ISDIR(buf.st_mode)) {
             PyMem_FREE(mode);
-            char *msg = strerror(EISDIR);
-            PyObject *exc = PyObject_CallFunction(PyExc_IOError, "(isO)",
-                                                  EISDIR, msg, "<fdopen>");
-            PyErr_SetObject(PyExc_IOError, exc);
-            Py_XDECREF(exc);
+            msg = strerror(EISDIR);
+            exc = PyObject_CallFunction(PyExc_IOError, "(isO)",
+                                        EISDIR, msg, "<fdopen>");
+            if (exc) {
+                PyErr_SetObject(PyExc_IOError, exc);
+                Py_DECREF(exc);
+            }
             return NULL;
         }
     }