Skip to content

Commit 3db6fc1

Browse files
thehesiodasvetlov
authored andcommitted
leakfix (#106)
* fix from @gpfei #105 * add leak test * add missing req
1 parent 7476da0 commit 3db6fc1

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

multidict/_istr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static PyMethodDef istr_methods[] = {
6767
void istr_dealloc(istrobject *self)
6868
{
6969
Py_XDECREF(self->canonical);
70+
PyUnicode_Type.tp_dealloc((PyObject*)self);
7071
}
7172

7273
static PyObject *

requirements-ci.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ tox==2.7.0
99
sphinxcontrib-newsfeed==0.1.4
1010
pytest-cov==2.5.1
1111
pygments==2.2.0
12+
psutil==5.2.2
1213
-e .

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pytest-sugar==0.8.0
44
ipython==6.1.0
55
pyenchant==1.6.8
66
sphinxcontrib-spelling==2.3.0
7+
psutil==5.2.2

tests/test_istr.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from multidict._multidict import istr
22
from multidict._multidict_py import istr as _istr
3+
import gc
4+
import psutil
35

46

57
class IStrMixin:
@@ -52,6 +54,24 @@ def xtest_eq(self):
5254
class TestPyIStr(IStrMixin):
5355
cls = _istr
5456

57+
@staticmethod
58+
def _create_strs():
59+
_istr('foobarbaz')
60+
istr2 = _istr()
61+
_istr(istr2)
62+
63+
def test_leak(self):
64+
gc.collect()
65+
p = psutil.Process()
66+
info = p.memory_info()
67+
for _ in range(10000):
68+
self._create_strs()
69+
70+
gc.collect()
71+
info2 = p.memory_info()
72+
rss_diff = info2.rss - info.rss
73+
assert rss_diff == 0
74+
5575

5676
class TestIStr(IStrMixin):
5777
cls = istr

0 commit comments

Comments
 (0)