From 05d51c88a25291238ffe2bdfd882101e449c288e Mon Sep 17 00:00:00 2001 From: fengzero Date: Thu, 3 Aug 2023 08:54:51 +0000 Subject: [PATCH] fix(modbus): free invalid memory --- plugins/modbus/modbus_tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modbus/modbus_tcp.c b/plugins/modbus/modbus_tcp.c index 5e164ea0..ab8546a5 100644 --- a/plugins/modbus/modbus_tcp.c +++ b/plugins/modbus/modbus_tcp.c @@ -144,7 +144,9 @@ static int driver_config(neu_plugin_t *plugin, const char *config) char * err_param = NULL; neu_json_elem_t port = { .name = "port", .t = NEU_JSON_INT }; neu_json_elem_t timeout = { .name = "timeout", .t = NEU_JSON_INT }; - neu_json_elem_t host = { .name = "host", .t = NEU_JSON_STR }; + neu_json_elem_t host = { .name = "host", + .t = NEU_JSON_STR, + .v.val_str = NULL }; neu_json_elem_t interval = { .name = "interval", .t = NEU_JSON_INT }; neu_json_elem_t mode = { .name = "connection_mode", .t = NEU_JSON_INT }; neu_json_elem_t tmode = { .name = "transport_mode", .t = NEU_JSON_INT }; @@ -159,7 +161,9 @@ static int driver_config(neu_plugin_t *plugin, const char *config) if (ret != 0) { plog_error(plugin, "config: %s, decode error: %s", config, err_param); free(err_param); - free(host.v.val_str); + if (host.v.val_str != NULL) { + free(host.v.val_str); + } return -1; }