Open jtschuster opened 1 year ago
Tagging subscribers to this area: @dotnet/interop-contrib See info in area-owners.md if you want to be subscribed.
Author: | jtschuster |
---|---|
Assignees: | jtschuster |
Labels: | `area-System.Runtime.InteropServices`, `source-generator` |
Milestone: | - |
The marshalling generators always use the length of the managed collection if it is only marshalled to unmanaged (and not unmarshalled to managed). However, during cleanup, they default to using 0 as the length when cleaning up an inner array of a 2D array. This causes the marshallers to not free any elements of the inner array on successful calls
Jagged arrays are technically an unsupported scenario, but this can cause a memory leak on successful calls to COM methods or LibraryImport methods. This issue is also present in .Net 7.
The fix for this would be to either require length parameters for parameters that are marshalled with marshallers that have a
Free
method (and use them -- we won't use them if they're provided now), or set length to__arrayMarshaller.GetManagedValuesSource().Length
in these specific scenarios.@jkoritzinsky @AaronRobinsonMSFT Should we try to get a fix in 8? I think it's probably okay since the behavior has been here since 7 with no issues, but what are your thoughts?
Source:
Generated: