Skip to content

[OVEP] Fixed coverity issues #693

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

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static std::vector<std::string> parseDevices(const std::string& device_string,
OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, std::shared_ptr<SharedContext> shared_context)
: IExecutionProvider{onnxruntime::kOpenVINOExecutionProvider},
session_context_(info),
shared_context_{shared_context},
shared_context_{std::move(shared_context)},
ep_ctx_handle_{session_context_.openvino_sdk_version, *GetLogger()} {
InitProviderOrtApi();
}
Expand Down
14 changes: 7 additions & 7 deletions onnxruntime/core/providers/openvino/openvino_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
if (std::find(std::begin(available_devices), std::end(available_devices), device) != std::end(available_devices))
device_found = true;
if (device_prefix != "CPU" && luid_list.size() > 0) {
for (auto dev : available_devices) {
for (const auto& dev : available_devices) {
ov::device::LUID ov_luid = OVCore::Get()->core.get_property(dev, ov::device::luid);
std::stringstream ov_luid_str;
ov_luid_str << ov_luid;
Expand All @@ -153,7 +153,7 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
}
if (luid_list.size() > 0) {
std::string ov_luid_devices;
for (auto luid_str : luid_list) {
for (const auto& luid_str : luid_list) {
if (ov_luid_map.contains(luid_str)) {
std::string ov_dev = ov_luid_map.at(luid_str);
std::string ov_dev_strip = split(ov_dev, '.')[0];
Expand All @@ -170,14 +170,14 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
}
if (!device_mode.empty()) {
selected_device = device_mode + ":" + ov_luid_devices;
for (auto dev_str : devices_to_check) {
auto default_dev = split(dev_str, '.')[0];
for (const auto& dev_str : devices_to_check) {
const auto default_dev = split(dev_str, '.')[0];

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

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

struct OpenVINOProviderFactory : IExecutionProviderFactory {
OpenVINOProviderFactory(ProviderInfo provider_info, std::shared_ptr<SharedContext> shared_context)
: provider_info_(std::move(provider_info)), shared_context_(shared_context) {}
: provider_info_(std::move(provider_info)), shared_context_(std::move(shared_context)) {}

~OpenVINOProviderFactory() override {}

Expand Down
12 changes: 8 additions & 4 deletions onnxruntime/core/providers/openvino/ov_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void* OVRTAllocator::Alloc(size_t size) {
try {
ov::Tensor* tensor = new ov::Tensor(remote_ctx_.create_host_tensor(ov::element::Type_t::u8,
{size}));
std::unique_lock lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
allocated_.insert({tensor->data(), tensor});
return reinterpret_cast<void*>(tensor->data());
} catch (const ov::Exception& e) {
Expand All @@ -32,12 +32,16 @@ void* OVRTAllocator::Alloc(size_t size) {

void OVRTAllocator::Free(void* p) {
try {
std::unique_lock lock(mutex_);
ov::Tensor* tensor = nullptr;
{
std::lock_guard<std::mutex> lock(mutex_);
auto it = allocated_.find(p);
if (it != allocated_.end()) {
ov::Tensor* tensor = it->second;
tensor = it->second;
allocated_.erase(it);
lock.unlock();
}
}
if (tensor) {
delete tensor;
}
} catch (const ov::Exception& e) {
Expand Down
Loading