[New-bugs-announce] [issue20967] hashlib memory leak

Adrian Teng report at bugs.python.org
Tue Mar 18 15:03:55 CET 2014


New submission from Adrian Teng:

A particular usage pattern of hashlib will cause a memory leak.

This leaks:
import hashlib
import sys

if __name__ == '__main__':
    data_sha1 = "hello world"
    data_md5 = "hello world"
    for i in xrange(int(1e6)):
        hashlib.sha1(data_sha1)
        hashlib.md5(data_md5)

        if i % 1000 == 0:
            print sys.getrefcount(data_sha1), ",", sys.getrefcount(data_md5)

-------
this doesn't leak:

import hashlib
import sys


if __name__ == '__main__':
    data_sha1 = "hello world"
    data_md5 = "hello world"
    for i in xrange(int(1e6)):
        sha1 = hashlib.sha1()
        sha1.update(data_sha1)
		md5 = hashlib.md5()
		md5.update(data_md5)
        
        if i % 1000 == 0:
            print sys.getrefcount(data_sha1), ", ", sys.getrefcount(data_md5)


See attached for leak memory profiling in linux

----------
components: Library (Lib)
files: memoryleak_min.py
messages: 213961
nosy: ateng
priority: normal
severity: normal
status: open
title: hashlib memory leak
type: resource usage
versions: Python 2.7
Added file: http://bugs.python.org/file34489/memoryleak_min.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20967>
_______________________________________


More information about the New-bugs-announce mailing list