diff --git a/BeefLibs/corlib/src/Reflection/MethodInfo.bf b/BeefLibs/corlib/src/Reflection/MethodInfo.bf index b191726e..31a62546 100644 --- a/BeefLibs/corlib/src/Reflection/MethodInfo.bf +++ b/BeefLibs/corlib/src/Reflection/MethodInfo.bf @@ -610,7 +610,12 @@ namespace System.Reflection List ffiParamList = scope .(16); List ffiArgList = scope .(16); - List tempVariants = scope .(4); + List tempVariants = scope .(4); + defer + { + for (var variant in tempVariants) + variant.Dispose(); + } var target; @@ -761,15 +766,17 @@ namespace System.Reflection if (underlyingType == paramType) handled = true; - + if (!handled) { if (!underlyingType.IsSubtypeOf(paramType)) { if (Convert.ConvertTo(arg, paramType) case .Ok(var variant)) { - tempVariants.Add(variant); - dataPtr = variant.GetValueData(); + var tempVariant = scope:mixin Variant(); + *tempVariant = variant; + tempVariants.Add(tempVariant); + dataPtr = tempVariant.GetValueData(); } else isValid = false;