[Python-checkins] cpython (2.7): Issue #15219: Fix a reference leak when hashlib.new() is called with

amaury.forgeotdarc python-checkins at python.org
Fri Jun 29 01:45:55 CEST 2012


http://hg.python.org/cpython/rev/49dee01d72f9
changeset:   77838:49dee01d72f9
branch:      2.7
parent:      77832:c37cb11b546f
user:        Amaury Forgeot d'Arc <amauryfa at gmail.com>
date:        Fri Jun 29 01:42:46 2012 +0200
summary:
  Issue #15219: Fix a reference leak when hashlib.new() is called with
invalid parameters.

files:
  Lib/test/test_hashlib.py |  8 ++------
  Misc/NEWS                |  3 +++
  Modules/_hashopenssl.c   |  1 +
  3 files changed, 6 insertions(+), 6 deletions(-)


diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -108,12 +108,8 @@
                                                 _algo.islower()]))
 
     def test_unknown_hash(self):
-        try:
-            hashlib.new('spam spam spam spam spam')
-        except ValueError:
-            pass
-        else:
-            self.assertTrue(0 == "hashlib didn't reject bogus hash name")
+        self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')
+        self.assertRaises(TypeError, hashlib.new, 1)
 
     def test_get_builtin_constructor(self):
         get_builtin_constructor = hashlib.__dict__[
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -75,6 +75,9 @@
 Library
 -------
 
+- Issue #15219: Fix a reference leak when hashlib.new() is called with
+  invalid parameters.
+
 - Issue #9559: If messages were only added, a new file is no longer
   created and renamed over the old file when flush() is called on an
   mbox, MMDF or Babyl mailbox.
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -477,6 +477,7 @@
     }
 
     if (!PyArg_Parse(name_obj, "s", &name)) {
+        PyBuffer_Release(&view);
         PyErr_SetString(PyExc_TypeError, "name must be a string");
         return NULL;
     }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list