Merge "fd_utils: Fix broken usage of iterators." into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fda29437bf
@@ -446,8 +446,8 @@ class FileDescriptorTable {
|
|||||||
//
|
//
|
||||||
// (a) they continue to be open.
|
// (a) they continue to be open.
|
||||||
// (b) they refer to the same file.
|
// (b) they refer to the same file.
|
||||||
std::unordered_map<int, FileDescriptorInfo*>::iterator it;
|
std::unordered_map<int, FileDescriptorInfo*>::iterator it = open_fd_map_.begin();
|
||||||
for (it = open_fd_map_.begin(); it != open_fd_map_.end(); ++it) {
|
while (it != open_fd_map_.end()) {
|
||||||
std::set<int>::const_iterator element = open_fds.find(it->first);
|
std::set<int>::const_iterator element = open_fds.find(it->first);
|
||||||
if (element == open_fds.end()) {
|
if (element == open_fds.end()) {
|
||||||
// The entry from the file descriptor table is no longer in the list
|
// The entry from the file descriptor table is no longer in the list
|
||||||
@@ -457,11 +457,10 @@ class FileDescriptorTable {
|
|||||||
// TODO(narayan): This will be an error in a future android release.
|
// TODO(narayan): This will be an error in a future android release.
|
||||||
// error = true;
|
// error = true;
|
||||||
// ALOGW("Zygote closed file descriptor %d.", it->first);
|
// ALOGW("Zygote closed file descriptor %d.", it->first);
|
||||||
open_fd_map_.erase(it);
|
it = open_fd_map_.erase(it);
|
||||||
} else {
|
} else {
|
||||||
// The entry from the file descriptor table is still open. Restat
|
// The entry from the file descriptor table is still open. Restat
|
||||||
// it and check whether it refers to the same file.
|
// it and check whether it refers to the same file.
|
||||||
open_fds.erase(element);
|
|
||||||
const bool same_file = it->second->Restat();
|
const bool same_file = it->second->Restat();
|
||||||
if (!same_file) {
|
if (!same_file) {
|
||||||
// The file descriptor refers to a different description. We must
|
// The file descriptor refers to a different description. We must
|
||||||
@@ -473,11 +472,20 @@ class FileDescriptorTable {
|
|||||||
// We flag an error and remove it from the list of files we're
|
// We flag an error and remove it from the list of files we're
|
||||||
// tracking.
|
// tracking.
|
||||||
error = true;
|
error = true;
|
||||||
open_fd_map_.erase(it);
|
it = open_fd_map_.erase(it);
|
||||||
|
} else {
|
||||||
|
// Successfully restatted the file, move on to the next open FD.
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// It's the same file. Nothing to do here.
|
// It's the same file. Nothing to do here. Move on to the next open
|
||||||
|
// FD.
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finally, remove the FD from the set of open_fds. We do this last because
|
||||||
|
// |element| will not remain valid after a call to erase.
|
||||||
|
open_fds.erase(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user