Fixed memory leak in wrconfig

Tue, 02 Jun 2015 19:57:53 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 02 Jun 2015 19:57:53 +0200
changeset 370
843dc511c877
parent 369
71f9c1288f3e
child 371
44665f154ead

Fixed memory leak in wrconfig

thermferm/rdconfig.c file | annotate | diff | comparison | revisions
--- a/thermferm/rdconfig.c	Tue Jun 02 17:50:05 2015 +0200
+++ b/thermferm/rdconfig.c	Tue Jun 02 19:57:53 2015 +0200
@@ -27,7 +27,6 @@
 #include "xutil.h"
 
 int		debug = FALSE;
-static char	*mypath;
 sys_config	Config;			/* System configuration		*/
 
 #define MY_ENCODING "utf-8"
@@ -144,6 +143,7 @@
 {
     int			rc = 0;
     FILE		*fp;
+    char		*mypath = NULL;
     xmlTextWriterPtr	writer;
     xmlBufferPtr	buf;
     units_list		*tmp3;
@@ -916,8 +916,10 @@
 
     if ((fp = fopen(mypath, "w")) == NULL) {
 	syslog(LOG_NOTICE, "could not rewrite %s", mypath);
+	free(mypath);
 	return 1;
     }
+    free(mypath);
 
     fprintf(fp, "%s", (const char *) buf->content);
     fclose(fp);
@@ -1910,6 +1912,7 @@
 int rdconfig(void) 
 {
     int		rc = 0, ival;
+    char	*mypath;
     xmlDocPtr	doc;
     xmlNodePtr	cur;
     xmlChar	*key;

mercurial