Skip to content

Commit 8d57482

Browse files
[OVEP] Fixed coverity issues (#693)
1 parent 080f66b commit 8d57482

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

onnxruntime/core/providers/openvino/openvino_execution_provider.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static std::vector<std::string> parseDevices(const std::string& device_string,
5555
OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, std::shared_ptr<SharedContext> shared_context)
5656
: IExecutionProvider{onnxruntime::kOpenVINOExecutionProvider},
5757
session_context_(info),
58-
shared_context_{shared_context},
58+
shared_context_{std::move(shared_context)},
5959
ep_ctx_handle_{session_context_.openvino_sdk_version, *GetLogger()} {
6060
InitProviderOrtApi();
6161
}

onnxruntime/core/providers/openvino/openvino_provider_factory.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
138138
if (std::find(std::begin(available_devices), std::end(available_devices), device) != std::end(available_devices))
139139
device_found = true;
140140
if (device_prefix != "CPU" && luid_list.size() > 0) {
141-
for (auto dev : available_devices) {
141+
for (const auto& dev : available_devices) {
142142
ov::device::LUID ov_luid = OVCore::Get()->core.get_property(dev, ov::device::luid);
143143
std::stringstream ov_luid_str;
144144
ov_luid_str << ov_luid;
@@ -153,7 +153,7 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
153153
}
154154
if (luid_list.size() > 0) {
155155
std::string ov_luid_devices;
156-
for (auto luid_str : luid_list) {
156+
for (const auto& luid_str : luid_list) {
157157
if (ov_luid_map.contains(luid_str)) {
158158
std::string ov_dev = ov_luid_map.at(luid_str);
159159
std::string ov_dev_strip = split(ov_dev, '.')[0];
@@ -170,14 +170,14 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
170170
}
171171
if (!device_mode.empty()) {
172172
selected_device = device_mode + ":" + ov_luid_devices;
173-
for (auto dev_str : devices_to_check) {
174-
auto default_dev = split(dev_str, '.')[0];
173+
for (const auto& dev_str : devices_to_check) {
174+
const auto default_dev = split(dev_str, '.')[0];
175175

176176
if (ov_luid_devices.find(default_dev) == std::string::npos)
177177
selected_device = selected_device + "," + dev_str;
178178
}
179179
} else {
180-
selected_device = ov_luid_devices;
180+
selected_device = std::move(ov_luid_devices);
181181
}
182182
}
183183
// If invalid device is chosen error is thrown
@@ -215,7 +215,7 @@ static void ParseProviderInfo(const ProviderOptions& provider_options,
215215
// Minor optimization: we'll hold an OVCore reference to ensure we don't create a new core between ParseDeviceType and
216216
// (potential) SharedContext creation.
217217
auto ov_core = OVCore::Get();
218-
pi.device_type = ParseDeviceType(ov_core, provider_options);
218+
pi.device_type = ParseDeviceType(std::move(ov_core), provider_options);
219219

220220
if (provider_options.contains("device_id")) {
221221
std::string dev_id = provider_options.at("device_id").data();
@@ -355,7 +355,7 @@ static void ParseProviderInfo(const ProviderOptions& provider_options,
355355

356356
struct OpenVINOProviderFactory : IExecutionProviderFactory {
357357
OpenVINOProviderFactory(ProviderInfo provider_info, std::shared_ptr<SharedContext> shared_context)
358-
: provider_info_(std::move(provider_info)), shared_context_(shared_context) {}
358+
: provider_info_(std::move(provider_info)), shared_context_(std::move(shared_context)) {}
359359

360360
~OpenVINOProviderFactory() override {}
361361

onnxruntime/core/providers/openvino/ov_allocator.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void* OVRTAllocator::Alloc(size_t size) {
2222
try {
2323
ov::Tensor* tensor = new ov::Tensor(remote_ctx_.create_host_tensor(ov::element::Type_t::u8,
2424
{size}));
25-
std::unique_lock lock(mutex_);
25+
std::lock_guard<std::mutex> lock(mutex_);
2626
allocated_.insert({tensor->data(), tensor});
2727
return reinterpret_cast<void*>(tensor->data());
2828
} catch (const ov::Exception& e) {
@@ -32,12 +32,16 @@ void* OVRTAllocator::Alloc(size_t size) {
3232

3333
void OVRTAllocator::Free(void* p) {
3434
try {
35-
std::unique_lock lock(mutex_);
35+
ov::Tensor* tensor = nullptr;
36+
{
37+
std::lock_guard<std::mutex> lock(mutex_);
3638
auto it = allocated_.find(p);
3739
if (it != allocated_.end()) {
38-
ov::Tensor* tensor = it->second;
40+
tensor = it->second;
3941
allocated_.erase(it);
40-
lock.unlock();
42+
}
43+
}
44+
if (tensor) {
4145
delete tensor;
4246
}
4347
} catch (const ov::Exception& e) {

0 commit comments

Comments
 (0)