#ifdef WITH_HIREDIS
#include "hiredis.h"
#include "adapters/libevent.h"
+#include "ref.h"
#define REDIS_CTX(p) (struct redis_stat_ctx *)(p)
guint64 learned;
gint id;
enum rspamd_redis_connection_state conn_state;
+ ref_entry_t ref;
};
/* Used to get statistics from redis */
task = rt->task;
+ if (rt->conn_state != RSPAMD_REDIS_CONNECTED) {
+ /* Task has disappeared already */
+ REF_RELEASE (rt);
+ return;
+ }
+
if (c->err == 0) {
if (r != NULL) {
if (G_LIKELY (reply->type == REDIS_REPLY_INTEGER)) {
rt->learned = val;
rt->conn_state = RSPAMD_REDIS_CONNECTED;
+ REF_RETAIN (rt);
msg_debug_task ("connected to redis server, tokens learned for %s: %uL",
rt->redis_object_expanded, rt->learned);
rspamd_upstream_fail (rt->selected);
rspamd_session_remove_event (task->s, rspamd_redis_fin, rt);
}
+
+ REF_RELEASE (rt);
}
/* Called when we have received tokens values from redis */
task = rt->task;
+ if (rt->conn_state != RSPAMD_REDIS_CONNECTED) {
+ /* Task has disappeared already */
+ REF_RELEASE (rt);
+ return;
+ }
+
if (c->err == 0) {
if (r != NULL) {
if (reply->type == REDIS_REPLY_ARRAY) {
rspamd_upstream_fail (rt->selected);
rspamd_session_remove_event (task->s, rspamd_redis_fin, rt);
}
+
+ REF_RELEASE (rt);
}
/* Called when we have set tokens during learning */
task = rt->task;
+ if (rt->conn_state != RSPAMD_REDIS_CONNECTED) {
+ /* Task has disappeared already */
+ REF_RELEASE (rt);
+ return;
+ }
+
if (c->err == 0) {
rspamd_upstream_ok (rt->selected);
rspamd_session_remove_event (task->s, rspamd_redis_fin_learn, rt);
redisAsyncFree (rt->redis);
rt->conn_state = RSPAMD_REDIS_DISCONNECTED;
}
+
+ REF_RELEASE (rt);
}
static gboolean
return (gpointer)backend;
}
+static void
+rspamd_redis_runtime_dtor (struct redis_stat_runtime *rt)
+{
+ g_slice_free1 (sizeof (*rt), rt);
+}
+
gpointer
rspamd_redis_runtime (struct rspamd_task *task,
struct rspamd_statfile_config *stcf,
return NULL;
}
- rt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*rt));
+ rt = g_slice_alloc0 (sizeof (*rt));
+ REF_INIT_RETAIN (rt, rspamd_redis_runtime_dtor);
rspamd_redis_expand_object (ctx->redis_object, ctx, task,
&rt->redis_object_expanded);
rt->selected = up;
rt->redis = NULL;
rt->conn_state = RSPAMD_REDIS_DISCONNECTED;
+
+ REF_RELEASE (rt);
}
}
rt->redis = NULL;
rt->conn_state = RSPAMD_REDIS_DISCONNECTED;
+ REF_RELEASE (rt);
}
}