Skip to content

Commit

Permalink
(types): don't de-allocate a String when it gets dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Apr 5, 2023
1 parent 18e8175 commit 3f75ed9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/nvim-types/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ impl Clone for String {

impl Drop for String {
fn drop(&mut self) {
// One extra for null terminator.
let _ = unsafe {
Vec::from_raw_parts(self.data, self.size + 1, self.size + 1)
};
// There's no way to know if the pointer we get from Neovim
// points to some `malloc`ed memory or to a static/borrowed string.
//
// TODO: we're leaking memory here if the pointer points to allocated
// memory.
}
}

Expand Down

0 comments on commit 3f75ed9

Please sign in to comment.