diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2020-01-13 20:58:46 +0100 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2020-01-13 20:58:46 +0100 |
commit | ea737db43cba15e5d57442a647e9abcb91ed4ea7 (patch) | |
tree | c8ec09a5e75175f117d7a3a0d85d4eaf2e5b952a /modules | |
parent | 1cf387ed9dcce39afb9c06b3a50b725d8b6f0461 (diff) |
Mono/C#: Fix _update_exports() leaking temporary Object/Node instances
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mono/csharp_script.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index d82e78d080..c708fd412d 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -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; |