Skip to content

Commit ad18d33

Browse files
dendyDaniel Levin
authored and
Daniel Levin
committed
Fix infinite loop in SubprocessSet::DoWork()
In case fd is invalid loop will be infinite because iterator is not incremented. Make cycle more obvious by adding regular iterator into for() loop and move Subprocess from running_ into finished_ in separate loop.
1 parent dcefb83 commit ad18d33

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/subprocess-posix.cc

+11-8
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,23 @@ bool SubprocessSet::DoWork() {
279279

280280
nfds_t cur_nfd = 0;
281281
for (vector<Subprocess*>::iterator i = running_.begin();
282-
i != running_.end(); ) {
282+
i != running_.end(); ++i) {
283283
int fd = (*i)->fd_;
284284
if (fd < 0)
285285
continue;
286286
assert(fd == fds[cur_nfd].fd);
287-
if (fds[cur_nfd++].revents) {
287+
if (fds[cur_nfd++].revents)
288288
(*i)->OnPipeReady();
289-
if ((*i)->Done()) {
290-
finished_.push(*i);
291-
i = running_.erase(i);
292-
continue;
293-
}
289+
}
290+
291+
for (vector<Subprocess*>::iterator i = running_.begin();
292+
i != running_.end(); ) {
293+
if ((*i)->Done()) {
294+
finished_.push(*i);
295+
i = running_.erase(i);
296+
} else {
297+
++i;
294298
}
295-
++i;
296299
}
297300

298301
return IsInterrupted();

0 commit comments

Comments
 (0)