From 06e9e7692aa0d1df7744cca4e70ea404eb25b093 Mon Sep 17 00:00:00 2001 From: Fabien Wernli Date: Tue, 15 May 2012 13:59:10 +0200 Subject: [PATCH] Cleanup modbus connection if wrong result Change-Id: I1b7520442d7663d5bc2529369e27e3e858fe2168 Signed-off-by: Florian Forster --- src/modbus.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/modbus.c b/src/modbus.c index b5bd75b5..f40258d0 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -466,8 +466,15 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ /* num_registers = */ values_num, /* buffer = */ values); if (status != values_num) { - ERROR ("Modbus plugin: modbus_read_registers (%s) failed. " - "Giving up.", host->host); + ERROR ("Modbus plugin: modbus_read_registers (%s/%s) failed. status = %i, values_num = %i " + "Giving up.", host->host, host->node, status, values_num); +#if LEGACY_LIBMODBUS + modbus_close (&host->connection); +#else + modbus_close (host->connection); + modbus_free (host->connection); +#endif + host->connection = NULL; return (-1); } -- 2.30.2