Skip to content

Commit d87a6a3

Browse files
committed
fix: make sure we drop Skim before returning the output
1 parent 7e462aa commit d87a6a3

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

examples/multiple_runs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use nix::libc::malloc_trim;
12
use skim::{Skim, prelude::SkimOptionsBuilder};
23

34
// Hint: use `ps -T -p $(pgrep -f target/debug/examples/multiple_runs)` to watch threads while the
@@ -6,9 +7,13 @@ fn main() {
67
for i in 0..3 {
78
let opts = SkimOptionsBuilder::default()
89
.header(format!("run {i}"))
10+
.cmd("cat benches/fixtures/10M.txt")
911
.build()
1012
.unwrap();
1113
let res = Skim::run_with(opts, None).unwrap();
14+
unsafe {
15+
malloc_trim(0);
16+
}
1217
println!(
1318
"run {i}: {:?}, sleeping for 5 secs",
1419
res.selected_items.first().map(|x| x.output())

src/skim.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ where
160160
rc.kill()
161161
}
162162
// Clear items
163-
self.app.item_pool.clear();
163+
// self.app.item_pool.clear();
164164
// Clear displayed items unless no_clear_if_empty is set
165165
if !self.app.options.no_clear_if_empty {
166166
self.app.item_list.clear();
@@ -378,24 +378,32 @@ where
378378
// Extract final_key and is_abort from final_event
379379
let is_abort = !matches!(&self.final_event, Event::Action(Action::Accept(_)));
380380

381+
let selected_items = self.app.results();
382+
383+
let cmd = if self.app.options.interactive {
384+
self.app.input.to_string()
385+
} else if self.app.options.cmd_query.is_some() {
386+
self.app.options.cmd_query.clone().unwrap()
387+
} else {
388+
self.initial_cmd.clone()
389+
};
390+
let query = self.app.input.to_string();
391+
let current = self.app.item_list.selected();
392+
let header = self.app.header.header.clone();
393+
let final_event = self.final_event.clone();
394+
let final_key = self.final_key.clone();
395+
396+
drop(self);
397+
381398
SkimOutput {
382-
cmd: if self.app.options.interactive {
383-
// In interactive mode, cmd is what the user typed
384-
self.app.input.to_string()
385-
} else if self.app.options.cmd_query.is_some() {
386-
// If cmd_query was provided, use that for output
387-
self.app.options.cmd_query.clone().unwrap()
388-
} else {
389-
// Otherwise use the execution command
390-
self.initial_cmd
391-
},
392-
final_event: self.final_event,
393-
final_key: self.final_key,
394-
query: self.app.input.to_string(),
399+
cmd,
400+
final_event,
401+
final_key,
402+
query,
395403
is_abort,
396-
selected_items: self.app.results(),
397-
current: self.app.item_list.selected(),
398-
header: self.app.header.header.clone(),
404+
selected_items,
405+
current,
406+
header,
399407
}
400408
}
401409

0 commit comments

Comments
 (0)