From f50ccd52388ffbcbbf0cd21ef7d6562300ef7ebb Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 12 Nov 2013 15:24:33 +0400 Subject: [PATCH] core: fix fake watcher list and count preservation Fake watcher list and count should be preserved only if `loop->watchers` was already allocated. --- src/unix/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/unix/core.c b/src/unix/core.c index 991b18fa..22c48dd7 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -603,21 +603,21 @@ static void maybe_resize(uv_loop_t* loop, unsigned int len) { if (len <= loop->nwatchers) return; + /* Preserve fake watcher list and count at the end of the watchers */ + if (loop->watchers != NULL) { + fake_watcher_list = loop->watchers[loop->nwatchers]; + fake_watcher_count = loop->watchers[loop->nwatchers + 1]; + } else { + fake_watcher_list = NULL; + fake_watcher_count = NULL; + } + nwatchers = next_power_of_two(len + 2) - 2; watchers = realloc(loop->watchers, (nwatchers + 2) * sizeof(loop->watchers[0])); if (watchers == NULL) abort(); - - /* Copy watchers, preserving fake one in the end */ - if (loop->watchers == NULL) { - fake_watcher_list = watchers[loop->nwatchers]; - fake_watcher_count = watchers[loop->nwatchers + 1]; - } else { - fake_watcher_list = NULL; - fake_watcher_count = NULL; - } for (i = loop->nwatchers; i < nwatchers; i++) watchers[i] = NULL; watchers[nwatchers] = fake_watcher_list;