From 96aa7cd69fbf7bac3f623d2dad32d3f5562ab1e6 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Wed, 14 Dec 2022 16:38:14 +0800 Subject: [PATCH] fix: monitor plugin memory leak --- plugins/monitor/monitor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/monitor/monitor.c b/plugins/monitor/monitor.c index 9b3b3827..df7e2c94 100644 --- a/plugins/monitor/monitor.c +++ b/plugins/monitor/monitor.c @@ -331,20 +331,20 @@ static int monitor_plugin_config(neu_plugin_t *plugin, const char *setting) } } - if (plugin->mqtt_client && neu_mqtt_client_is_open(plugin->mqtt_client)) { - rv = neu_mqtt_client_close(plugin->mqtt_client); - if (0 != rv) { - plog_error(plugin, "neu_mqtt_client_close fail"); - rv = NEU_ERR_EINTERNAL; - goto error; - } - } else { + if (NULL == plugin->mqtt_client) { plugin->mqtt_client = neu_mqtt_client_new(NEU_MQTT_VERSION_V311); if (NULL == plugin->mqtt_client) { plog_error(plugin, "neu_mqtt_client_new fail"); rv = NEU_ERR_EINTERNAL; goto error; } + } else if (neu_mqtt_client_is_open(plugin->mqtt_client)) { + rv = neu_mqtt_client_close(plugin->mqtt_client); + if (0 != rv) { + plog_error(plugin, "neu_mqtt_client_close fail"); + rv = NEU_ERR_EINTERNAL; + goto error; + } } rv = config_mqtt_client(plugin, plugin->mqtt_client, &config);