[GRASS-SVN] r36492 - grass/trunk/lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 27 08:20:31 EDT 2009


Author: mmetz
Date: 2009-03-27 08:20:31 -0400 (Fri, 27 Mar 2009)
New Revision: 36492

Modified:
   grass/trunk/lib/vector/diglib/plus.c
   grass/trunk/lib/vector/diglib/struct_alloc.c
Log:
diglib free structures modified

Modified: grass/trunk/lib/vector/diglib/plus.c
===================================================================
--- grass/trunk/lib/vector/diglib/plus.c	2009-03-26 20:10:48 UTC (rev 36491)
+++ grass/trunk/lib/vector/diglib/plus.c	2009-03-27 12:20:31 UTC (rev 36492)
@@ -120,11 +120,7 @@
 	    if (Node == NULL)
 		continue;
 
-	    if (Node->alloc_lines > 0) {
-		free(Node->lines);
-		free(Node->angles);
-	    }
-	    free(Node);
+	    dig_free_node(Node);
 	}
 	free(Plus->Node);
     }
@@ -152,7 +148,7 @@
 	    if (Line == NULL)
 		continue;
 
-	    free(Line);
+	    dig_free_line(Line);
 	}
 	free(Plus->Line);
     }
@@ -188,13 +184,7 @@
 	    if (Area == NULL)
 		continue;
 
-	    if (Area->alloc_lines > 0)
-		free(Area->lines);
-
-	    if (Area->alloc_isles > 0)
-		free(Area->isles);
-
-	    free(Area);
+	    dig_free_area(Area);
 	}
 	free(Plus->Area);
     }
@@ -222,10 +212,7 @@
 	    if (Isle == NULL)
 		continue;
 
-	    if (Isle->alloc_lines > 0)
-		free(Isle->lines);
-
-	    free(Isle);
+	    dig_free_isle(Isle);
 	}
 	free(Plus->Isle);
     }

Modified: grass/trunk/lib/vector/diglib/struct_alloc.c
===================================================================
--- grass/trunk/lib/vector/diglib/struct_alloc.c	2009-03-26 20:10:48 UTC (rev 36491)
+++ grass/trunk/lib/vector/diglib/struct_alloc.c	2009-03-27 12:20:31 UTC (rev 36492)
@@ -44,7 +44,7 @@
 
     Node = (P_NODE *) malloc(sizeof(P_NODE));
     if (Node == NULL)
-	return NULL;
+        return NULL;
 
     Node->n_lines = 0;
     Node->alloc_lines = 0;
@@ -57,8 +57,11 @@
 /* free node structure */
 void dig_free_node(P_NODE *Node)
 {
-    free(Node->lines);
-    free(Node->angles);
+    if (Node->alloc_lines > 0) {
+        free(Node->lines);
+        free(Node->angles);
+    }
+
     free(Node);
 }
 
@@ -80,12 +83,12 @@
 
     p = realloc(node->lines, num * sizeof(plus_t));
     if (p == NULL)
-	return -1;
+        return -1;
     node->lines = (plus_t *) p;
 
     p = realloc(node->angles, num * sizeof(float));
     if (p == NULL)
-	return -1;
+        return -1;
     node->angles = (float *)p;
 
     node->alloc_lines = num;
@@ -107,7 +110,7 @@
     size = Plus->alloc_nodes + 1 + add;
     p = realloc(Plus->Node, size * sizeof(P_NODE *));
     if (p == NULL)
-	return -1;
+        return -1;
 
     Plus->Node = (P_NODE **) p;
     Plus->alloc_nodes = size - 1;
@@ -122,7 +125,7 @@
 
     Line = (P_LINE *) malloc(sizeof(P_LINE));
     if (Line == NULL)
-	return NULL;
+        return NULL;
 
     return (Line);
 }
@@ -147,7 +150,7 @@
     size = Plus->alloc_lines + 1 + add;
     p = realloc(Plus->Line, size * sizeof(P_LINE *));
     if (p == NULL)
-	return -1;
+        return -1;
 
     Plus->Line = (P_LINE **) p;
     Plus->alloc_lines = size - 1;
