From: Vsevolod Stakhov Date: Fri, 28 Sep 2018 17:10:57 +0000 (+0100) Subject: [Fix] Try to fix watchers chaining X-Git-Tag: 1.8.1~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e80857cdb12d45f42c3f18263c4ddee263326ad;p=thirdparty%2Frspamd.git [Fix] Try to fix watchers chaining --- diff --git a/src/libserver/events.c b/src/libserver/events.c index 9563753e07..325da44523 100644 --- a/src/libserver/events.c +++ b/src/libserver/events.c @@ -395,12 +395,25 @@ rspamd_session_watch_start (struct rspamd_async_session *session, if (session->cur_watcher == NULL) { session->cur_watcher = rspamd_mempool_alloc0 (session->pool, sizeof (*session->cur_watcher)); - } - st_elt = rspamd_mempool_alloc (session->pool, sizeof (*st_elt)); - st_elt->cb = cb; - st_elt->ud = ud; - LL_PREPEND (session->cur_watcher->st, st_elt); + st_elt = rspamd_mempool_alloc (session->pool, sizeof (*st_elt)); + st_elt->cb = cb; + st_elt->ud = ud; + LL_PREPEND (session->cur_watcher->st, st_elt); + } + else { + if (session->cur_watcher->st) { + /* Reuse the existing (empty) watcher */ + session->cur_watcher->st->cb = cb; + session->cur_watcher->st->ud = ud; + } + else { + st_elt = rspamd_mempool_alloc (session->pool, sizeof (*st_elt)); + st_elt->cb = cb; + st_elt->ud = ud; + LL_PREPEND (session->cur_watcher->st, st_elt); + } + } session->cur_watcher->id = id; session->flags |= RSPAMD_SESSION_FLAG_WATCHING;