]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #15219: Fix a reference leak when hashlib.new() is called with
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 28 Jun 2012 23:42:46 +0000 (01:42 +0200)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 28 Jun 2012 23:42:46 +0000 (01:42 +0200)
invalid parameters.

Lib/test/test_hashlib.py
Misc/NEWS
Modules/_hashopenssl.c

index 855ecbfb4e4af4dab55072f2a19841669eb2b168..95bf0b347c59deb1b90aff5070b0bc33466f3d43 100644 (file)
@@ -108,12 +108,8 @@ class HashLibTestCase(unittest.TestCase):
                                                 _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__[
index aa41678e73a26b1bbbda05a15acdf1c3b8a6a651..09ea7e3b9db1b424d45937d009666838b0d38a84 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -75,6 +75,9 @@ Core and Builtins
 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.
index aa9dd4e775f2cd7a159bdb2f39b75b19a67f66bb..7f016d4bdcb9fda6476ad25b0c8c20f0b0198d97 100644 (file)
@@ -477,6 +477,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
     }
 
     if (!PyArg_Parse(name_obj, "s", &name)) {
+        PyBuffer_Release(&view);
         PyErr_SetString(PyExc_TypeError, "name must be a string");
         return NULL;
     }