From 0b61a1739f8cbc4bd50a2cc3b7dd6172e850bbba Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner <michal.vaner@nic.cz> Date: Fri, 6 Nov 2015 14:47:18 +0100 Subject: [PATCH] flow: Get rid of a resource leak on reconnect After reconnecting, either ignore the config update (if the config is the same we have) or wipe out the old config first to free the memory. --- src/plugins/flow/main.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/plugins/flow/main.c b/src/plugins/flow/main.c index bab43429..60eb4cbc 100644 --- a/src/plugins/flow/main.c +++ b/src/plugins/flow/main.c @@ -137,14 +137,19 @@ static void schedule_timeout(struct context *context) { static void configure(struct context *context, uint32_t conf_id, uint32_t max_flows, uint32_t timeout, uint32_t min_packets, const uint8_t *filter_desc, size_t filter_size) { ulog(LLOG_INFO, "Received configuration %u (max. %u flows, %u ms timeout)\n", (unsigned)conf_id, (unsigned)max_flows, (unsigned)timeout); struct user_data *u = context->user_data; - if (u->configured && u->conf_id != conf_id) { - ulog(LLOG_DEBUG, "Replacing old configuration\n"); - // Switching configuration, so flush the old data - flush(context, true); - sanity(u->timeout_scheduled, "Missing timeout after flush\n"); - loop_timeout_cancel(context->loop, u->timeout_id); - u->timeout_scheduled = false; - mem_pool_reset(u->conf_pool); + if (u->configured) { + if (u->conf_id != conf_id) { + ulog(LLOG_DEBUG, "Replacing old configuration\n"); + // Switching configuration, so flush the old data + flush(context, true); + sanity(u->timeout_scheduled, "Missing timeout after flush\n"); + loop_timeout_cancel(context->loop, u->timeout_id); + u->timeout_scheduled = false; + mem_pool_reset(u->conf_pool); + } else { + ulog(LLOG_DEBUG, "Ignoring the same flow config\n"); + return; + } } u->conf_id = conf_id; u->max_flows = max_flows; -- GitLab