This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Eric Wieser
Recipients Eric Wieser
Date 2020-08-31.12:56:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1598878582.68.0.23646842714.issue41673@roundup.psfhosted.org>
In-reply-to
Content
The full definition of `multiprocessing.heap.BufferWrapper` is:

    class BufferWrapper(object):

        _heap = Heap()

        def __init__(self, size):
            if size < 0:
                raise ValueError("Size {0:n} out of range".format(size))
            if sys.maxsize <= size:
                raise OverflowError("Size {0:n} too large".format(size))
            block = BufferWrapper._heap.malloc(size)
            self._state = (block, size)
            util.Finalize(self, BufferWrapper._heap.free, args=(block,))

        def create_memoryview(self):
            (arena, start, stop), size = self._state
            return memoryview(arena.buffer)[start:start+size]


But this means that a `memoryview` can be constructed that point to free'd "memory",


    >>> b = BufferWrapper(10)
    >>> m = b.create_memoryview()
    >>> del b  # free is called
    >>> b[0]  # making this invalid

It would be better if `m` would keep a reference to `b` so that it remains alive.
`RawArray` works around this by placing a reference to `b` in `ctypes_obj._wrapper`, but this results in `b` being lost again if `m2 = memoryview(ctypes_obj); del ctypes_obj` is used.
History
Date User Action Args
2020-08-31 12:56:22Eric Wiesersetrecipients: + Eric Wieser
2020-08-31 12:56:22Eric Wiesersetmessageid: <1598878582.68.0.23646842714.issue41673@roundup.psfhosted.org>
2020-08-31 12:56:22Eric Wieserlinkissue41673 messages
2020-08-31 12:56:22Eric Wiesercreate