[GRASS-SVN] r42026 - grass-addons/raster/r.fuzzy.system

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 25 02:17:46 EDT 2010


Author: jarekj71
Date: 2010-04-25 02:17:41 -0400 (Sun, 25 Apr 2010)
New Revision: 42026

Modified:
   grass-addons/raster/r.fuzzy.system/main.c
   grass-addons/raster/r.fuzzy.system/rule_parser.c
   grass-addons/raster/r.fuzzy.system/system.c
Log:
fixing memory leaks

Modified: grass-addons/raster/r.fuzzy.system/main.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/main.c	2010-04-24 23:05:10 UTC (rev 42025)
+++ grass-addons/raster/r.fuzzy.system/main.c	2010-04-25 06:17:41 UTC (rev 42026)
@@ -160,10 +160,9 @@
 
     if ((outfd = G_open_raster_new(output, FCELL_TYPE)) < 0)
 	G_fatal_error(_("Unable to create raster map <%s>"), output);
+    
     out_buf = G_allocate_f_raster_buf();
 
-
-
     if (multiple)
 	create_output_maps();
 	antecedents = (float *)G_malloc(nrules * sizeof(float));
@@ -174,7 +173,6 @@
 	G_percent(row, nrows, 2);
 	get_rows(row);
 	for (col = 0; col < ncols; ++col) {
-
 	    if (get_cells(col)) {
 		G_set_f_null_value(&out_buf[col], 1);
 
@@ -199,12 +197,13 @@
 	    G_fatal_error(_("Failed writing raster map <%s> at row <%d>"),
 			  output, row);
 
-	if (multiple)
+	if (multiple) 
 	    for (i = 0; i < nrules; ++i)
 		if (G_put_raster_row
 		    (m_outputs[i].ofd, m_outputs[i].out_buf, FCELL_TYPE) < 0)
 		    G_fatal_error(_("Failed writing raster map <%s> at row <%d>"),
 				  m_outputs[i].output_name, row);
+
     }
     G_percent(row, nrows, 2);
 
@@ -233,7 +232,7 @@
 	    G_command_history(&history);
 	    G_write_history(m_outputs[i].output_name, &history);
 	}
-    G_message("Done!");
+   G_message("Done!");
     exit(EXIT_SUCCESS);
 
 }

Modified: grass-addons/raster/r.fuzzy.system/rule_parser.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/rule_parser.c	2010-04-24 23:05:10 UTC (rev 42025)
+++ grass-addons/raster/r.fuzzy.system/rule_parser.c	2010-04-25 06:17:41 UTC (rev 42026)
@@ -27,7 +27,7 @@
     s_rules = (RULES *) G_malloc((nrules) * sizeof(RULES));
     rules = (char **)G_malloc((nrules) * sizeof(char *));
     for (i = 0; i < nrules; ++i)
-	rules[i] = (char *)G_malloc(21 * sizeof(char *));
+	rules[i] = (char *)G_malloc(21 * sizeof(char));
 
     fsetpos(fd, &init);		/* reset position */
 
@@ -77,6 +77,9 @@
 	G_strip(buf);
 	G_strip(tmp);
 
+		for (p = 0; p <= rule_num; ++p)
+	strcpy(rules[p],"");
+	
 	done = 1;
 	for (s = 0; s <= s_maps[n - 1].nsets; ++s) {	/* output map */
 

Modified: grass-addons/raster/r.fuzzy.system/system.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/system.c	2010-04-24 23:05:10 UTC (rev 42025)
+++ grass-addons/raster/r.fuzzy.system/system.c	2010-04-25 06:17:41 UTC (rev 42026)
@@ -35,12 +35,14 @@
 
 	if (defuzzyfication > d_BISECTOR && antecedents[j] < max_antecedent)
 	    continue;
+	    
+	    set_index = s_rules[j].output_set_index; //było niżej
 
 	for (i = 0; i < resolution; ++i) {
-
+	    
 	    consequent = fuzzy(universe[i],
 			       &s_maps[output_index].sets[set_index]);
-	    set_index = s_rules[j].output_set_index;
+	    
 	    consequent = (!implication) ? MIN(antecedents[j], consequent) :
 		antecedents[j] * consequent;
 	    agregate[i] = MAX(agregate[i], consequent);



More information about the grass-commit mailing list