# HG changeset patch # User Michiel Broek # Date 1533305597 -7200 # Node ID fcfc3dbe85faf78525bc6ab169428c9dac863074 # Parent 88c398efc7287db7f0318e4e62722bd43b9dcb10 Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind. diff -r 88c398efc728 -r fcfc3dbe85fa configure --- a/configure Thu Aug 02 13:39:30 2018 +0200 +++ b/configure Fri Aug 03 16:13:17 2018 +0200 @@ -2035,7 +2035,7 @@ PACKAGE="mbsePi-apps" -VERSION="0.8.6" +VERSION="0.8.7" COPYRIGHT="Copyright (C) 2014-2018 Michiel Broek, All Rights Reserved" CYEARS="2014-2018" diff -r 88c398efc728 -r fcfc3dbe85fa configure.ac --- a/configure.ac Thu Aug 02 13:39:30 2018 +0200 +++ b/configure.ac Fri Aug 03 16:13:17 2018 +0200 @@ -8,7 +8,7 @@ dnl General settings dnl After changeing the version number, run autoconf! PACKAGE="mbsePi-apps" -VERSION="0.8.6" +VERSION="0.8.7" COPYRIGHT="Copyright (C) 2014-2018 Michiel Broek, All Rights Reserved" CYEARS="2014-2018" AC_SUBST(PACKAGE) diff -r 88c398efc728 -r fcfc3dbe85fa thermferm/mqtt.c --- a/thermferm/mqtt.c Thu Aug 02 13:39:30 2018 +0200 +++ b/thermferm/mqtt.c Fri Aug 03 16:13:17 2018 +0200 @@ -284,7 +284,7 @@ profiles_list *profile; prof_step *pstep; - payload = xstrcat(payload, (char *)"{"); + payload = xstrcpy((char *)"{"); /* * Fixed unit values, never change these! @@ -560,7 +560,7 @@ */ void publishDBirthAll(void) { - char *payload = NULL; + char *topic = NULL, *payload = NULL, *payloadu = NULL; units_list *unit; int comma = FALSE; @@ -570,13 +570,19 @@ if (unit->mode != UNITMODE_OFF) { if (comma) payload = xstrcat(payload, (char *)","); - payload = xstrcat(payload, unit_data(unit, true)); + payloadu = unit_data(unit, true); + payload = xstrcat(payload, payloadu); comma = TRUE; + free(payloadu); + payloadu = NULL; } } if (comma) { // Only publish if there is at least one unit active. payload = xstrcat(payload, (char *)"]}}"); - publisher(mosq, topic_base((char *)"DBIRTH"), payload, true); + topic = topic_base((char *)"DBIRTH"); + publisher(mosq, topic, payload, true); + free(topic); + topic = NULL; } free(payload); payload = NULL; @@ -586,17 +592,20 @@ void publishDData(units_list *unit) { - char *payload = NULL, *topic = NULL; + char *payload = NULL, *payloadu = NULL, *topic = NULL; if (mqtt_use) { payload = payload_header(); - payload = xstrcat(payload, unit_data(unit, false)); + payloadu = unit_data(unit, false); + payload = xstrcat(payload, payloadu); payload = xstrcat(payload, (char *)"}"); topic = xstrcat(topic_base((char *)"DDATA"), (char *)"/"); topic = xstrcat(topic, unit->alias); publisher(mosq, topic, payload, false); free(payload); payload = NULL; + free(payloadu); + payloadu = NULL; free(topic); topic = NULL; } @@ -778,7 +787,7 @@ void publishNData(bool birth, int flag) { - char *payload = NULL, sidx[10], buf[64]; + char *topic = NULL, *payload = NULL, sidx[10], buf[64]; struct utsname ubuf; bool comma = false; @@ -887,11 +896,15 @@ neterr: payload = xstrcat(payload, (char *)"}}"); - if (birth) - publisher(mosq, topic_base((char *)"NBIRTH"), payload, true); - else - publisher(mosq, topic_base((char *)"NDATA"), payload, false); - + if (birth) { + topic = topic_base((char *)"NBIRTH"); + publisher(mosq, topic, payload, true); + } else { + topic = topic_base((char *)"NDATA"); + publisher(mosq, topic, payload, false); + } + free(topic); + topic = NULL; free(payload); payload = NULL; @@ -914,7 +927,7 @@ void mqtt_connect(void) { - char *id = NULL; + char *id = NULL, *topic; char err[1024]; int rc; @@ -945,16 +958,20 @@ mosquitto_lib_cleanup(); return; } + free(id); + id = NULL; /* * Set our will */ - if ((rc = mosquitto_will_set(mosq, topic_base((char *)"NDEATH"), 0, NULL, mqtt_qos, false))) { + topic = topic_base((char *)"NDEATH"); + if ((rc = mosquitto_will_set(mosq, topic, 0, NULL, mqtt_qos, false))) { if (rc > MOSQ_ERR_SUCCESS) syslog(LOG_NOTICE, "MQTT: mosquitto_will_set: %s", mosquitto_strerror(rc)); mosquitto_lib_cleanup(); return; } + free(topic); if (debug) mosquitto_log_callback_set(mosq, my_log_callback); @@ -991,6 +1008,7 @@ void mqtt_disconnect(void) { int rc; + char *topic; if (mqtt_use) { /* @@ -998,10 +1016,18 @@ * After that, remove the retained topic. */ syslog(LOG_NOTICE, "MQTT disconnecting"); - publisher(mosq, topic_base((char *)"DBIRTH"), NULL, true); // Not always needed, but ... - publisher(mosq, topic_base((char *)"DDEATH"), NULL, true); - publisher(mosq, topic_base((char *)"NBIRTH"), NULL, true); - publisher(mosq, topic_base((char *)"NDEATH"), NULL, true); + topic = topic_base((char *)"DBIRTH"); + publisher(mosq, topic, NULL, true); // Not always needed, but ... + free(topic); + topic = topic_base((char *)"DDEATH"); + publisher(mosq, topic, NULL, true); + free(topic); + topic = topic_base((char *)"NBIRTH"); + publisher(mosq, topic, NULL, true); + free(topic); + topic = topic_base((char *)"NDEATH"); + publisher(mosq, topic, NULL, true); + free(topic); mqtt_last_mid = mqtt_mid_sent; mqtt_status = STATUS_WAITING; mqtt_my_shutdown = TRUE; diff -r 88c398efc728 -r fcfc3dbe85fa thermferm/rdconfig.c --- a/thermferm/rdconfig.c Thu Aug 02 13:39:30 2018 +0200 +++ b/thermferm/rdconfig.c Fri Aug 03 16:13:17 2018 +0200 @@ -42,12 +42,12 @@ void killconfig(void) { - units_list *tmp2; - profiles_list *tmp3; - prof_step *tmp4; - devices_list *device; + units_list *tmp2, *oldtmp2; + profiles_list *tmp3, *oldtmp3; + prof_step *tmp4, *oldtmp4; + devices_list *device, *olddev; #ifdef USE_SIMULATOR - simulator_list *simulator; + simulator_list *simulator, *oldsim; #endif if (Config.name) @@ -79,7 +79,8 @@ free(Config.uuid); Config.uuid = NULL; - for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { + for (tmp2 = Config.units; tmp2; tmp2 = oldtmp2) { + oldtmp2 = tmp2->next; if (tmp2->uuid) free(tmp2->uuid); if (tmp2->product_uuid) @@ -108,17 +109,23 @@ free(tmp2->psu_address); if (tmp2->profile) free(tmp2->profile); + if (tmp2->PID_cool) + free(tmp2->PID_cool); + if (tmp2->PID_heat) + free(tmp2->PID_heat); free(tmp2); } Config.units = NULL; - for (tmp3 = Config.profiles; tmp3; tmp3 = tmp3->next) { + for (tmp3 = Config.profiles; tmp3; tmp3 = oldtmp3) { + oldtmp3 = tmp3->next; if (tmp3->uuid) free(tmp3->uuid); if (tmp3->name) free(tmp3->name); if (tmp3->steps) { - for (tmp4 = tmp3->steps; tmp4; tmp4 = tmp4->next) { + for (tmp4 = tmp3->steps; tmp4; tmp4 = oldtmp4) { + oldtmp4 = tmp4->next; free(tmp4); } } @@ -126,7 +133,8 @@ } Config.profiles = NULL; - for (device = Config.devices; device; device = device->next) { + for (device = Config.devices; device; device = olddev) { + olddev = device->next; if (device->uuid) free(device->uuid); if (device->address) @@ -140,7 +148,8 @@ Config.devices = NULL; #ifdef USE_SIMULATOR - for (simulator = Config.simulators; simulator; simulator = simulator->next) { + for (simulator = Config.simulators; simulator; simulator = oldsim) { + oldsim = simulator->next; if (simulator->uuid) free(simulator->uuid); if (simulator->name) @@ -2266,6 +2275,8 @@ xmlFree(key); } if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_HOST"))) { + if (Config.mqtt_host) + free(Config.mqtt_host); Config.mqtt_host = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_PORT"))) { diff -r 88c398efc728 -r fcfc3dbe85fa thermferm/slcd.c --- a/thermferm/slcd.c Thu Aug 02 13:39:30 2018 +0200 +++ b/thermferm/slcd.c Fri Aug 03 16:13:17 2018 +0200 @@ -38,7 +38,7 @@ void putLCDsocket(int fd, uint16_t data) { - socklen_t slen; + socklen_t slen = 0; uint16_t rdat; if (sock == -1) diff -r 88c398efc728 -r fcfc3dbe85fa thermferm/thermferm.c --- a/thermferm/thermferm.c Thu Aug 02 13:39:30 2018 +0200 +++ b/thermferm/thermferm.c Fri Aug 03 16:13:17 2018 +0200 @@ -968,6 +968,7 @@ } } + killconfig(); syslog(LOG_NOTICE, "Finished, rc=%d", rc); return rc; } @@ -2084,6 +2085,7 @@ } sock = -1; } + lcd_buf_reset(); wrconfig(); ulockprog((char *)"thermferm");