Skip to content

Commit e0827eb

Browse files
authored
Merge pull request adafruit#6238 from dhalbert/ringbuf-free-fix
Free ringbuf buffer by relying on gc, not gc_free()
2 parents 8cd09b1 + 70add52 commit e0827eb

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

py/ringbuf.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "ringbuf.h"
2929

3030
bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) {
31-
r->heap = false;
3231
r->buf = buf;
3332
r->size = capacity;
3433
r->iget = r->iput = 0;
@@ -40,17 +39,15 @@ bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) {
4039
// size of the buffer is one greater than that, due to how the buffer
4140
// handles empty and full statuses.
4241
bool ringbuf_alloc(ringbuf_t *r, size_t capacity, bool long_lived) {
43-
r->heap = true;
4442
r->buf = gc_alloc(capacity + 1, false, long_lived);
4543
r->size = capacity + 1;
4644
r->iget = r->iput = 0;
4745
return r->buf != NULL;
4846
}
4947

5048
void ringbuf_free(ringbuf_t *r) {
51-
if (r->heap) {
52-
gc_free(r->buf);
53-
}
49+
// Free buf by letting gc take care of it. If the VM has finished already,
50+
// this will be safe.
5451
r->buf = (uint8_t *)NULL;
5552
r->size = 0;
5653
ringbuf_clear(r);

py/ringbuf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef struct _ringbuf_t {
3737
uint32_t size;
3838
uint32_t iget;
3939
uint32_t iput;
40-
bool heap;
4140
} ringbuf_t;
4241

4342
// Note that the capacity of the buffer is N-1!

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy