-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Make name an std::string in OrtMemoryInfo #25960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR changes the name field in OrtMemoryInfo from a const char* to std::string to prevent dangling pointer issues when users pass arbitrary names that may be deallocated before the API requires them.
- Updates the
OrtMemoryInfostruct to usestd::stringfor the name field instead ofconst char* - Refactors all code that accesses the name field to use
.c_str()when C-string interface is needed - Adds input validation to API functions to prevent null pointer issues
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| include/onnxruntime/core/framework/ortmemoryinfo.h | Changes name field from const char* to std::string and updates comparison operations |
| onnxruntime/core/framework/allocator.cc | Adds input validation and updates API functions to work with string names |
| onnxruntime/core/session/environment.cc | Updates string comparison to use std::string equality |
| onnxruntime/core/framework/bfc_arena.cc | Updates constructor call to use .c_str() |
| onnxruntime/core/session/lora_adapters.cc | Updates string comparisons for memory info names |
| onnxruntime/test/framework/TestAllocatorManager.cc | Updates constructor call to use .c_str() |
| onnxruntime/test/framework/allocator_test.cc | Updates test assertion to use .c_str() |
| onnxruntime/test/framework/tensor_test.cc | Updates test assertions to use .c_str() or direct string comparison |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
### Description <!-- Describe your changes. --> OrtMemoryInfo has a name which is pointer. With the recent changes a user can pass an arbitrary name and then deallocate the string as the API does not require it. Make the name a `std::strng` to own it and refactor. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> We will have a dangling pointer especially when it comes to other languages. The way it used to work in the past, is that the string would be compared to an internal constant and that constant would be used then. (cherry picked from commit 8ad0614)
### Description <!-- Describe your changes. --> OrtMemoryInfo has a name which is pointer. With the recent changes a user can pass an arbitrary name and then deallocate the string as the API does not require it. Make the name a `std::strng` to own it and refactor. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> We will have a dangling pointer especially when it comes to other languages. The way it used to work in the past, is that the string would be compared to an internal constant and that constant would be used then. (cherry picked from commit 8ad0614)
This PR cherry-picks the following PRs to the rel-1.23.0 branch: * #25938 * #25957 * #25960 * #25968 * #25971 --------- Co-authored-by: Dmitri Smirnov <yuslepukhin@users.noreply.github.com> Co-authored-by: Adrian Lizarraga <adlizarraga@microsoft.com> Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com>
|
This PR has been cherry-picked into the |
Description
OrtMemoryInfo has a name which is pointer.
With the recent changes a user can pass an arbitrary name and then deallocate the string
as the API does not require it. Make the name a
std::strngto own it and refactor.Motivation and Context
We will have a dangling pointer especially when it comes to other languages.
The way it used to work in the past, is that the string would be compared to an internal constant and that constant would be used then.