Skip to content

Commit

Permalink
[registrar] Make sure to release the return value from xamarin_get_pa…
Browse files Browse the repository at this point in the history
…rameter_type. (#11725)

Before:

    There were 258046 MonoObjects created, 235142 MonoObjects freed, so 22904 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204193 MonoObjects freed, so 1611 were not freed. (static registrar)

After:

    There were 258054 MonoObjects created, 235172 MonoObjects freed, so 22882 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 205190 MonoObjects freed, so 614 were not freed. (static registrar)
  • Loading branch information
rolfbjarne authored May 28, 2021
1 parent 51c9364 commit dc30bdf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 3 additions & 1 deletion runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@
if (index == -1) {
p = mono_signature_get_return_type (msig);
} else {
for (int i = 0; i < index + 1; i++)
for (int i = 0; i < index + 1; i++) {
xamarin_mono_object_release (&p);
p = mono_signature_get_params (msig, &iter);
}
}

xamarin_bridge_free_mono_signature (&msig);
Expand Down
5 changes: 4 additions & 1 deletion runtime/trampolines.m
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@
{
guint32 context_ref = GPOINTER_TO_UINT (context);
MonoObject *obj;
MonoType *parameterType = NULL;

if (context_ref == INVALID_TOKEN_REF) {
// This requires the dynamic registrar to invoke the correct conversion function
Expand All @@ -1639,7 +1640,9 @@
managed_method = xamarin_get_managed_method_for_token (context_ref /* token ref */, exception_gchandle);
if (*exception_gchandle != INVALID_GCHANDLE) return NULL;

arg0 = xamarin_get_nsobject_with_type_for_ptr (value, false, xamarin_get_parameter_type (managed_method, 0), exception_gchandle);
parameterType = xamarin_get_parameter_type (managed_method, 0);
arg0 = xamarin_get_nsobject_with_type_for_ptr (value, false, parameterType, exception_gchandle);
xamarin_mono_object_release (&parameterType);
if (*exception_gchandle != INVALID_GCHANDLE) {
xamarin_mono_object_release (&managed_method);
return NULL;
Expand Down
25 changes: 20 additions & 5 deletions tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,10 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
if (type != nativetype) {
body_setup.AppendLine ("MonoClass *paramclass{0} = NULL;", i);
cleanup.AppendLine ("xamarin_mono_object_release (&paramclass{0});", i);
setup_call_stack.AppendLine ("paramclass{0} = mono_class_from_mono_type (xamarin_get_parameter_type (managed_method, {0}));", i);
body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
cleanup.AppendLine ("xamarin_mono_object_release (&paramtype{0});", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("paramclass{0} = mono_class_from_mono_type (paramtype{0});", i);
GenerateConversionToManaged (nativetype, type, setup_call_stack, descriptiveMethodName, ref exceptions, method, $"p{i}", $"arg_ptrs [{i}]", $"paramclass{i}", i);
if (isRef || isOut)
throw ErrorHelper.CreateError (4163, Errors.MT4163_B, descriptiveMethodName);
Expand Down Expand Up @@ -3562,7 +3565,10 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
cleanup.AppendLine ("xamarin_mono_object_release (&marr{0});", i);
} else if (isNSObject) {
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_nsobject_array (arr{0}, xamarin_get_parameter_type (managed_method, {0}), NULL, &exception_gchandle);", i);
body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
cleanup.AppendLine ("xamarin_mono_object_release (&paramtype{0});", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_nsobject_array (arr{0}, paramtype{0}, NULL, &exception_gchandle);", i);
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
cleanup.AppendLine ("xamarin_mono_object_release (&marr{0});", i);
} else if (isINativeObject) {
Expand All @@ -3581,13 +3587,16 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
if (!HasIntPtrBoolCtor (nativeObjType))
throw ErrorHelper.CreateError (4103, Errors.MT4103, nativeObjType.FullName, descriptiveMethodName);

body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
cleanup.AppendLine ("xamarin_mono_object_release (&paramtype{0});", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
if (isNativeObjectInterface) {
var resolvedElementType = ResolveType (elementType);
var iface_token_ref = $"0x{CreateTokenReference (resolvedElementType, TokenType.TypeDef):X} /* {resolvedElementType} */ ";
var implementation_token_ref = $"0x{CreateTokenReference (nativeObjType, TokenType.TypeDef):X} /* {nativeObjType} */ ";
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_inativeobject_array_static (arr{0}, xamarin_get_parameter_type (managed_method, {0}), NULL, {1}, {2}, &exception_gchandle);", i, iface_token_ref, implementation_token_ref);
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_inativeobject_array_static (arr{0}, paramtype{0}, NULL, {1}, {2}, &exception_gchandle);", i, iface_token_ref, implementation_token_ref);
} else {
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_inativeobject_array (arr{0}, xamarin_get_parameter_type (managed_method, {0}), NULL, &exception_gchandle);", i);
setup_call_stack.AppendLine ("marr{0} = xamarin_nsarray_to_managed_inativeobject_array (arr{0}, paramtype{0}, NULL, &exception_gchandle);", i);
}
cleanup.AppendLine ("xamarin_mono_object_release (&marr{0});", i);
setup_call_stack.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
Expand Down Expand Up @@ -3625,6 +3634,7 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
setup_call_stack.AppendLine ("nsobj{0} = *(NSObject **) p{0};", i).Unindent ();
setup_call_stack.AppendLine ("if (nsobj{0}) {{", i);
body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
cleanup.AppendLine ("xamarin_mono_object_release (&paramtype{0});", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("mobj{0} = xamarin_get_nsobject_with_type_for_ptr (nsobj{0}, false, paramtype{0}, &exception_gchandle);", i);
cleanup.AppendLine ("xamarin_mono_object_release (&mobj{0});", i);
Expand Down Expand Up @@ -3662,6 +3672,7 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
body_setup.AppendLine ("int32_t created{0} = false;", i);
setup_call_stack.AppendLine ("if (nsobj{0}) {{", i);
body_setup.AppendLine ("MonoType *paramtype{0} = NULL;", i);
cleanup.AppendLine ("xamarin_mono_object_release (&paramtype{0});", i);
setup_call_stack.AppendLine ("paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("mobj{0} = xamarin_get_nsobject_with_type_for_ptr_created (nsobj{0}, false, paramtype{0}, &created{0}, &exception_gchandle);", i);
cleanup.AppendLine ("xamarin_mono_object_release (&mobj{0});", i);
Expand Down Expand Up @@ -3703,6 +3714,7 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
if (!td.IsInterface) {
// find the MonoClass for this parameter
body_setup.AppendLine ("MonoType *type{0};", i);
cleanup.AppendLine ("xamarin_mono_object_release (&type{0});", i);
setup_call_stack.AppendLine ("type{0} = xamarin_get_parameter_type (managed_method, {0});", i);
}
body_setup.AppendLine ("MonoObject *inobj{0} = NULL;", i);
Expand Down Expand Up @@ -3836,7 +3848,10 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
if (returntype != method.NativeReturnType) {
body_setup.AppendLine ("MonoClass *retparamclass = NULL;");
cleanup.AppendLine ("xamarin_mono_object_release (&retparamclass);");
setup_call_stack.AppendLine ("retparamclass = mono_class_from_mono_type (xamarin_get_parameter_type (managed_method, -1));");
body_setup.AppendLine ("MonoType *retparamtype = NULL;");
cleanup.AppendLine ("xamarin_mono_object_release (&retparamtype);");
setup_call_stack.AppendLine ("retparamtype = xamarin_get_parameter_type (managed_method, -1);");
setup_call_stack.AppendLine ("retparamclass = mono_class_from_mono_type (retparamtype);");
GenerateConversionToNative (returntype, method.NativeReturnType, setup_return, descriptiveMethodName, ref exceptions, method, "retval", "res", "retparamclass");
} else if (returntype.IsValueType) {
setup_return.AppendLine ("res = *({0} *) mono_object_unbox ((MonoObject *) retval);", rettype);
Expand Down

9 comments on commit dc30bdf

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (no change)

Packages generated

View packages
# GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

5 tests failed, 216 tests passed.

Failed tests

  • monotouch-test/Mac [dotnet]/Debug (CoreCLR) [dotnet]: Failed (Test run failed.
    Tests run: 2444 Passed: 2357 Inconclusive: 10 Failed: 4 Ignored: 83)
  • monotouch-test/Mac [dotnet]/Debug (CoreCLR, static registrar) [dotnet]: Failed (Test run failed.
    Tests run: 2441 Passed: 2357 Inconclusive: 10 Failed: 2 Ignored: 82)
  • monotouch-test/iOS Unified 32-bits - simulator/Debug: Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 32-bits - simulator/Debug: Failed
  • introspection/watchOS 32-bits - simulator/Debug (watchOS 5.0): Failed

Pipeline on Agent XAMBOT-1025.BigSur'
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac Catalina (10.15) ❌

Tests failed on Mac Catalina (10.15).

Failed tests are:

  • introspection
  • xammac_tests

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac Mojave (10.14) ❌

Tests failed on Mac Mojave (10.14).

Failed tests are:

  • introspection
  • xammac_tests

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac High Sierra (10.13) ❌

Tests failed on Mac High Sierra (10.13).

Failed tests are:

  • introspection
  • xammac_tests

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Status for 'xamarin-macios - sample testing (build)': failure.

  • ❌ Debug_iPhone_AF: Failed
  • ❌ Debug_iPhone_GR: Failed
  • ❌ Debug_iPhone_SZ: Failed
  • ❌ Debug_iPhoneSimulator: Failed
  • ❌ Release_iPhone_AF: Failed
  • ❌ Release_iPhone_GR: Failed
  • ❌ Release_iPhone_SZ: Failed
  • ❌ Release_iPhoneSimulator: Failed
  • ❌ Debug_Mac: Failed
  • ❌ Release_Mac: Failed
  • ❌ PublishPerformanceData: Failed

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (Build). ⚠️

Results were skipped for this run Azure Devops.

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

Before:

There were 258046 MonoObjects created, 235142 MonoObjects freed, so 22904 were not freed. (dynamic registrar)
There were 205804 MonoObjects created, 204193 MonoObjects freed, so 1611 were not freed. (static registrar)

After:

There were 258054 MonoObjects created, 235172 MonoObjects freed, so 22882 were not freed. (dynamic registrar)
There were 205804 MonoObjects created, 205190 MonoObjects freed, so 614 were not freed. (static registrar)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS32b). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)

Please sign in to comment.