Skip to content

Commit a8170f9

Browse files
committed
MP3Decoder: ensure object uses finalizer
.. so that the underlying allocations will be freed. This is not important now but will be if the underlying allocator is changed to something else like `port_malloc` in the future.
1 parent 6136c33 commit a8170f9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

shared-bindings/audiomp3/MP3Decoder.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
9494
arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb));
9595
}
9696

97-
audiomp3_mp3file_obj_t *self = mp_obj_malloc(audiomp3_mp3file_obj_t, &audiomp3_mp3file_type);
97+
audiomp3_mp3file_obj_t *self = m_new_obj_with_finaliser(audiomp3_mp3file_obj_t);
98+
self->base.type = &audiomp3_mp3file_type;
99+
98100
if (!mp_obj_is_type(arg, &mp_type_fileio)) {
99101
mp_raise_TypeError(MP_ERROR_TEXT("file must be a file opened in byte mode"));
100102
}
@@ -260,6 +262,7 @@ STATIC const mp_rom_map_elem_t audiomp3_mp3file_locals_dict_table[] = {
260262
// Methods
261263
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&audiomp3_mp3file_open_obj) },
262264
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiomp3_mp3file_deinit_obj) },
265+
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&audiomp3_mp3file_deinit_obj) },
263266
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
264267
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiomp3_mp3file___exit___obj) },
265268

0 commit comments

Comments
 (0)