fix(modbus): free invalid memory

This commit is contained in:
fengzero
2023-08-03 09:08:01 +00:00
parent af6146cd83
commit 05d51c88a2
+6 -2
View File
@@ -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;
}