[Python-checkins] r43124 - in python/trunk: Modules/almodule.c Modules/gcmodule.c Modules/ossaudiodev.c Modules/pyexpat.c Objects/tupleobject.c Objects/typeobject.c Python/compile.c

georg.brandl python-checkins at python.org
Fri Mar 17 20:03:43 CET 2006


Author: georg.brandl
Date: Fri Mar 17 20:03:25 2006
New Revision: 43124

Modified:
   python/trunk/Modules/almodule.c
   python/trunk/Modules/gcmodule.c
   python/trunk/Modules/ossaudiodev.c
   python/trunk/Modules/pyexpat.c
   python/trunk/Objects/tupleobject.c
   python/trunk/Objects/typeobject.c
   python/trunk/Python/compile.c
Log:
Fix some missing checks after PyTuple_New, PyList_New, PyDict_New



Modified: python/trunk/Modules/almodule.c
==============================================================================
--- python/trunk/Modules/almodule.c	(original)
+++ python/trunk/Modules/almodule.c	Fri Mar 17 20:03:25 2006
@@ -1482,7 +1482,8 @@
 	}
 	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];
@@ -1692,6 +1693,7 @@
 	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);

Modified: python/trunk/Modules/gcmodule.c
==============================================================================
--- python/trunk/Modules/gcmodule.c	(original)
+++ python/trunk/Modules/gcmodule.c	Fri Mar 17 20:03:25 2006
@@ -1085,6 +1085,8 @@
 {
 	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);

Modified: python/trunk/Modules/ossaudiodev.c
==============================================================================
--- python/trunk/Modules/ossaudiodev.c	(original)
+++ python/trunk/Modules/ossaudiodev.c	Fri Mar 17 20:03:25 2006
@@ -935,24 +935,32 @@
 
     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;
 }
 
 

Modified: python/trunk/Modules/pyexpat.c
==============================================================================
--- python/trunk/Modules/pyexpat.c	(original)
+++ python/trunk/Modules/pyexpat.c	Fri Mar 17 20:03:25 2006
@@ -1519,6 +1519,8 @@
     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)

Modified: python/trunk/Objects/tupleobject.c
==============================================================================
--- python/trunk/Objects/tupleobject.c	(original)
+++ python/trunk/Objects/tupleobject.c	Fri Mar 17 20:03:25 2006
@@ -615,6 +615,7 @@
 		}
 		else {
 			result = PyTuple_New(slicelength);
+			if (!result) return NULL;
 
 			src = self->ob_item;
 			dest = ((PyTupleObject *)result)->ob_item;

Modified: python/trunk/Objects/typeobject.c
==============================================================================
--- python/trunk/Objects/typeobject.c	(original)
+++ python/trunk/Objects/typeobject.c	Fri Mar 17 20:03:25 2006
@@ -1106,14 +1106,17 @@
 	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);

Modified: python/trunk/Python/compile.c
==============================================================================
--- python/trunk/Python/compile.c	(original)
+++ python/trunk/Python/compile.c	Fri Mar 17 20:03:25 2006
@@ -319,7 +319,9 @@
 list2dict(PyObject *list)
 {
 	Py_ssize_t i, n;
-	PyObject *v, *k, *dict = PyDict_New();
+	PyObject *v, *k;
+	PyObject *dict = PyDict_New();
+	if (!dict) return NULL;
 
 	n = PyList_Size(list);
 	for (i = 0; i < n; i++) {


More information about the Python-checkins mailing list