Skip to content

Segfault when insufficient memory #30

Open
@jonnor

Description

@jonnor

The following code

import emlearn_trees

import array
import gc

def test_trees_alloc():
    n_trees = 100
    nodes_per_tree = 10000

    leaves = 127
    n_classes = leaves
    n_features = 127
    n_nodes = n_trees * nodes_per_tree

    print(n_nodes)
    model = emlearn_trees.new(n_trees, n_nodes, leaves)
    model.setdata(n_features, n_classes)

    for n in range(n_trees):
        model.addroot(n)

    for n in range(n_nodes):
        model.addnode(-1, -2, 3, 4)
        pass

    inp = array.array('h', range(n_features))
    out = array.array('f', range(n_classes))
    model.predict(inp, out)

    print('OK')

test_trees_alloc()

segfault with 1M heap

/usr/bin/time -v micropython -X heapsize=1M test_trees.py 

Works with 10 M heap

/usr/bin/time -v micropython -X heapsize=10M test_trees.py

This is probably due to m_malloc returning 0. I thought it would raise a MemoryError exception...
This likely affects many/most of the other modules as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions