Mono/C#: Fix _update_exports() leaking temporary Object/Node instances
This commit is contained in:
parent
1cf387ed9d
commit
ea737db43c
1 changed files with 13 additions and 0 deletions
|
@ -2243,7 +2243,11 @@ bool CSharpScript::_update_exports() {
|
|||
MonoException *ctor_exc = NULL;
|
||||
ctor->invoke(tmp_object, NULL, &ctor_exc);
|
||||
|
||||
Object *tmp_native = GDMonoMarshal::unbox<Object *>(CACHED_FIELD(GodotObject, ptr)->get_value(tmp_object));
|
||||
|
||||
if (ctor_exc) {
|
||||
// TODO: Should we free 'tmp_native' if the exception was thrown after its creation?
|
||||
|
||||
MonoGCHandle::free_handle(tmp_pinned_gchandle);
|
||||
tmp_object = NULL;
|
||||
|
||||
|
@ -2322,6 +2326,15 @@ bool CSharpScript::_update_exports() {
|
|||
|
||||
MonoGCHandle::free_handle(tmp_pinned_gchandle);
|
||||
tmp_object = NULL;
|
||||
|
||||
if (tmp_native && !Object::cast_to<Reference>(tmp_native)) {
|
||||
Node *node = Object::cast_to<Node>(tmp_native);
|
||||
if (node && node->is_inside_tree()) {
|
||||
ERR_PRINTS("Temporary instance was added to the scene tree.");
|
||||
} else {
|
||||
memdelete(tmp_native);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
placeholder_fallback_enabled = false;
|
||||
|
|
Loading…
Reference in a new issue