From: Neal Norwitz Date: Sun, 19 Jan 2003 15:48:38 +0000 (+0000) Subject: Backport SF # 669553, fix memory (ref) leaks X-Git-Tag: v2.2.3c1~167 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=583b86bd2c119d8dd100d2509475137b11fae1e2;p=thirdparty%2FPython%2Fcpython.git Backport SF # 669553, fix memory (ref) leaks --- diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index 44527e3af2b6..f8783c82430b 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -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); diff --git a/Objects/intobject.c b/Objects/intobject.c index ee617654863d..94dc088b9681 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -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); }