Skip to content

Commit 0a4d9d9

Browse files
committed
safe VisionBuf life time via client owner reference
1 parent a16cf1f commit 0a4d9d9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

msgq/visionipc/visionipc_pyx.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cdef class CLContext:
1010

1111
cdef class VisionBuf:
1212
cdef cppVisionBuf * buf
13+
cdef object _owner
1314

1415
@staticmethod
15-
cdef create(cppVisionBuf*)
16+
cdef create(cppVisionBuf*, object)

msgq/visionipc/visionipc_pyx.pyx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ cpdef enum VisionStreamType:
2929

3030

3131
cdef class VisionBuf:
32+
3233
@staticmethod
33-
cdef create(cppVisionBuf * cbuf):
34+
cdef create(cppVisionBuf * cbuf, object owner):
3435
buf = VisionBuf()
3536
buf.buf = cbuf
37+
buf._owner = owner # Keep a reference to the owner to manage lifetime
3638
return buf
3739

40+
def __dealloc__(self):
41+
self._owner = None # explicitly release the reference
42+
3843
@property
3944
def data(self):
4045
return np.asarray(<cnp.uint8_t[:self.buf.len]> self.buf.addr)
@@ -155,7 +160,7 @@ cdef class VisionIpcClient:
155160
buf = self.client.recv(&self.extra, timeout_ms)
156161
if not buf:
157162
return None
158-
return VisionBuf.create(buf)
163+
return VisionBuf.create(buf, self)
159164

160165
def connect(self, bool blocking):
161166
return self.client.connect(blocking)

0 commit comments

Comments
 (0)