Skip to content

Commit 6307996

Browse files
committed
correctly free property and method lists
1 parent 7482941 commit 6307996

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

godot-core/src/engine/script_instance.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -575,27 +575,22 @@ mod script_instance_info {
575575
)
576576
};
577577

578-
let length = handle_panic(ctx, || {
578+
let vec = handle_panic(ctx, || {
579579
let instance = instance_data_as_script_instance::<T>(p_instance);
580580

581-
borrow_instance(instance).get_property_list().len()
581+
instance
582+
.property_list
583+
.lock()
584+
.expect("mutext should not be poisoned")
585+
.remove(&p_prop_info)
586+
.expect("godot is trying to free the property list, but none has been set")
582587
})
583588
.unwrap_or_default();
584589

585590
// SAFETY: p_prop_info is expected to have been created by get_property_list_func
586591
// and therefore should have the same length as before. get_propery_list_func
587592
// also guarantees that both vector length and capacity are equal.
588-
let _drop = transfer_ptr_list_from_godot(p_prop_info, length);
589-
590-
// now drop the backing data
591-
let instance = instance_data_as_script_instance::<T>(p_instance);
592-
593-
let _drop = instance
594-
.property_list
595-
.lock()
596-
.expect("mutex should not be poisoned")
597-
.remove(&p_prop_info)
598-
.expect("we can not free a list that has not been allocated");
593+
let _drop = transfer_ptr_list_from_godot(p_prop_info, vec.len());
599594
}
600595

601596
/// # Safety
@@ -708,18 +703,23 @@ mod script_instance_info {
708703
) {
709704
let ctx = || format!("error while calling {}::get_method_list", type_name::<T>());
710705

711-
let length = handle_panic(ctx, || {
706+
let vec = handle_panic(ctx, || {
712707
let instance = instance_data_as_script_instance::<T>(p_instance);
713708

714-
borrow_instance(instance).get_method_list().len()
709+
instance
710+
.method_list
711+
.lock()
712+
.expect("method_list mutext should not be poisoned")
713+
.remove(&p_method_info)
714+
.expect("godot is trying to free the method_list, but none has been set")
715715
})
716716
.unwrap_or_default();
717717

718718
// SAFETY: p_method_info is expected to have been created by get_method_list_func and therefore should have the same length as before.
719719
// get_method_list_func also guarantees that both vector length and capacity are equal.
720-
let vec = transfer_ptr_list_from_godot(p_method_info, length);
720+
let vec_sys = transfer_ptr_list_from_godot(p_method_info, vec.len());
721721

722-
vec.into_iter().for_each(|method_info| {
722+
vec_sys.into_iter().for_each(|method_info| {
723723
transfer_ptr_list_from_godot(
724724
method_info.arguments,
725725
method_info.argument_count as usize,

0 commit comments

Comments
 (0)