-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix infinite loop in SubprocessSet::DoWork() #2484
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,11 +256,11 @@ bool SubprocessSet::DoWork() { | |
for (vector<Subprocess*>::iterator i = running_.begin(); | ||
i != running_.end(); ++i) { | ||
int fd = (*i)->fd_; | ||
if (fd < 0) | ||
continue; | ||
pollfd pfd = { fd, POLLIN | POLLPRI, 0 }; | ||
fds.push_back(pfd); | ||
++nfds; | ||
if (fd >= 0) { | ||
pollfd pfd = { fd, POLLIN | POLLPRI, 0 }; | ||
fds.push_back(pfd); | ||
++nfds; | ||
} | ||
} | ||
|
||
interrupted_ = 0; | ||
|
@@ -281,18 +281,18 @@ bool SubprocessSet::DoWork() { | |
for (vector<Subprocess*>::iterator i = running_.begin(); | ||
i != running_.end(); ) { | ||
int fd = (*i)->fd_; | ||
if (fd < 0) | ||
continue; | ||
assert(fd == fds[cur_nfd].fd); | ||
if (fds[cur_nfd++].revents) { | ||
(*i)->OnPipeReady(); | ||
if ((*i)->Done()) { | ||
finished_.push(*i); | ||
i = running_.erase(i); | ||
continue; | ||
if (fd >= 0) { | ||
assert(fd == fds[cur_nfd].fd); | ||
if (fds[cur_nfd++].revents) { | ||
(*i)->OnPipeReady(); | ||
} | ||
} | ||
++i; | ||
if ((*i)->Done()) { | ||
finished_.push(*i); | ||
i = running_.erase(i); | ||
} else { | ||
++i; | ||
} | ||
} | ||
|
||
return IsInterrupted(); | ||
|
@@ -333,13 +333,13 @@ bool SubprocessSet::DoWork() { | |
int fd = (*i)->fd_; | ||
if (fd >= 0 && FD_ISSET(fd, &set)) { | ||
(*i)->OnPipeReady(); | ||
Comment on lines
334
to
335
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is existing already, changes below have nothing to do with the fd value... if an infinite loop is still possible after the fd value is handled then are we sure that omitting the increment in the loop itself isn't the actual mistake and all you need to do is put it back? |
||
if ((*i)->Done()) { | ||
finished_.push(*i); | ||
i = running_.erase(i); | ||
continue; | ||
} | ||
} | ||
++i; | ||
if ((*i)->Done()) { | ||
finished_.push(*i); | ||
i = running_.erase(i); | ||
} else { | ||
++i; | ||
} | ||
} | ||
|
||
return IsInterrupted(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the way this one has the increment anyway