avoid using invalid iterator when erasing items using an iterator in a loop (#436)

* avoid using invalid iterator when erasing items using an iterator in a loop

* do not overwrite iterator in cases where it will be unused
This commit is contained in:
William Woodall 2018-02-02 16:46:24 -08:00 committed by GitHub
parent 3a503685bf
commit f88ade7a2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -249,7 +249,7 @@ public:
if (!group) { if (!group) {
// Group was not found, meaning the subscription is not valid... // Group was not found, meaning the subscription is not valid...
// Remove it from the ready list and continue looking // Remove it from the ready list and continue looking
subscription_handles_.erase(it); it = subscription_handles_.erase(it);
continue; continue;
} }
if (!group->can_be_taken_from().load()) { if (!group->can_be_taken_from().load()) {
@ -270,7 +270,7 @@ public:
return; return;
} }
// Else, the subscription is no longer valid, remove it and continue // Else, the subscription is no longer valid, remove it and continue
subscription_handles_.erase(it); it = subscription_handles_.erase(it);
} }
} }
@ -288,7 +288,7 @@ public:
if (!group) { if (!group) {
// Group was not found, meaning the service is not valid... // Group was not found, meaning the service is not valid...
// Remove it from the ready list and continue looking // Remove it from the ready list and continue looking
service_handles_.erase(it); it = service_handles_.erase(it);
continue; continue;
} }
if (!group->can_be_taken_from().load()) { if (!group->can_be_taken_from().load()) {
@ -305,7 +305,7 @@ public:
return; return;
} }
// Else, the service is no longer valid, remove it and continue // Else, the service is no longer valid, remove it and continue
service_handles_.erase(it); it = service_handles_.erase(it);
} }
} }
@ -321,7 +321,7 @@ public:
if (!group) { if (!group) {
// Group was not found, meaning the service is not valid... // Group was not found, meaning the service is not valid...
// Remove it from the ready list and continue looking // Remove it from the ready list and continue looking
client_handles_.erase(it); it = client_handles_.erase(it);
continue; continue;
} }
if (!group->can_be_taken_from().load()) { if (!group->can_be_taken_from().load()) {
@ -338,7 +338,7 @@ public:
return; return;
} }
// Else, the service is no longer valid, remove it and continue // Else, the service is no longer valid, remove it and continue
client_handles_.erase(it); it = client_handles_.erase(it);
} }
} }