Skip to content

Commit

Permalink
[DIAL] Make a copy of device id before erasing device from map.
Browse files Browse the repository at this point in the history
erase() by key takes input param as a const ref. Invoking erase() by
key using data that will be destroyed during the erase() call will
result in undefined behavior.

BUG=656073

Review-Url: https://chromiumcodereview.appspot.com/2436403003
Cr-Commit-Position: refs/heads/master@{#426957}
  • Loading branch information
imcheng authored and Commit bot committed Oct 22, 2016
1 parent 5bbf3c6 commit 2a375e6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chrome/browser/extensions/api/dial/dial_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ bool DialRegistry::PruneExpiredDevices() {
auto* device = it->second;
if (IsDeviceExpired(*device)) {
VLOG(2) << "Device " << device->label() << " expired, removing";
const size_t num_erased_by_id =
device_by_id_map_.erase(device->device_id());

// Make a copy of the device ID here since |device| will be destroyed
// during erase().
std::string device_id = device->device_id();
const size_t num_erased_by_id = device_by_id_map_.erase(device_id);
DCHECK_EQ(1U, num_erased_by_id);
device_by_label_map_.erase(it++);
pruned_device = true;
Expand Down

0 comments on commit 2a375e6

Please sign in to comment.