]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport SF # 669553, fix memory (ref) leaks
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 19 Jan 2003 15:48:38 +0000 (15:48 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 19 Jan 2003 15:48:38 +0000 (15:48 +0000)
Modules/pyexpat.c
Objects/intobject.c

index 44527e3af2b6dd193364aa1f3ae8dc00dbca0d9c..f8783c82430b7cacf7ca603a017949f849c7efb7 100644 (file)
@@ -1312,20 +1312,30 @@ xmlparse_getattr(xmlparseobject *self, char *name)
         Py_INCREF(self->handlers[handlernum]);
         return self->handlers[handlernum];
     }
+
+#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, PyString_FromString(handler_info[i].name));
+        for (i = 0; handler_info[i].name != NULL; i++) {
+            APPEND(rc, handler_info[i].name);
         }
-        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("ordered_attributes"));
-        PyList_Append(rc, PyString_FromString("returns_unicode"));
-        PyList_Append(rc, PyString_FromString("specified_attributes"));
-
+        APPEND(rc, "ErrorCode");
+        APPEND(rc, "ErrorLineNumber");
+        APPEND(rc, "ErrorColumnNumber");
+        APPEND(rc, "ErrorByteIndex");
+        APPEND(rc, "ordered_attributes");
+        APPEND(rc, "returns_unicode");
+        APPEND(rc, "specified_attributes");
+
+#undef APPEND
         return rc;
     }
     return Py_FindMethod(xmlparse_methods, (PyObject *)self, name);
index ee617654863db7e3477c1e6da0f676ce4dc245c6..94dc088b968148bdb3c6bef074fab72bb46fe4de 100644 (file)
@@ -649,9 +649,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);
 }