From 38d4d4a35b9f5ba10d0343d458dd97a2a2432dae Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Fri, 2 Jun 2006 04:50:49 +0000 Subject: [PATCH] Fix memory leak found by valgrind. --- Lib/test/test_exceptions.py | 6 ++++-- Objects/exceptions.c | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 8bd385ad381..84d2798e6ea 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -265,7 +265,9 @@ class ExceptionTests(unittest.TestCase): if (e is not exc and # needed for sampleUnicode errors type(e) is not exc): raise - for checkArgName in expected.keys(): + # Verify no ref leaks in Exc_str() + s = str(e) + for checkArgName in expected: self.assertEquals(repr(getattr(e, checkArgName)), repr(expected[checkArgName]), 'exception "%s", attribute "%s"' % @@ -273,7 +275,7 @@ class ExceptionTests(unittest.TestCase): # test for pickling support new = pickle.loads(pickle.dumps(e, random.randint(0, 2))) - for checkArgName in expected.keys(): + for checkArgName in expected: self.assertEquals(repr(getattr(e, checkArgName)), repr(expected[checkArgName]), 'pickled exception "%s", attribute "%s' % diff --git a/Objects/exceptions.c b/Objects/exceptions.c index acc7da50c16..3b793074061 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -619,7 +619,6 @@ EnvironmentError_str(PyEnvironmentErrorObject *self) PyTuple_SET_ITEM(tuple, 1, Py_None); } - Py_INCREF(repr); PyTuple_SET_ITEM(tuple, 2, repr); rtnval = PyString_Format(fmt, tuple);