Skip to content

Fix plugin EP allocator deleter lifetime - #29770

Merged
tianleiwu merged 1 commit into
mainfrom
tlwu/allocator_lifetime
Jul 21, 2026
Merged

Fix plugin EP allocator deleter lifetime#29770
tianleiwu merged 1 commit into
mainfrom
tlwu/allocator_lifetime

Conversation

@tianleiwu

@tianleiwu tianleiwu commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Cherrypick #29663 so that it can pass CI for 1.28 release.


Summary

This PR fixes an AppVerifier failure seen during ONNX Runtime / onnxruntime_genai shutdown with the plugin EP path:

INVALID_POINTER_READ_AVRF_c0000005_onnxruntime.dll!OrtGetApiBase
Access violation - code c0000005

The bug is in the allocator deleter lifetime. Plugin EP allocators are released later by an OrtAllocatorUniquePtr custom deleter, but the deleter was reaching OrtEpFactory::ReleaseAllocator through transient owner captures:

  • Environment::CreateSharedAllocatorImpl captured ep_device by reference.
  • PluginExecutionProvider::CreatePreferredAllocators captured this.

The fix captures the required OrtEpFactory* directly in both deleters and calls:

ep_factory->ReleaseAllocator(ep_factory, allocator);

This keeps allocator destruction independent from the stack reference / provider object used when the deleter was created, while preserving the same allocator ownership and release API.

Changed files

  • onnxruntime/core/session/environment.cc
  • onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc

Verification

Built ORT and the TRT-RTX EP repro stack against TRT-RTX 1.6.1.114, then ran the DeepSeek WinML AppVerifier repro.

  • Fixed branch: "appVerifierEnabled": true, "appVerifierFailed": false
  • Rebuilt origin/main negative control: "appVerifierEnabled": true, "appVerifierFailed": true

This confirms the invalid pointer read still reproduces on origin/main and is removed by the allocator deleter lifetime change.

Capture the OrtEpFactory pointer directly in plugin allocator release callbacks instead of capturing transient owner objects. This keeps allocator destruction safe when shared or per-session allocator wrappers outlive the object that created the callback.
@tianleiwu
tianleiwu merged commit b55d99a into main Jul 21, 2026
92 of 93 checks passed
@tianleiwu
tianleiwu deleted the tlwu/allocator_lifetime branch July 21, 2026 17:08
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.

3 participants