From: Vsevolod Stakhov Date: Mon, 29 Feb 2016 15:26:43 +0000 (+0000) Subject: [Fix] Fix redis stats to avoid double free X-Git-Tag: 1.2.0~141 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=236b4ab67c51170088c19c8c22ceb1a05240112b;p=rspamd.git [Fix] Fix redis stats to avoid double free --- diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index ae47eef9f..5fbb7f2da 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -84,6 +84,7 @@ struct rspamd_redis_stat_cbdata { GPtrArray *cur_keys; struct upstream *selected; guint inflight; + gboolean wanna_die; }; #define GET_TASK_ELT(task, elt) (task == NULL ? NULL : (task)->elt) @@ -425,7 +426,9 @@ rspamd_redis_async_cbdata_cleanup (struct rspamd_redis_stat_cbdata *cbdata) guint i; gchar *k; - if (cbdata) { + if (cbdata && !cbdata->wanna_die) { + /* Avoid double frees */ + cbdata->wanna_die = TRUE; redisAsyncFree (cbdata->redis); for (i = 0; i < cbdata->cur_keys->len; i ++) { @@ -468,6 +471,10 @@ rspamd_redis_stat_learns (redisAsyncContext *c, gpointer r, gpointer priv) ucl_object_t *obj; gulong num = 0; + if (cbdata->wanna_die) { + return; + } + cbdata->inflight --; if (c->err == 0 && r != NULL) { @@ -498,6 +505,10 @@ rspamd_redis_stat_key (redisAsyncContext *c, gpointer r, gpointer priv) ucl_object_t *obj; glong num = 0; + if (cbdata->wanna_die) { + return; + } + cbdata->inflight --; if (c->err == 0 && r != NULL) { @@ -545,6 +556,11 @@ rspamd_redis_stat_keys (redisAsyncContext *c, gpointer r, gpointer priv) gchar **pk, *k; guint i, processed = 0; + + if (cbdata->wanna_die) { + return; + } + cbdata->inflight --; if (c->err == 0 && r != NULL) {