Skip to content

Commit

Permalink
Merge pull request #783 from EdwardSro/pr-bug-fixes
Browse files Browse the repository at this point in the history
pyverbs: Memset the memory after posix_memalign
  • Loading branch information
rleon committed Jul 20, 2020
2 parents 8a477f6 + 26b3b7f commit 1faf9b8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pyverbs/mem_alloc.pyx
Expand Up @@ -7,6 +7,7 @@ from posix.stdlib cimport posix_memalign as c_posix_memalign
from libc.stdlib cimport malloc as c_malloc, free as c_free
from posix.mman cimport mmap as c_mmap, munmap as c_munmap
from libc.stdint cimport uintptr_t
from libc.string cimport memset
cimport posix.mman as mm

cdef extern from 'sys/mman.h':
Expand Down Expand Up @@ -58,7 +59,8 @@ def malloc(size):

def posix_memalign(size, alignment=8):
"""
Python wrapper for the stdlib posix_memalign function
Python wrapper for the stdlib posix_memalign function.
The function calls posix_memalign and memsets the memory to 0.
:param size: The size of the memory block in bytes
:param alignment: Alignment of the allocated memory, must be a power of two
:return: The address of the allocated memory, which is a multiple of
Expand All @@ -68,6 +70,7 @@ def posix_memalign(size, alignment=8):
ret = c_posix_memalign(&ptr, alignment, size)
if ret:
raise MemoryError('Failed to allocate memory ({err}'.format(ret))
memset(ptr, 0, size)
return <uintptr_t>ptr


Expand Down

0 comments on commit 1faf9b8

Please sign in to comment.