Skip to content

Commit

Permalink
Fix iterator invalidation bug when cleaning the database of previousl…
Browse files Browse the repository at this point in the history
…y detected barcodes (#14)
  • Loading branch information
svwilliams committed Jun 28, 2022
1 parent a1cb492 commit 697fe7b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/barcode_reader_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,17 @@ namespace zbar_ros
void BarcodeReaderNodelet::cleanCb()
{
const std::lock_guard<std::mutex> lock(memory_mutex_);
for (boost::unordered_map<std::string, ros::Time>::iterator it = barcode_memory_.begin();
it != barcode_memory_.end(); ++it)
boost::unordered_map<std::string, ros::Time>::iterator it = barcode_memory_.begin();
while (it != barcode_memory_.end())
{
if (ros::Time::now() > it->second)
{
NODELET_DEBUG_STREAM("Cleaned " << it->first << " from memory");
barcode_memory_.erase(it);
it = barcode_memory_.erase(it);
}
else
{
++it;
}
}
}
Expand Down

0 comments on commit 697fe7b

Please sign in to comment.