Skip to content

Crash when returning inside while-loop #1974

Closed

Description

@veddan

When I try to run the following program it crashes with an error message from glibc.

fn main() {
  let s = "hej";
  while s != "" {
    ret;
  }
}

The error message is

*** glibc detected *** ./crash: double free or corruption (fasttop): 0x0000000001a2c7d0 ***

I tried running the program with valgrind. It then produced a different error message:

rust: fatal, 'live_allocs < 1' failed, ./src/rt/memory_region.cpp:54 

If I change the loop to "while true", the program finishes without error.

Activity

  1. brson commented on Mar 14, 2012

    @brson
    Contributor

    It looks like this is due to the basic block containing the loop condition being a parent of the loop body, so when we run all the cleanups for ret or break it runs the condition's cleanups (a 2nd time).

  2. ghost assigned on Mar 14, 2012
  3. brson commented on Mar 14, 2012

    @brson
    Contributor

    Fixed by aeb445b

  4. added a commit that references this issue on Feb 3, 2021
    28794e9
  5. added a commit that references this issue on Jan 26, 2026
  6. added 2 commits that reference this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-codegenArea: Code generationI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions