diff Objects/unicodeobject.c @ 36878:accfb156f9cc 2.4

Backport r42894: SF #1444030 Fix several potential defects found by Coverity.
author Hye-Shik Chang <hyeshik@gmail.com>
date Tue, 07 Mar 2006 15:59:09 +0000
parents 76a1c20e830e
children bc5161f292b7
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Tue Mar 07 14:16:02 2006 +0000
+++ b/Objects/unicodeobject.c	Tue Mar 07 15:59:09 2006 +0000
@@ -1866,16 +1866,16 @@
             message = "malformed \\N character escape";
             if (ucnhash_CAPI == NULL) {
                 /* load the unicode data module */
-                PyObject *m, *v;
+                PyObject *m, *api;
                 m = PyImport_ImportModule("unicodedata");
                 if (m == NULL)
                     goto ucnhashError;
-                v = PyObject_GetAttrString(m, "ucnhash_CAPI");
+                api = PyObject_GetAttrString(m, "ucnhash_CAPI");
                 Py_DECREF(m);
-                if (v == NULL)
+                if (api == NULL)
                     goto ucnhashError;
-                ucnhash_CAPI = PyCObject_AsVoidPtr(v);
-                Py_DECREF(v);
+                ucnhash_CAPI = PyCObject_AsVoidPtr(api);
+                Py_DECREF(api);
                 if (ucnhash_CAPI == NULL)
                     goto ucnhashError;
             }
@@ -1935,6 +1935,7 @@
         PyExc_UnicodeError,
         "\\N escapes not supported (can't load unicodedata module)"
         );
+    Py_XDECREF(v);
     Py_XDECREF(errorHandler);
     Py_XDECREF(exc);
     return NULL;
@@ -3911,7 +3912,7 @@
 	return -1;
     substr = PyUnicode_FromObject(substr);
     if (substr == NULL) {
-	Py_DECREF(substr);
+	Py_DECREF(str);
 	return -1;
     }
 
@@ -4382,7 +4383,7 @@
     return list;
 
  onError:
-    Py_DECREF(list);
+    Py_XDECREF(list);
     Py_DECREF(string);
     return NULL;
 }
@@ -6627,6 +6628,10 @@
 	if (!str)
 		return NULL;
 	result = _PyUnicode_New(len);
+	if (!result) {
+		Py_DECREF(str);
+		return NULL;
+	}
 	for (i = 0; i < len; i++)
 		result->str[i] = buf[i];
 	result->str[len] = 0;
@@ -6813,7 +6818,7 @@
 		rescnt = fmtcnt + 100;
 		reslen += rescnt;
 		if (_PyUnicode_Resize(&result, reslen) < 0)
-		    return NULL;
+		    goto onError;
 		res = PyUnicode_AS_UNICODE(result) + reslen - rescnt;
 		--rescnt;
 	    }
@@ -7111,6 +7116,7 @@
 		rescnt = width + fmtcnt + 100;
 		reslen += rescnt;
 		if (reslen < 0) {
+		    Py_XDECREF(temp);
 		    Py_DECREF(result);
 		    return PyErr_NoMemory();
 		}