Skip to content

fix: Add memory lifetime warnings to ReadOnlySpan properties - #406

Open
Abhilash437 wants to merge 1 commit into
apache:mainfrom
Abhilash437:fix/span-lifetime-warning-397
Open

fix: Add memory lifetime warnings to ReadOnlySpan properties#406
Abhilash437 wants to merge 1 commit into
apache:mainfrom
Abhilash437:fix/span-lifetime-warning-397

Conversation

@Abhilash437

@Abhilash437 Abhilash437 commented Aug 11, 2026

Copy link
Copy Markdown

What's Changed

Adds explicit XML documentation remarks (<remarks>) to properties and methods that return a ReadOnlySpan over managed or unmanaged memory across Apache Arrow array and buffer classes.

Motivation & Relation to PR #393

When an ArrowBuffer or Array is backed by unmanaged memory (e.g., allocated via a custom MemoryAllocator or NativeMemoryManager), extracting a ReadOnlySpan into a local variable and subsequently disposing the parent buffer/array can lead to use-after-free memory access issues.

While PR #393 explores structural lifecycle/pinning mechanisms, this PR provides an immediate, non-breaking developer safety improvement:

  • Added <remarks> warning callouts to ArrowBuffer.Span, PrimitiveArray.Values, BooleanArray.Values, and BinaryArray.GetBytes. These surface as visible safety notes in IDE tooltips and IntelliSense (Visual Studio, VS Code, Rider) without breaking builds or requiring API breaking changes under TreatWarningsAsErrors=true.
  • Added PoisonMemoryAllocator and unit test TestNativeMemoryManagerUseAfterFree to Apache.Arrow.Tests to verify memory poisoning on buffer release.

Closes #397. Relates to #393.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrowBuffer spans do not keep native memory alive: NativeMemoryManager's finalizer can free a buffer while a Span over it is in use

1 participant