Skip to content

Commit

Permalink
Fix memory leaks when instantiating Mixin manually for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Xrayez committed Aug 5, 2021
1 parent 46379f6 commit cb708de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/script/mixin_script/mixin_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ Variant Mixin::call(const StringName &p_method, const Variant **p_args, int p_ar
if (real_owner) {
return real_owner->call(p_method, p_args, p_argcount, r_error);
}
#ifdef DEBUG_ENABLED
// The following allows to call `Mixin.free()`.
// This is not strictly needed because Mixin objects should not be instantiated directly,
// and doing so is discouraged, but this can make debug builds more robust for fuzz testing.
Object::call(p_method, p_args, p_argcount, r_error);
#endif
return Variant();
}

Expand Down
2 changes: 1 addition & 1 deletion doc/Mixin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</brief_description>
<description>
A class which extends the run-time functionality of objects that use [MixinScript]. All scripts added to [MixinScript] must inherit from [Mixin].
Mixin objects are instantiated internally and cannot be used as a [Node] in the scene tree.
[b]Warning:[/b] [Mixin] objects are instantiated internally and cannot be used as a [Node] in the scene tree. Do not instantiate [Mixin] objects manually.
</description>
<tutorials>
</tutorials>
Expand Down
8 changes: 8 additions & 0 deletions tests/project/goost/core/script/test_mixin_script.gd
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ func test_move_script():
assert_eq(n.tell(), "First", "Did not move")
ms.move_mixin(1, MixinFirst)
assert_eq(n.tell(), "Second")


func test_mixin_get_owner():
var m = Mixin.new()
var o = m.get_owner()
assert_null(o)
m.free()
assert_freed(m, "Freed")

0 comments on commit cb708de

Please sign in to comment.