From f3a456f755378d704ad28cbec12c64c2ac3e697e Mon Sep 17 00:00:00 2001 From: Jing Fang Date: Tue, 30 Jul 2024 13:07:44 -0700 Subject: [PATCH] resolve comments --- onnxruntime/core/framework/session_state_utils.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/onnxruntime/core/framework/session_state_utils.cc b/onnxruntime/core/framework/session_state_utils.cc index d42fd09685dcf..b13b0cd27496d 100644 --- a/onnxruntime/core/framework/session_state_utils.cc +++ b/onnxruntime/core/framework/session_state_utils.cc @@ -325,9 +325,12 @@ common::Status SaveInitializedTensors( bool use_device_allocator_for_initializers = session_options.config_options.GetConfigOrDefault(kOrtSessionOptionsUseDeviceAllocatorForInitializers, "0") == "1"; - Tensor* p_tensor = buffered_tensors.find(name) != buffered_tensors.end() - ? buffered_tensors[name].release() - : nullptr; + Tensor* p_tensor = nullptr; + if (auto iter = buffered_tensors.find(name); + iter != buffered_tensors.end()) { + p_tensor = iter->second.release(); + buffered_tensors.erase(iter); + } Status st = DeserializeTensorProto(env, graph_loc, tensor_proto, (m.has_value()) ? &*m : nullptr, alloc, default_cpu_alloc, ort_value, data_transfer_mgr,