]> granicus.if.org Git - python/commitdiff
Fix some missing checks after PyTuple_New, PyList_New, PyDict_New
authorGeorg Brandl <georg@python.org>
Fri, 17 Mar 2006 19:03:25 +0000 (19:03 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 17 Mar 2006 19:03:25 +0000 (19:03 +0000)
Modules/almodule.c
Modules/gcmodule.c
Modules/ossaudiodev.c
Modules/pyexpat.c
Objects/tupleobject.c
Objects/typeobject.c
Python/compile.c

index 5254fca18eb4b25cfc8c220f964f75ec4e441a2a..fbeb13a630245bdc40f0f5c3486468f857159164 100644 (file)
@@ -1482,7 +1482,8 @@ al_GetParams(PyObject *self, PyObject *args)
        }
        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 @@ al_GetParamInfo(PyObject *self, PyObject *args)
        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);
index 7e3f95a4cad1e536b410741bffa222899f4be504..3d49f6cf5c05dbca3523ac64337c235e687ff4aa 100644 (file)
@@ -1085,6 +1085,8 @@ gc_get_referrers(PyObject *self, PyObject *args)
 {
        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);
index ce8a0d07c1df2df29e3fc02f91326fe0e571c1fb..563620cbea3f993c11ce33f19d2ec8c2a3285e81 100644 (file)
@@ -935,24 +935,32 @@ build_namelists (PyObject *module)
 
     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;
 }
 
 
index e4bf180a6ad0770603d184bc4fe9171dd6f427e0..b6e927d32cd583621a795769890c4e8caa995479 100644 (file)
@@ -1519,6 +1519,8 @@ xmlparse_getattr(xmlparseobject *self, char *name)
     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)
index 384b355a10eb0d5798113ea1facfcb044503de76..c16c71a154c412f0f60f58658c190bd259f41d50 100644 (file)
@@ -615,6 +615,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
                }
                else {
                        result = PyTuple_New(slicelength);
+                       if (!result) return NULL;
 
                        src = self->ob_item;
                        dest = ((PyTupleObject *)result)->ob_item;
index 65bf404a3d2aa072bca5cd200748599d9850309f..e45a480822a9646bdaaaacca82ab6200b15faf5c 100644 (file)
@@ -1106,14 +1106,17 @@ set_mro_error(PyObject *to_merge, int *remain)
        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);
index baf3989a9d2a434473eb531ead23f9ebb4092ae4..1217c1e6aa88a88ce946533263486a642769140e 100644 (file)
@@ -319,7 +319,9 @@ static PyObject *
 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++) {