Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 03dcffb

Browse files
edgchen1Zhao-Xu Luo
authored and
Zhao-Xu Luo
committedApr 17, 2025
[onnxruntime_perf_test] Fix custom_allocator_ destruction order. (microsoft#24136)
Move the allocator data member declaration before the `Ort::Value` container data members that might use the allocator so that the `Ort::Value` containers will be destroyed first. `custom_allocator_` may be used as the allocator for the `Ort::Value`s in `test_inputs_` and `outputs_`. The allocator shouldn't be destroyed before `Ort::Value`s allocated with it are freed.
1 parent ce61696 commit 03dcffb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎onnxruntime/test/perftest/ort_test_session.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class OnnxRuntimeTestSession : public TestSession {
3737
Ort::Session session_{nullptr};
3838
std::mt19937 rand_engine_;
3939
std::uniform_int_distribution<int> dist_;
40-
std::vector<std::vector<Ort::Value>> test_inputs_;
4140
OrtAllocator* allocator_ = Ort::AllocatorWithDefaultOptions();
41+
// Note: custom_allocator_, if used, must outlive the `Ort::Value`s allocated with it in test_inputs_ and outputs_.
4242
Ort::Allocator custom_allocator_{nullptr};
43+
std::vector<std::vector<Ort::Value>> test_inputs_;
4344
std::vector<Ort::Value> outputs_;
4445
std::vector<std::string> output_names_;
4546
// The same size with output_names_.

0 commit comments

Comments
 (0)
Please sign in to comment.