Skip to content

malloc_consolidate() error after tests finish #7797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
raymyers opened this issue May 18, 2025 · 1 comment
Closed

malloc_consolidate() error after tests finish #7797

raymyers opened this issue May 18, 2025 · 1 comment

Comments

@raymyers
Copy link

raymyers commented May 18, 2025

Roc version

e0cefe4 (latest nightly)

OS

Linux Nopilot 5.15.167.4-microsoft-standard-WSL2 # 1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Error

Oddly I get this error after the tests have already passed. The same example seems to work fine when run from a main instead of test.

0 failed and 3 passed in 200 ms.
malloc_consolidate(): unaligned fastbin chunk detected

(long pause)

Aborted (core dumped)

Program

This is part of a lisp interpreter, trimed down to reproduce the bug.

app [main!] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}

import pf.Stdout
import pf.Arg


tokenize = |s|
    s
    |> Str.replace_each("(", " ( ")
    |> Str.replace_each(")", " ) ")
    |> Str.split_on(" ")
    |> List.drop_if(|e| e == "")

expect tokenize("(1 2(3))") == ["(", "1", "2", "(", "3", ")", ")"]

Ast : [AtomNode Str, ListNode (List Ast)]

ReadErr : [MissingCloseParen, UnexpectedCloseParen]

read_from_tokens : List Str -> Result (List Ast) ReadErr
read_from_tokens = |tokens|
    if tokens == [] then
        Ok([])
    else
        when read_once_from_tokens(tokens) is
            Ok((ast, more_tokens)) ->
                when read_from_tokens(more_tokens) is
                    Ok(more_asts) -> Ok(List.prepend(more_asts, ast))
                    Err(err) -> Err(err)

            Err(err) -> Err(err)

expect
    read_from_tokens(tokenize("(1 2(3))"))
    ==
    Ok([ListNode([AtomNode("1"), AtomNode("2"), ListNode([AtomNode("3")])])])

read_once_from_tokens : List Str -> Result (Ast, List Str) ReadErr
read_once_from_tokens = |tokens|
    when tokens is
        [] -> Ok((AtomNode("Nil"), []))
        ["(", .. as rest] -> read_list_from_tokens(rest, [])
        [")", ..] -> Err(UnexpectedCloseParen)
        [atom, .. as rest] -> Ok((AtomNode(atom), rest))

read_list_from_tokens : List Str, List Ast -> Result ([ListNode (List Ast)], List Str) ReadErr
read_list_from_tokens = |tokens, acc|
    when tokens is
        [] -> Err(MissingCloseParen)
        [")", .. as rest] -> Ok((ListNode(acc), rest))
        ["(", .. as rest] ->
            when read_list_from_tokens(rest, []) is
                Ok((list_node, next_rest)) ->
                    read_list_from_tokens(next_rest, List.append(acc, list_node))

                Err(err) -> Err(err)

        [atom, .. as rest] ->
            next_acc = List.concat(acc, [AtomNode(atom)])
            read_list_from_tokens(rest, next_acc)

main! : List Arg.Arg => Result {} [Exit I32 Str]_
main! = |_args|
    Stdout.write!("Hello")

expect
    str = "((lambda (b) b) 1)"
    read_result = str |> tokenize |> read_from_tokens
    dbg read_result
    Bool.true
@Anton-4
Copy link
Collaborator

Anton-4 commented May 19, 2025

Thanks for the compact reproduction @raymyers! This is very likely #7799, please follow that issue for updates.

@Anton-4 Anton-4 closed this as completed May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants