Small fixes for device configuration

Thu, 31 Jul 2014 19:29:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 31 Jul 2014 19:29:54 +0200
changeset 161
493e39bb0a08
parent 160
87bfa951ffc2
child 162
6fc9e3f7962f

Small fixes for device configuration

thermferm/devices.c file | annotate | diff | comparison | revisions
thermferm/rdconfig.c file | annotate | diff | comparison | revisions
--- a/thermferm/devices.c	Thu Jul 31 17:52:41 2014 +0200
+++ b/thermferm/devices.c	Thu Jul 31 19:29:54 2014 +0200
@@ -41,7 +41,7 @@
     DIR			*fd;
     devices_list	*device, *ndev;
     int			found, subdevices, i, rc = 0;
-    char		*family;
+    char		family[3];
     uuid_t		uu;
 
     /*
@@ -52,15 +52,15 @@
 	    if (de->d_name[0] != '.') {
 		found = FALSE;
 		for (device = Config.devices; device; device = device->next) {
-		    if (strcmp(device->address ,de->d_name) == 0) {
+		    if (strcmp(device->address,de->d_name) == 0) {
 			found = TRUE;
 			break;
 		    }
 		}
 
 		if (found == FALSE) {
-		    family = malloc(3);
 		    strncpy(family, de->d_name, 2);
+		    family[2] = '\0';
 		    subdevices = 1;
 		    if (strcmp(family, (char *)"29") == 0)
 			subdevices = 8;
@@ -103,9 +103,10 @@
 			    Config.devices = ndev;
 			} else {
 			    for (device = Config.devices; device; device = device->next) {
-				if (device->next == NULL)
+				if (device->next == NULL) {
 				    device->next = ndev;
-				break;
+				    break;
+				}
 			    }
 			}
 			rc++;
--- a/thermferm/rdconfig.c	Thu Jul 31 17:52:41 2014 +0200
+++ b/thermferm/rdconfig.c	Thu Jul 31 19:29:54 2014 +0200
@@ -47,6 +47,7 @@
     units_list		*tmp2;
     profiles_list	*tmp3;
     prof_step		*tmp4;
+    devices_list	*device;
 
     if (Config.name)
 	free(Config.name);
@@ -103,6 +104,19 @@
     }
     Config.profiles = NULL;
 
+    for (device = Config.devices; device; device = device->next) {
+	if (device->uuid)
+	    free(device->uuid);
+	if (device->address)
+	    free(device->address);
+	if (device->description)
+	    free(device->description);
+	if (device->comment)
+	    free(device->comment);
+	free(device);
+    }
+    Config.devices = NULL;
+
 #ifdef HAVE_WIRINGPI_H
     Config.lcd_cols = 16;
     Config.lcd_rows = 2;
@@ -1156,7 +1170,7 @@
 		device->gpiopin = ival;
 	    xmlFree(key);                                       
 	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"DESCRPTION"))) {
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"DESCRIPTION"))) {
 	    device->description = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"INUSE"))) {

mercurial