From 75792ed8c8fed656a38df6447e91f5591f1d2cea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 22 Jan 2016 16:24:04 +0000 Subject: [PATCH] Don't crash if learn cache failed to initialize --- src/libstat/stat_config.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 538ddf8cf6..c8b7bcebc3 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -196,8 +196,16 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base) cl->cache = rspamd_stat_get_cache (cache_name); g_assert (cl->cache != NULL); cl->cachecf = cl->cache->init (stat_ctx, cfg, st, cache_obj); - msg_debug_config ("added cache %s for symbol %s", - cl->cache->name, stf->symbol); + + if (cl->cachecf == NULL) { + msg_err_config ("error adding cache %s for symbol %s", + cl->cache->name, stf->symbol); + cl->cache = NULL; + } + else { + msg_debug_config ("added cache %s for symbol %s", + cl->cache->name, stf->symbol); + } } if (st->bkcf == NULL) { @@ -246,7 +254,10 @@ rspamd_stat_close (void) g_slice_free1 (sizeof (*st), st); } - cl->cache->close (cl->cachecf); + if (cl->cache && cl->cachecf) { + cl->cache->close (cl->cachecf); + } + g_array_free (cl->statfiles_ids, TRUE); g_slice_free1 (sizeof (*cl), cl); } -- 2.47.3