Skip to content

memory allocation failure should print backtrace #147385

Closed as duplicate
Closed as duplicate

Description

@e00E

When memory allocation fails (for example when extending a Vec), a Rust program prints "memory allocation of xxx bytes failed" and aborts This message would be more helpful if it told you where the allocation happened by printing a backtrace. No backtrace is inconsistent with panics, which print a backtrace. A memory allocation feels like a panic so I expect to get a backtrace.

I understand there might be technical reasons for why this is hard. I'm still reporting this because from a user perspective this is wrong and we might be able to improve it. I didn't find a previous issue talking about this.

Linux, Rust 1.90.0

example program, playground

fn main() {
    foo();
}

fn foo() {
    // panic!();
    let mut v = Vec::new();
    v.resize(1000000000000, 1u8);
    // Print pointer so vector doesn't get optimized out.
    let ptr = v.as_ptr();
    println!("{ptr:?}");
}

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 5, 2025
  2. workingjubilee commented on Oct 5, 2025

    @workingjubilee
    Member

    Well, for one, the backtrace implementation would need to not require allocation.

  3. workingjubilee commented on Oct 5, 2025

    @workingjubilee
    Member

    At least, to always succeed. Sometimes that would abort.

    Anyways this is actually a duplicate, effectively, of #43596 which you may have found by searching for oom panic as part of the GH search query, and it doesn't seem to be adding a distinct discussion.

    Useful comment in a related thread to note: #51245 (comment)
    Useful PR to note: #112331

  4. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    and removed
    C-bugCategory: This is a bug.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions