diff --git a/py/ringbuf.c b/py/ringbuf.c index 72e164946ae5..fe47b50068b6 100644 --- a/py/ringbuf.c +++ b/py/ringbuf.c @@ -28,7 +28,6 @@ #include "ringbuf.h" bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) { - r->heap = false; r->buf = buf; r->size = capacity; r->iget = r->iput = 0; @@ -40,7 +39,6 @@ bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) { // size of the buffer is one greater than that, due to how the buffer // handles empty and full statuses. bool ringbuf_alloc(ringbuf_t *r, size_t capacity, bool long_lived) { - r->heap = true; r->buf = gc_alloc(capacity + 1, false, long_lived); r->size = capacity + 1; r->iget = r->iput = 0; @@ -48,9 +46,8 @@ bool ringbuf_alloc(ringbuf_t *r, size_t capacity, bool long_lived) { } void ringbuf_free(ringbuf_t *r) { - if (r->heap) { - gc_free(r->buf); - } + // Free buf by letting gc take care of it. If the VM has finished already, + // this will be safe. r->buf = (uint8_t *)NULL; r->size = 0; ringbuf_clear(r); diff --git a/py/ringbuf.h b/py/ringbuf.h index 8f7e7b176059..d868eff1e40d 100644 --- a/py/ringbuf.h +++ b/py/ringbuf.h @@ -37,7 +37,6 @@ typedef struct _ringbuf_t { uint32_t size; uint32_t iget; uint32_t iput; - bool heap; } ringbuf_t; // Note that the capacity of the buffer is N-1!