@@ -900,8 +900,9 @@ e is InvocationExpressionSyntax i
900900 && IsMemoryPoolType ( sym . ContainingType ) ;
901901
902902// The owner buffer a Span/ReadOnlySpan/Memory/ReadOnlyMemory VIEW expression borrows from:
903- // `owner.AsSpan(...)` / `owner.AsMemory(...)`, or `new Span<T>(owner, …)` / `new Memory<T>(owner)`
904- // (and the ReadOnly* forms), where the source is a local identifier. Returns the owner local name,
903+ // `owner.AsSpan(...)` / `owner.AsMemory(...)`, `new Span<T>(owner, …)` / `new Memory<T>(owner)`
904+ // (and the ReadOnly* forms), or `owner.Memory` / `owner.Memory.Span` of a `System.Buffers.
905+ // IMemoryOwner<T>` (a MemoryPool rental), where the source is a local identifier. Returns the owner local name,
905906// else null. The BORROW is recognised by the RESOLVED BCL symbols — `System.MemoryExtensions`
906907// `AsSpan`/`AsMemory` (which alias the receiver array) and the `System.Span<T>` / `ReadOnlySpan<T>`
907908// / `Memory<T>` / `ReadOnlyMemory<T>` constructor (which wraps the array argument) — NOT by name, so
@@ -926,6 +927,23 @@ e is InvocationExpressionSyntax i
926927 { ContainingType : { Name : "Span" or "ReadOnlySpan" or "Memory" or "ReadOnlyMemory" } sct }
927928 && IsInNamespace ( sct , "System" ) )
928929 return arg . Identifier . Text ;
930+ // owner.Memory — a Memory<T> view of a System.Buffers.IMemoryOwner<T> (e.g. a MemoryPool rental).
931+ // Like array.AsMemory(), the Memory CAN escape (return / field); a use of the view after the
932+ // owner's Dispose is a use of the owner after release (OWN002), and a returned Memory after
933+ // Dispose is a dangling borrow. Recognised by the resolved `IMemoryOwner<T>.Memory` property.
934+ if ( e is MemberAccessExpressionSyntax mem
935+ && mem . Name . Identifier . Text == "Memory"
936+ && mem . Expression is IdentifierNameSyntax mo
937+ && model . GetSymbolInfo ( mem ) . Symbol is IPropertySymbol { ContainingType : { Name : "IMemoryOwner" } ict }
938+ && IsInNamespace ( ict , "System" , "Buffers" ) )
939+ return mo . Identifier . Text ;
940+ // owner.Memory.Span — the Span<T> of that Memory view (a ref-struct borrow that cannot escape).
941+ if ( e is MemberAccessExpressionSyntax { Name . Identifier . Text : "Span" } spanAcc
942+ && spanAcc . Expression is MemberAccessExpressionSyntax
943+ { Name . Identifier . Text : "Memory" , Expression : IdentifierNameSyntax mo2 } innerMem
944+ && model . GetSymbolInfo ( innerMem ) . Symbol is IPropertySymbol { ContainingType : { Name : "IMemoryOwner" } ict2 }
945+ && IsInNamespace ( ict2 , "System" , "Buffers" ) )
946+ return mo2 . Identifier . Text ;
929947 return null ;
930948}
931949
0 commit comments