From ab742578f6127eefab6367c0509f83f886b11b6a Mon Sep 17 00:00:00 2001 From: Aaron <138695933+svix-aaron1011@users.noreply.github.com> Date: Sat, 13 Apr 2024 10:07:15 -0400 Subject: [PATCH] Impl Drop for CTypeInfo (#1452) This deallocates the C++ allocation, preventing a memory leak --- src/binding.cc | 2 ++ src/fast_api.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/binding.cc b/src/binding.cc index 087750aa..ee887b32 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -2115,6 +2115,8 @@ v8::CTypeInfo* v8__CTypeInfo__New(v8::CTypeInfo::Type ty) { return u.release(); } +void v8__CTypeInfo__DELETE(v8::CTypeInfo* self) { delete self; } + struct CTypeSequenceType { v8::CTypeInfo::Type c_type; v8::CTypeInfo::SequenceType sequence_type; diff --git a/src/fast_api.rs b/src/fast_api.rs index 96a0a9e1..7f1667b5 100644 --- a/src/fast_api.rs +++ b/src/fast_api.rs @@ -13,6 +13,7 @@ extern "C" { len: usize, tys: *const CTypeSequenceInfo, ) -> *mut CTypeInfo; + fn v8__CTypeInfo__DELETE(this: &mut CTypeInfo); fn v8__CFunctionInfo__New( return_info: *const CTypeInfo, args_len: usize, @@ -72,6 +73,12 @@ impl CTypeInfo { } } +impl Drop for CTypeInfo { + fn drop(&mut self) { + unsafe { v8__CTypeInfo__DELETE(self) }; + } +} + #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[repr(u8)] pub enum SequenceType {