Commits

Georg Brandl committed e43d5d2

Backport: Fix missing NULL checks after PyTuple_New, PyList_New, PyDict_New

  • Participants
  • Parent commits 82f700f
  • Branches 2.4

Comments (0)

Files changed (6)

File Modules/almodule.c

 	}
 	if (alGetParams(resource, pvs, npvs) < 0)
 		goto error;
-	v = PyList_New(npvs);
+	if (!(v = PyList_New(npvs)))
+		goto error;
 	for (i = 0; i < npvs; i++) {
 		if (pvs[i].sizeOut < 0) {
 			char buf[32];
 	if (alGetParamInfo(res, param, &pinfo) < 0)
 		return NULL;
 	v = PyDict_New();
+	if (!v) return NULL;
 
 	item = PyInt_FromLong((long) pinfo.resource);
 	PyDict_SetItemString(v, "resource", item);

File Modules/gcmodule.c

 {
 	int i;
 	PyObject *result = PyList_New(0);
+	if (!result) return NULL;
 	for (i = 0; i < NUM_GENERATIONS; i++) {
 		if (!(gc_referrers_for(args, GEN_HEAD(i), result))) {
 			Py_DECREF(result);

File Modules/ossaudiodev.c

 
     labels = PyList_New(num_controls);
     names = PyList_New(num_controls);
+    if (labels == NULL || names == NULL)
+        goto error2;
     for (i = 0; i < num_controls; i++) {
         s = PyString_FromString(control_labels[i]);
         if (s == NULL)
-            return -1;
+            goto error2;
         PyList_SET_ITEM(labels, i, s);
 
         s = PyString_FromString(control_names[i]);
         if (s == NULL)
-            return -1;
+            goto error2;
         PyList_SET_ITEM(names, i, s);
     }
 
     if (PyModule_AddObject(module, "control_labels", labels) == -1)
-        return -1;
+        goto error2;
     if (PyModule_AddObject(module, "control_names", names) == -1)
-        return -1;
+        goto error1;
 
     return 0;
+
+error2:
+    Py_XDECREF(labels);
+error1:
+    Py_XDECREF(names);
+    return -1;
 }
 
 

File Modules/pyexpat.c

             return self->intern;
         }
     }
-
+    
 #define APPEND(list, str)				\
         do {						\
                 PyObject *o = PyString_FromString(str);	\
     if (strcmp(name, "__members__") == 0) {
         int i;
         PyObject *rc = PyList_New(0);
+	if (!rc)
+		return NULL;
         for (i = 0; handler_info[i].name != NULL; i++) {
             PyObject *o = get_handler_name(&handler_info[i]);
             if (o != NULL)

File Objects/tupleobject.c

 		}
 		else {
 			result = PyTuple_New(slicelength);
+			if (!result) return NULL;
 
 			src = self->ob_item;
 			dest = ((PyTupleObject *)result)->ob_item;

File Objects/typeobject.c

 	char buf[1000];
 	PyObject *k, *v;
 	PyObject *set = PyDict_New();
+	if (!set) return;
 
 	to_merge_size = PyList_GET_SIZE(to_merge);
 	for (i = 0; i < to_merge_size; i++) {
 		PyObject *L = PyList_GET_ITEM(to_merge, i);
 		if (remain[i] < PyList_GET_SIZE(L)) {
 			PyObject *c = PyList_GET_ITEM(L, remain[i]);
-			if (PyDict_SetItem(set, c, Py_None) < 0)
+			if (PyDict_SetItem(set, c, Py_None) < 0) {
+				Py_DECREF(set);
 				return;
+			}
 		}
 	}
 	n = PyDict_Size(set);