diff --git a/crates/types/src/string.rs b/crates/types/src/string.rs index fdda3768..95b78b20 100644 --- a/crates/types/src/string.rs +++ b/crates/types/src/string.rs @@ -138,11 +138,9 @@ impl Clone for String { impl Drop for String { fn drop(&mut self) { - // 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. + if !self.as_ptr().is_null() { + unsafe { libc::free(self.as_ptr() as *mut ffi::c_void) } + } } } diff --git a/crates/types/src/string_builder.rs b/crates/types/src/string_builder.rs index 965a1abf..d5ba5b9d 100644 --- a/crates/types/src/string_builder.rs +++ b/crates/types/src/string_builder.rs @@ -210,14 +210,6 @@ impl fmt::Write for StringBuilder { } } -impl Drop for StringBuilder { - fn drop(&mut self) { - if !self.inner.as_ptr().is_null() { - unsafe { libc::free(self.inner.as_ptr() as *mut ffi::c_void) } - } - } -} - #[cold] #[inline(never)] fn unable_to_alloc_memory() {