From d13942a1ca26edf5d9f107a55fa8ba16c8614790 Mon Sep 17 00:00:00 2001 From: "Chandio, Bibrak Qamar" Date: Wed, 18 Dec 2024 17:04:36 -0800 Subject: [PATCH] fix: potential memory leaks (#248) * fix: potential memory leaks Fixes some potential memory leaks that were raised by static code analyzer. Signed-off-by: Chandio, Bibrak Qamar --- .../checkers/events_checker/zel_events_checker.cpp | 5 ++++- third_party/xla/ordered_set.h | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/layers/validation/checkers/events_checker/zel_events_checker.cpp b/source/layers/validation/checkers/events_checker/zel_events_checker.cpp index c554ae58..4c577b1a 100644 --- a/source/layers/validation/checkers/events_checker/zel_events_checker.cpp +++ b/source/layers/validation/checkers/events_checker/zel_events_checker.cpp @@ -559,7 +559,10 @@ void eventsChecker::ZEeventsChecker::checkForDeadlock( // Form the dependency in the DAG for (uint32_t i = 0; i < numWaitEvents; i++) { auto it = eventToDagID.find(phWaitEvents[i]); - + if (it == eventToDagID.end()) { + std::cerr << "Warning: phWaitEvents {" << phWaitEvents[i] << "} might be an invalid event in call to " << zeCallDisc << std::endl; + return; + } uint32_t dagID = it->second; if (dagID == invalidDagID) { // Create a new node in the DAG for this wait event. That action will be created some time in the future. diff --git a/third_party/xla/ordered_set.h b/third_party/xla/ordered_set.h index 575af616..705d6a80 100755 --- a/third_party/xla/ordered_set.h +++ b/third_party/xla/ordered_set.h @@ -56,12 +56,16 @@ class OrderedSet { // set. void Erase(T value) { auto it = value_to_index_.find(value); - assert(it != value_to_index_.end()); + if (it == value_to_index_.end()) { + std::cerr << "Value not found in OrderedSet" << std::endl; + exit(0); + } + auto index = it->second; // Since we don't want to move values around in `value_sequence_` we swap // the value in the last position and with value to be deleted and then // pop_back. - value_to_index_[value_sequence_.back()] = it->second; + value_to_index_[value_sequence_.back()] = index; std::swap(value_sequence_[it->second], value_sequence_.back()); value_sequence_.pop_back(); value_to_index_.erase(it);