0

I have a Rust program compiled with Rust 1.30.0:

use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, Result};

fn main() -> Result<()> {
    let file = File::open("file.txt")?;
    let mut scores = HashMap::new();
    let mut i = 0;
    for line in BufReader::new(file).lines() {
        let line = line.expect("Unable to read line");
        scores.insert(line, i);
        i = i + 1;
    }
    Ok(())
}

First I build it:

cargo build --release
cd target/release

Running it alone works:

./hello_cargo

But when running Valgrind:

valgrind --tool=massif --main-stacksize=1900000000 ./hello_cargo
==11619== Massif, a heap profiler
==11619== Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote
==11619== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==11619== Command: ./hello_cargo
==11619==
==11619==
==11619== Process terminating with default action of signal 11 (SIGSEGV)
==11619==  Access not within mapped region at address 0x8193A990
==11619==    at 0x4863B9E: __dlerror_main_freeres (dlerror.c:189)
==11619==    by 0x4A3EA41: __libc_freeres (in /lib/x86_64-linux-gnu/libc-2.28.so)
==11619==    by 0x482D19E: _vgnU_freeres (in /usr/lib/valgrind/vgpreload_core-amd64-linux.so)
==11619==    by 0x48F1529: __run_exit_handlers (exit.c:132)
==11619==    by 0x48F1559: exit (exit.c:139)
==11619==    by 0x48D10A1: (below main) (libc-start.c:342)
==11619==  If you believe this happened as a result of a stack
==11619==  overflow in your program's main thread (unlikely but
==11619==  possible), you can try to increase the size of the
==11619==  main thread stack using the --main-stacksize= flag.
==11619==  The main thread stack size used in this run was 1900003328.

I tried with different parameters of main-stacksize but it did not help.

How can I solve the issue?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
David Michael Gang
  • 7,107
  • 8
  • 53
  • 98
  • 3
    Please see if [Why does Valgrind not detect a memory leak in a Rust program using nightly 1.29.0?](https://stackoverflow.com/q/51509314/155423) solves your issue. Not using the system allocator usually leads to failures with Valgrind. – Shepmaster Nov 06 '18 at 18:53
  • i cannot use this. it gives a compilation error: error[E0554]: #![feature] may not be used on the stable release channel. When removing the feature line i get an error error[E0658]: use of unstable library feature 'alloc_system': this library is unlikely to be stabilized in its current form or name (see issue #32838) – David Michael Gang Nov 06 '18 at 19:13
  • @DavidMichaelGang we expected you to have read the book, https://doc.rust-lang.org/stable/book/second-edition/appendix-07-nightly-rust.html#unstable-features – Stargateur Nov 06 '18 at 19:15
  • @Stargateur you are 100 % right. I did not get to this chapter yet but had to read the whole book. – David Michael Gang Nov 06 '18 at 19:24
  • 1
    @shepmaster it worked perfectly – David Michael Gang Nov 06 '18 at 19:25

0 Answers0