Skip to content

Commit 31af04e

Browse files
authored
Merge pull request #1703 from ShacharKagan/mem_fixes
pyverbs: Fix memory leaks and update Python/Cython compatibility
2 parents 97d14a8 + f167dea commit 31af04e

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

pyverbs/base.pyx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ cdef close_weakrefs(iterables):
3636
for it in iterables:
3737
if it is None:
3838
continue
39-
while True:
40-
try:
41-
tmp = it.pop()
42-
tmp.close()
43-
except KeyError: # popping an empty set
44-
break
39+
items = list(it)
40+
it.clear()
41+
for item in items:
42+
if item is not None:
43+
item.close()
4544

4645

4746
cdef class PyverbsObject(object):

pyverbs/providers/mlx5/mlx5dv.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ cdef class Mlx5DevxObj(PyverbsCM):
276276

277277
@property
278278
def obj(self):
279-
return <object>self.obj
279+
return <uintptr_t>self.obj
280280

281281
def __dealloc__(self):
282282
self.close()

tests/test_mlx5_crypto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def check_crypto_caps(dev_name, is_wrapped_dek_mode, multi_block_support=False):
6464
:param multi_block_support: If True, check for multi-block support.
6565
"""
6666
mlx5dv_attr = Mlx5DVContextAttr()
67-
ctx = Mlx5Context(mlx5dv_attr, name=dev_name)
68-
crypto_caps = ctx.query_mlx5_device().crypto_caps
67+
with Mlx5Context(mlx5dv_attr, name=dev_name) as ctx:
68+
crypto_caps = ctx.query_mlx5_device().crypto_caps
6969
failed_selftests = crypto_caps['failed_selftests']
7070
if failed_selftests:
7171
raise unittest.SkipTest(f'The device crypto selftest failed ({failed_selftests})')

0 commit comments

Comments
 (0)