projects
/
ldk-c-bindings
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ad08c71
)
Fix double-free of String bytes after converting an owned Str.
author
Matt Corallo
<git@bluematt.me>
Mon, 3 May 2021 16:33:05 +0000
(16:33 +0000)
committer
Matt Corallo
<git@bluematt.me>
Mon, 3 May 2021 16:33:35 +0000
(16:33 +0000)
lightning-c-bindings/src/c_types/mod.rs
patch
|
blob
|
history
diff --git
a/lightning-c-bindings/src/c_types/mod.rs
b/lightning-c-bindings/src/c_types/mod.rs
index 3d45802e8063850cc2f71983e47daeefce11a304..6267b80bc2dd007ba9476f76d01127d2b9a74937 100644
(file)
--- a/
lightning-c-bindings/src/c_types/mod.rs
+++ b/
lightning-c-bindings/src/c_types/mod.rs
@@
-387,13
+387,15
@@
impl Str {
if self.len == 0 { return ""; }
std::str::from_utf8(unsafe { std::slice::from_raw_parts(self.chars, self.len) }).unwrap()
}
if self.len == 0 { return ""; }
std::str::from_utf8(unsafe { std::slice::from_raw_parts(self.chars, self.len) }).unwrap()
}
- pub(crate) fn into_string(self) -> String {
+ pub(crate) fn into_string(
mut
self) -> String {
let bytes = if self.len == 0 {
Vec::new()
} else if self.chars_is_owned {
let bytes = if self.len == 0 {
Vec::new()
} else if self.chars_is_owned {
- unsafe {
+
let ret =
unsafe {
Box::from_raw(std::slice::from_raw_parts_mut(unsafe { self.chars as *mut u8 }, self.len))
Box::from_raw(std::slice::from_raw_parts_mut(unsafe { self.chars as *mut u8 }, self.len))
- }.into()
+ }.into();
+ self.chars_is_owned = false;
+ ret
} else {
let mut ret = Vec::with_capacity(self.len);
ret.extend_from_slice(unsafe { std::slice::from_raw_parts(self.chars, self.len) });
} else {
let mut ret = Vec::with_capacity(self.len);
ret.extend_from_slice(unsafe { std::slice::from_raw_parts(self.chars, self.len) });