diff options
| author | David Lamparter <equinox@diac24.net> | 2017-06-06 17:25:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-06 17:25:06 +0200 |
| commit | fa135ba00813984f1f0d601b8f7930d4efaefe07 (patch) | |
| tree | d27427322ee7e8d4fe39e34a36e742ba28ee4111 /lib/thread.c | |
| parent | 206c5105e0b7c8a7b87f6cd0d3151c3311616c4b (diff) | |
| parent | 95db01eb22d4afe43a7f37243077f24b0b90ae9d (diff) | |
Merge pull request #648 from qlyoung/fix-pollfd-stack-overflow
lib: use heap for pollfds
Diffstat (limited to 'lib/thread.c')
| -rw-r--r-- | lib/thread.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/thread.c b/lib/thread.c index 2280b96316..8c54ec6cea 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -393,6 +393,8 @@ thread_master_create (void) rv->handler.pfdcount = 0; rv->handler.pfds = XCALLOC (MTYPE_THREAD_MASTER, sizeof (struct pollfd) * rv->handler.pfdsize); + rv->handler.copy = XCALLOC (MTYPE_THREAD_MASTER, + sizeof (struct pollfd) * rv->handler.pfdsize); return rv; } @@ -544,6 +546,7 @@ thread_master_free (struct thread_master *m) close (m->io_pipe[1]); XFREE (MTYPE_THREAD_MASTER, m->handler.pfds); + XFREE (MTYPE_THREAD_MASTER, m->handler.copy); XFREE (MTYPE_THREAD_MASTER, m); pthread_mutex_lock (&cpu_record_mtx); @@ -1228,17 +1231,15 @@ thread_fetch (struct thread_master *m, struct thread *fetch) timer_wait = &timer_val; } - /* copy pollfds so we can unlock during blocking calls to poll() */ - struct pollfd pfds[m->handler.pfdsize]; unsigned int count = m->handler.pfdcount + m->handler.pfdcountsnmp; - memcpy (pfds, m->handler.pfds, count * sizeof (struct pollfd)); + memcpy (m->handler.copy, m->handler.pfds, count * sizeof (struct pollfd)); pthread_mutex_unlock (&m->mtx); { - num = fd_poll (m, pfds, m->handler.pfdsize, count, timer_wait); + num = fd_poll (m, m->handler.copy, m->handler.pfdsize, count, timer_wait); } pthread_mutex_lock (&m->mtx); - + /* Signals should get quick treatment */ if (num < 0) { @@ -1260,7 +1261,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch) /* Got IO, process it */ if (num > 0) - thread_process_io (m, pfds, num, count); + thread_process_io (m, m->handler.copy, num, count); #if 0 /* If any threads were made ready above (I/O or foreground timer), |
