dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Marshalling generators LastIndexMarshalled tracking doesn't free partially marshalled inner array elements if marshalling fails #93431

Open jtschuster opened 1 year ago

jtschuster commented 1 year ago

For jagged arrays, the marshallers won't free a partially marshalled inner array because it doesn't consider the inner array to have completed marshalling until all inner elements are marshalled, and therefore assumes the inner array doesn't need to be freed. Usually this is the behavior we want, because most array elements can't be partially marshalled and won't need partial freeing, but inner arrays of jagged arrays may be partially marshalled.

This is an unsupported scenario and only occurs when marshalling fails.

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/interop-contrib See info in area-owners.md if you want to be subscribed.

Issue Details
For jagged arrays, the marshallers won't free a partially marshalled inner array because it doesn't consider the inner array to have completed marshalling until all inner elements are marshalled, and therefore assumes the inner array doesn't need to be freed. Usually this is the behavior we want, because most array elements can't be partially marshalled and won't need partial freeing, but inner arrays of jagged arrays may be partially marshalled. This is an unsupported scenario and only occurs when marshalling fails.
Author: jtschuster
Assignees: -
Labels: `area-System.Runtime.InteropServices`
Milestone: Future