From c00b2271e6295c248c18d1bd62e14df372004e85 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Oct 2006 18:20:49 +0200 Subject: * progress.cc: - fix memleak in progress.cc * tests/memleak.py: - uncomment the mem-leak code * doc/examples/sources.py: - improved the example --- debian/changelog | 4 +++- doc/examples/sources.py | 2 +- python/progress.cc | 10 +++++++--- tests/memleak.py | 14 +++++++++----- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index 21cbd6a8..1979f75d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,8 +12,10 @@ python-apt (0.6.20) unstable; urgency=low - fix missing docstring (closes: #368907), Thanks to Josh Triplett * make it build against python2.5 + * python/progress.cc: + - fix memleak (lp: #43096) - -- + -- Michael Vogt Mon, 2 Oct 2006 17:29:49 +0200 python-apt (0.6.19) unstable; urgency=low diff --git a/doc/examples/sources.py b/doc/examples/sources.py index c12c6f15..b48c0ba5 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -12,4 +12,4 @@ sources.Restart() while sources.Lookup('hello'): print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` print sources.Files - print sources.Index.ArchiveURI("") + print sources.Index.ArchiveURI(sources.Files[0][2]) diff --git a/python/progress.cc b/python/progress.cc index f00058c9..df9c2ec1 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -18,8 +18,10 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, PyObject *arglist, PyObject **res) { - if(callbackInst == 0) + if(callbackInst == 0) { + Py_XDECREF(arglist); return false; + } PyObject *method = PyObject_GetAttrString(callbackInst,(char*) method_name); if(method == NULL) { @@ -49,22 +51,24 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, // OpProgress interface -// FIXME: add "string Op, string SubOp" as attribute to the callbackInst void PyOpProgress::Update() { - PyObject *o; o = Py_BuildValue("s", Op.c_str()); PyObject_SetAttrString(callbackInst, "op", o); + Py_XDECREF(o); o = Py_BuildValue("s", SubOp.c_str()); PyObject_SetAttrString(callbackInst, "subOp", o); + Py_XDECREF(o); o = Py_BuildValue("b", MajorChange); PyObject_SetAttrString(callbackInst, "majorChange", o); + Py_XDECREF(o); // Build up the argument list... PyObject *arglist = Py_BuildValue("(f)", Percent); if(CheckChange(0.05)) RunSimpleCallback("update", arglist); + Py_XDECREF(arglist); }; void PyOpProgress::Done() diff --git a/tests/memleak.py b/tests/memleak.py index 3e59cbb7..b5d05afc 100755 --- a/tests/memleak.py +++ b/tests/memleak.py @@ -10,11 +10,15 @@ import sys cache = apt.Cache() # memleak -#for i in range(100): -# cache.open(None) -# print cache["apt"].name -# time.sleep(1) -# gc.collect() +for i in range(100): + cache.open(None) + print cache["apt"].name + time.sleep(1) + gc.collect() + f = open("%s" % i,"w") + for obj in gc.get_objects(): + f.write("%s\n" % str(obj)) + f.close() # memleak #for i in range(100): -- cgit v1.2.3