File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -177,9 +177,11 @@ void process(dnsstate_t *state)
177
177
struct timeval tv;
178
178
179
179
while (1) {
180
- int rv;
181
- int timeout;
182
- size_t i;
180
+ int rv;
181
+ int timeout;
182
+ size_t i;
183
+ struct pollfd * fds;
184
+ size_t nfds;
183
185
184
186
/* Since we don't have any other program state to wait on, we'll just
185
187
* stop looping when we know there are no remaining queries, which is
@@ -199,18 +201,24 @@ void process(dnsstate_t *state)
199
201
continue;
200
202
}
201
203
202
- for (i=0; i<state->nfds; i++) {
203
- if (state->fds[i].revents == 0) {
204
+ /* Duplicate fds structure as calling into ares_process_fd() may manipulate
205
+ * the one contained in state */
206
+ nfds = state->nfds;
207
+ fds = malloc(sizeof(*fds) * nfds);
208
+ memcpy(fds, state->fds, sizeof(*fds) * nfds);
209
+
210
+ for (i=0; i<nfds; i++) {
211
+ if (fds[i].revents == 0) {
204
212
continue;
205
213
}
206
214
207
215
/* Notify about read/write events per FD */
208
216
ares_process_fd(state->channel,
209
- (state->fds[i].revents & (POLLERR|POLLHUP|POLLIN))?
210
- state->fds[i].fd:ARES_SOCKET_BAD,
211
- (state->fds[i].revents & POLLOUT)?
212
- state->fds[i].fd:ARES_SOCKET_BAD);
217
+ (fds[i].revents & (POLLERR|POLLHUP|POLLIN))?fds[i].fd:ARES_SOCKET_BAD,
218
+ (fds[i].revents & POLLOUT)?fds[i].fd:ARES_SOCKET_BAD);
213
219
}
220
+
221
+ free(fds);
214
222
}
215
223
}
216
224
You can’t perform that action at this time.
0 commit comments