Skip to content

Commit 52ea6fe

Browse files
committed
Fix more allocations found by tests
1 parent 09b23ca commit 52ea6fe

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

extmod/modasyncio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ mp_obj_t mp_asyncio_context = MP_OBJ_NULL;
179179

180180
static mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
181181
mp_arg_check_num(n_args, n_kw, 1, 2, false);
182-
mp_obj_task_t *self = m_new_obj(mp_obj_task_t);
182+
// CIRCUITPY-CHANGE: Task holds onto core and data so collect it.
183+
mp_obj_task_t *self = m_malloc_with_collect(sizeof(mp_obj_task_t));
183184
self->pairheap.base.type = type;
184185
mp_pairheap_init_node(task_lt, &self->pairheap);
185186
self->coro = args[0];

extmod/vfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
237237
}
238238

239239
// create new object
240-
mp_vfs_mount_t *vfs = m_new_obj(mp_vfs_mount_t);
240+
// CIRCUITPY-CHANGE: Collect the mount object because it references others
241+
mp_vfs_mount_t *vfs = m_malloc_with_collect(sizeof(mp_vfs_mount_t));
241242
vfs->str = mnt_str;
242243
vfs->len = mnt_len;
243244
vfs->obj = vfs_obj;

ports/unix/alloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void mp_unix_alloc_exec(size_t min_size, void **ptr, size_t *size) {
5858
}
5959

6060
// add new link to the list of mmap'd regions
61-
mmap_region_t *rg = m_new_obj(mmap_region_t);
61+
// CIRCUITPY-CHANGE: Collect the mmap region because it points to others.
62+
mmap_region_t *rg = m_malloc_with_collect(sizeof(mmap_region_t));
6263
rg->ptr = *ptr;
6364
rg->len = min_size;
6465
rg->next = MP_STATE_VM(mmap_region_head);

py/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static size_t get_hash_alloc_greater_or_equal_to(size_t x) {
8787
/* map */
8888

8989
// CIRCUITPY-CHANGE: Helper for allocating tables of elements
90-
#define malloc_table(num) m_malloc_helper(sizeof(mp_map_elem_t) * (num), M_MALLOC_COLLECT)
90+
#define malloc_table(num) m_malloc_helper(sizeof(mp_map_elem_t) * (num), M_MALLOC_COLLECT | M_MALLOC_RAISE_ERROR | M_MALLOC_ENSURE_ZEROED)
9191

9292
void mp_map_init(mp_map_t *map, size_t n) {
9393
if (n == 0) {

py/pystack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ static inline void mp_local_free(void *ptr) {
8282
}
8383

8484
static inline void *mp_nonlocal_alloc(size_t n_bytes) {
85-
return m_new(uint8_t, n_bytes);
85+
// CIRCUITPY-CHANGE: Collect the allocated memory because it holds function arguments.
86+
return m_malloc_with_collect(n_bytes);
8687
}
8788

8889
static inline void *mp_nonlocal_realloc(void *ptr, size_t old_n_bytes, size_t new_n_bytes) {

0 commit comments

Comments
 (0)