Skip to content

Commit fe03d82

Browse files
committed
extra: stop rl from leaking each line that is read.
1 parent 21ce41d commit fe03d82

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libextra/rl.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ pub fn read(prompt: &str) -> Option<~str> {
9191
let line = locked!(rustrt::linenoise(buf));
9292

9393
if line.is_null() { None }
94-
else { Some(str::raw::from_c_str(line)) }
94+
else {
95+
unsafe {
96+
do (|| {
97+
Some(str::raw::from_c_str(line))
98+
}).finally {
99+
// linenoise's return value is from strdup, so we
100+
// better not leak it.
101+
rt::global_heap::exchange_free(line);
102+
}
103+
}
104+
}
95105
}
96106
}
97107

0 commit comments

Comments
 (0)