From fddfb8a0b05b1e62a6e39f709bc48906701cd8af Mon Sep 17 00:00:00 2001 From: Riccardo Mazzarini Date: Tue, 19 Aug 2025 12:27:32 +0200 Subject: [PATCH] fix: re-enable `String`'s `Drop` impl --- crates/types/src/string.rs | 8 +++----- crates/types/src/string_builder.rs | 8 -------- 2 files changed, 3 insertions(+), 13 deletions(-) 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() {