Skip to content

Commit 41986fa

Browse files
authored
Use mimalloc to avoid bash's non thread safe allocator (#771)
It turns out that bash overrides the global allocator. Flyline defaults to using that non thread safe allocator. So if multiple threads are (de)allocating rust objects like Vec simultaneously, it can cause heap corruption. Hopefully this fixes #770
1 parent c4fd509 commit 41986fa

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ disallowed_methods = "deny"
1111
crate-type = ["cdylib"]
1212

1313
[dependencies]
14+
mimalloc = { version = "0.1.52", default-features = false }
1415
clap = { version = "4.6.1", features = ["derive"] }
1516
clap_complete = { version = "4.6.3", features = ["unstable-dynamic"] }
1617
ratatui = { git = "https://github.com/Marlinski/ratatui.git", rev = "fd8e0f024847af467129e0a166390d7e291c1b2e", features = ["default", "unstable-rendered-line-info", "serde"] }

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use libc::{c_char, c_int};
22
use std::sync::Mutex;
33

4+
#[global_allocator]
5+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
6+
47
pub const FILENAME_INFERENCE_LIMIT: usize = 5000;
58

69
#[cfg(feature = "pre_bash_4_4")]

0 commit comments

Comments
 (0)