Skip to content

Commit 8ce326e

Browse files
committed
Implement fix from PR commaai#658
1 parent dad9849 commit 8ce326e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

msgq/visionipc/visionipc_module.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ typedef struct {
8686
PyObject_HEAD
8787
VisionBuf *buf;
8888
bool owner;
89+
PyObject *owner_obj;
8990
} PyVisionBuf;
9091

9192
static void VisionBuf_dealloc(PyVisionBuf *self) {
93+
Py_XDECREF(self->owner_obj);
9294
Py_TYPE(self)->tp_free((PyObject *)self);
9395
}
9496

@@ -97,6 +99,7 @@ static PyObject *VisionBuf_new(PyTypeObject *type, PyObject *args, PyObject *kwd
9799
if (self != NULL) {
98100
self->buf = NULL;
99101
self->owner = false;
102+
self->owner_obj = NULL;
100103
}
101104
return (PyObject *)self;
102105
}
@@ -174,11 +177,13 @@ static PyType_Spec VisionBuf_spec = {
174177
VisionBuf_slots
175178
};
176179

177-
static PyObject* wrap_VisionBuf(VisionBuf *cbuf) {
180+
static PyObject* wrap_VisionBuf(VisionBuf *cbuf, PyObject *owner) {
178181
PyVisionBuf *obj = (PyVisionBuf*)PyObject_New(PyVisionBuf, VisionBufType);
179182
if (obj) {
180183
obj->buf = cbuf;
181184
obj->owner = false;
185+
obj->owner_obj = owner;
186+
Py_XINCREF(obj->owner_obj);
182187
}
183188
return (PyObject*)obj;
184189
}
@@ -350,7 +355,7 @@ static PyObject *VisionIpcClient_recv(PyVisionIpcClient *self, PyObject *args, P
350355
Py_END_ALLOW_THREADS
351356

352357
if (!buf) Py_RETURN_NONE;
353-
return wrap_VisionBuf(buf);
358+
return wrap_VisionBuf(buf, (PyObject*)self);
354359
}
355360

356361
static PyObject *VisionIpcClient_connect(PyVisionIpcClient *self, PyObject *args) {

0 commit comments

Comments
 (0)