[pypy-commit] pypy rgc-mem-pressure: fix hashlib's copy() leak

justinpeel noreply at buildbot.pypy.org
Thu Oct 20 20:00:09 CEST 2011


Author: Justin Peel <notmuchtotell at gmail.com>
Branch: rgc-mem-pressure
Changeset: r48278:38375b2c1ddb
Date: 2011-10-20 11:57 -0600
http://bitbucket.org/pypy/pypy/changeset/38375b2c1ddb/

Log:	fix hashlib's copy() leak

diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py
--- a/pypy/module/_hashlib/interp_hashlib.py
+++ b/pypy/module/_hashlib/interp_hashlib.py
@@ -30,15 +30,17 @@
         # and use a custom lock only when needed.
         self.lock = Lock(space)
 
-        digest = ropenssl.EVP_get_digestbyname(name)
-        if not digest:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("unknown hash function"))
         ctx = lltype.malloc(ropenssl.EVP_MD_CTX.TO, flavor='raw')
-        ropenssl.EVP_DigestInit(ctx, digest)
         rgc.add_memory_pressure(HASH_MALLOC_SIZE + self._digest_size())
         self.ctx = ctx
 
+    def initdigest(self):
+        digest = ropenssl.EVP_get_digestbyname(self.name)
+        if not digest:
+            raise OperationError(space.w_Value,
+                                 space.wrap("unknown hash function"))
+        ropenssl.EVP_DigestInit(self.ctx, digest)
+
     def __del__(self):
         # self.lock.free()
         if self.ctx:
@@ -139,6 +141,7 @@
 @unwrap_spec(name=str, string='bufferstr')
 def new(space, name, string=''):
     w_hash = W_Hash(space, name)
+    w_hash.initdigest()
     w_hash.update(space, string)
     return space.wrap(w_hash)
 


More information about the pypy-commit mailing list