@@ -169,7 +172,7 @@
     size = Plus->alloc_areas + 1 + add;
     p = realloc(Plus->Area, size * sizeof(P_AREA *));
     if (p == NULL)
-	return -1;
+        return -1;
 
     Plus->Area = (P_AREA **) p;
     Plus->alloc_areas = size - 1;
@@ -192,7 +195,7 @@
     size = Plus->alloc_isles + 1 + add;
     p = realloc(Plus->Isle, size * sizeof(P_ISLE *));
     if (p == NULL)
-	return -1;
+        return -1;
 
     Plus->Isle = (P_ISLE **) p;
     Plus->alloc_isles = size - 1;
@@ -207,7 +210,7 @@
 
     Area = (P_AREA *) malloc(sizeof(P_AREA));
     if (Area == NULL)
-	return NULL;
+        return NULL;
 
     Area->n_lines = 0;
     Area->alloc_lines = 0;
@@ -225,8 +228,12 @@
 /* free area structure */
 void dig_free_area(P_AREA *Area)
 {
-    free(Area->lines);
-    free(Area->isles);
+    if (Area->alloc_lines > 0)
+        free(Area->lines);
+
+    if (Area->alloc_isles > 0)
+        free(Area->isles);
+
     free(Area);
 }
 
@@ -237,7 +244,7 @@
 
     Isle = (P_ISLE *) malloc(sizeof(P_ISLE));
     if (Isle == NULL)
-	return NULL;
+        return NULL;
 
     Isle->n_lines = 0;
     Isle->alloc_lines = 0;
@@ -251,7 +258,9 @@
 /* free isle structure */
 void dig_free_isle(P_ISLE *Isle)
 {
-    free(Isle->lines);
+    if (Isle->alloc_lines > 0)
+        free(Isle->lines);
+
     free(Isle);
 }
 
@@ -268,7 +277,7 @@
     if (!(p =
 	  dig__alloc_space(num, &alloced, 50, (char *)points->x,
 			   sizeof(double)))) {
-	return (dig_out_of_memory());
+        return (dig_out_of_memory());
     }
     points->x = (double *)p;
 
@@ -277,7 +286,7 @@
     if (!(p =
 	  dig__alloc_space(num, &alloced, 50, (char *)points->y,
 			   sizeof(double)))) {
-	return (dig_out_of_memory());
+        return (dig_out_of_memory());
     }
     points->y = (double *)p;
 
@@ -286,7 +295,7 @@
     if (!(p =
 	  dig__alloc_space(num, &alloced, 50, (char *)points->z,
 			   sizeof(double)))) {
-	return (dig_out_of_memory());
+        return (dig_out_of_memory());
     }
     points->z = (double *)p;
 
@@ -308,7 +317,7 @@
     if (!(p =
 	  dig__alloc_space(num, &alloced, 1, (int *)cats->field,
 			   sizeof(int)))) {
-	return (dig_out_of_memory());
+        return (dig_out_of_memory());
     }
     cats->field = (int *)p;
 
@@ -316,7 +325,7 @@
     if (!(p =
 	  dig__alloc_space(num, &alloced, 1, (int *)cats->cat,
 			   sizeof(int)))) {
-	return (dig_out_of_memory());
+        return (dig_out_of_memory());
     }
     cats->cat = (int *)p;
 
@@ -338,7 +347,7 @@
 
     p = realloc(area->lines, num * sizeof(plus_t));
     if (p == NULL)
-	return -1;
+        return -1;
     area->lines = (plus_t *) p;
 
     area->alloc_lines = num;
@@ -361,7 +370,7 @@
 
     p = realloc(area->isles, num * sizeof(plus_t));
     if (p == NULL)
-	return -1;
+        return -1;
     area->isles = (plus_t *) p;
 
     area->alloc_isles = num;
@@ -384,7 +393,7 @@
 
     p = realloc(isle->lines, num * sizeof(plus_t));
     if (p == NULL)
-	return -1;
+        return -1;
     isle->lines = (plus_t *) p;
 
     isle->alloc_lines = num;



More information about the grass-commit mailing list