Skip to content

Commit

Permalink
RawGd::move_return_ptr with PtrcallType::Virtual leaks reference
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Aug 9, 2024
1 parent 128c7ce commit 7c71146
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions godot-core/src/obj/raw_gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,14 @@ where

unsafe fn move_return_ptr(self, ptr: sys::GDExtensionTypePtr, call_type: PtrcallType) {
if T::DynMemory::pass_as_ref(call_type) {
interface_fn!(ref_set_object)(ptr as sys::GDExtensionRefPtr, self.obj_sys())
// ref_set_object creates a new Ref<T> in the engine and increments the reference count. We have to drop our Gd<T> to decrement
// the reference count again.
interface_fn!(ref_set_object)(ptr as sys::GDExtensionRefPtr, self.obj_sys());
} else {
ptr::write(ptr as *mut _, self.obj)
ptr::write(ptr as *mut _, self.obj);
// We've passed ownership to caller.
std::mem::forget(self);
}
// We've passed ownership to caller.
std::mem::forget(self);
}
}

Expand Down

0 comments on commit 7c71146

Please sign in to comment.