Skip to content

Commit 5115fda

Browse files
committed
shared-bindings: I2SOut: Ensure object is deinitialised
(or deinitialized, for those of us on this side of the pond) Otherwise, a sequence like ``` audio = audiobusio.I2SOut(bit_clock=board.D6, word_select=board.D9, data=board.D10) sine_wave_sample = audiocore.RawSample(sine_wave) audio.play(sine_wave_sample, loop=True) del audio ``` could free the memory associated with audio without stopping the related background task. Later, when fresh objects are allocated within a now-freed memory region, they can get overwritten in the background task, leading to a hard crash. This presumably can affect multiple I2S implementations, but it was reported against the nRF one.
1 parent 1c6c9a3 commit 5115fda

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

shared-bindings/audiobusio/I2SOut.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
117117
assert_pin(data_obj, false);
118118
const mcu_pin_obj_t *data = MP_OBJ_TO_PTR(data_obj);
119119

120-
audiobusio_i2sout_obj_t *self = m_new_obj(audiobusio_i2sout_obj_t);
120+
audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t);
121121
self->base.type = &audiobusio_i2sout_type;
122122
common_hal_audiobusio_i2sout_construct(self, bit_clock, word_select, data, args[ARG_left_justified].u_bool);
123123

@@ -268,6 +268,7 @@ const mp_obj_property_t audiobusio_i2sout_paused_obj = {
268268

269269
STATIC const mp_rom_map_elem_t audiobusio_i2sout_locals_dict_table[] = {
270270
// Methods
271+
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&audiobusio_i2sout_deinit_obj) },
271272
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiobusio_i2sout_deinit_obj) },
272273
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
273274
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiobusio_i2sout___exit___obj) },

0 commit comments

Comments
 (0)