You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IoError.to_str() leaks five allocations per call #1392
use std.fs
fn main:
match read_file("/tmp/does-not-exist"):
Ok(s) => print(s.len())
Err(e) =>
let m = e.to_str()
print(m)
with run --debug-alloc (installed v0.15.2.1, origin/main 8c859a7): debug-alloc: leak count=5 (four 16-byte and one 32-byte blocks). e.message() (lib/std/fs.w, hand-written) is leak count=0, so the leak is in the to_str generated for the pub error IoError declaration (or its Display glue).
The same leak appears for any error declaration's generated Display, not only IoError.to_str(). With the seed at 8c859a7:
error DbError =
| Failed(status: i32)
fn main:
let e = DbError.Failed(3)
print(f"err {e}")
with run --debug-alloc gives leak count=3, and let s = e.display(); print(s) gives the same. Found while writing the stage 5 facade fixtures (#1426), where <R>Error is a rendered error declaration. The fixtures avoid displaying the error until this is fixed.
Same leak with a user error declaration and no std involvement (origin/main 1c76062, base stage2), found while writing the #1430 fixtures (behav_1430_error_from_declared_later.w shows it under --debug-alloc, declared in either order):
error DbError =
| Failed(code: i32, detail: i64)
| Missing(what: str)
fn main:
let e = DbError.Failed(1, 2)
let s = f"{e}"
print(s)
with run --debug-alloc: prints Failed(1, 2), debug-alloc: leak count=6 (all 16-byte blocks). With DbError.Missing("users") alone: leak count=2. Wrapping it (error AppError from DbError, f"{AppError.Db(DbError.Failed(1, 2))}") leaks likewise. So the generated Display for any error declaration leaks per formatted field, not just IoError.to_str.
Activity
ehartford commentedon Sep 23, 2026
The same leak appears for any
errordeclaration's generated Display, not onlyIoError.to_str(). With the seed at 8c859a7:with run --debug-allocgivesleak count=3, andlet s = e.display(); print(s)gives the same. Found while writing the stage 5 facade fixtures (#1426), where<R>Erroris a renderederrordeclaration. The fixtures avoid displaying the error until this is fixed.ehartford commentedon Sep 23, 2026
Same leak with a user
errordeclaration and no std involvement (origin/main 1c76062, base stage2), found while writing the #1430 fixtures (behav_1430_error_from_declared_later.wshows it under--debug-alloc, declared in either order):with run --debug-alloc: printsFailed(1, 2),debug-alloc: leak count=6(all 16-byte blocks). WithDbError.Missing("users")alone:leak count=2. Wrapping it (error AppError from DbError,f"{AppError.Db(DbError.Failed(1, 2))}") leaks likewise. So the generated Display for any error declaration leaks per formatted field, not just IoError.to_str.Codegen: a built-in enum/struct display frees its parts once joined; …
Codegen: a built-in enum/struct display frees its parts once joined; …