]> granicus.if.org Git - python/commitdiff
SF # 669553, fix memory (ref) leaks
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 19 Jan 2003 15:40:09 +0000 (15:40 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 19 Jan 2003 15:40:09 +0000 (15:40 +0000)
Will backport.

Modules/pyexpat.c
Objects/intobject.c

index f74751ba616a1cb91f0be0ed27e2859039762107..7e54f0e74806228fdd6b9a828c9430f2a6f8b477 100644 (file)
@@ -1332,24 +1332,36 @@ xmlparse_getattr(xmlparseobject *self, char *name)
         }
     }
 
+#define APPEND(list, str)                              \
+       do {                                            \
+               PyObject *o = PyString_FromString(str); \
+               if (o != NULL)                          \
+                       PyList_Append(list, o);         \
+               Py_XDECREF(o);                          \
+       } while (0)
+
     if (strcmp(name, "__members__") == 0) {
         int i;
         PyObject *rc = PyList_New(0);
         for (i = 0; handler_info[i].name != NULL; i++) {
-            PyList_Append(rc, get_handler_name(&handler_info[i]));
+            PyObject *o = get_handler_name(&handler_info[i]);
+            if (o != NULL)
+                PyList_Append(rc, o);
+            Py_XDECREF(o);
         }
-        PyList_Append(rc, PyString_FromString("ErrorCode"));
-        PyList_Append(rc, PyString_FromString("ErrorLineNumber"));
-        PyList_Append(rc, PyString_FromString("ErrorColumnNumber"));
-        PyList_Append(rc, PyString_FromString("ErrorByteIndex"));
-        PyList_Append(rc, PyString_FromString("buffer_size"));
-        PyList_Append(rc, PyString_FromString("buffer_text"));
-        PyList_Append(rc, PyString_FromString("buffer_used"));
-        PyList_Append(rc, PyString_FromString("ordered_attributes"));
-        PyList_Append(rc, PyString_FromString("returns_unicode"));
-        PyList_Append(rc, PyString_FromString("specified_attributes"));
-        PyList_Append(rc, PyString_FromString("intern"));
-
+        APPEND(rc, "ErrorCode");
+        APPEND(rc, "ErrorLineNumber");
+        APPEND(rc, "ErrorColumnNumber");
+        APPEND(rc, "ErrorByteIndex");
+        APPEND(rc, "buffer_size");
+        APPEND(rc, "buffer_text");
+        APPEND(rc, "buffer_used");
+        APPEND(rc, "ordered_attributes");
+        APPEND(rc, "returns_unicode");
+        APPEND(rc, "specified_attributes");
+        APPEND(rc, "intern");
+
+#undef APPEND
         return rc;
     }
     return Py_FindMethod(xmlparse_methods, (PyObject *)self, name);
index d9e4d317c1fa124fac7081dbaeaa9efb978df26c..805f3b7a28add46e70abf00f19f41258345a1c15 100644 (file)
@@ -606,9 +606,16 @@ int_neg(PyIntObject *v)
        a = v->ob_ival;
        x = -a;
        if (a < 0 && x < 0) {
+               PyObject *o;
                if (err_ovf("integer negation"))
                        return NULL;
-               return PyNumber_Negative(PyLong_FromLong(a));
+               o = PyLong_FromLong(a);
+               if (o != NULL) {
+                       PyObject *result = PyNumber_Negative(o);
+                       Py_DECREF(o);
+                       return result;
+               }
+               return NULL;
        }
        return PyInt_FromLong(x);
 }