]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Try to fix watchers chaining
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Sep 2018 17:10:57 +0000 (18:10 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Sep 2018 17:10:57 +0000 (18:10 +0100)
src/libserver/events.c

index 9563753e0723255b9d31fed6397ec089a5c6b40a..325da445231dea3e1653cd37e81eb795fd977a1b 100644 (file)
@@ -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;