Skip to content

Commit

Permalink
fix: potential memory leaks (#248)
Browse files Browse the repository at this point in the history
* fix: potential memory leaks

Fixes some potential memory leaks that were raised by static code
analyzer.

Signed-off-by: Chandio, Bibrak Qamar <[email protected]>
  • Loading branch information
bibrak authored Dec 19, 2024
1 parent 16fffbb commit d13942a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions third_party/xla/ordered_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d13942a

Please sign in to comment.