From 866b01740d8fb5bd82d7a6b62566eb722647f2a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ture=20P=C3=A5lsson?= <ture@lysator.liu.se>
Date: Fri, 5 Dec 2014 09:16:45 +0100
Subject: [PATCH] Mode nodes malloc outside loop

---
 src/protobuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/protobuf.c b/src/protobuf.c
index 1e66cc3..21959ec 100644
--- a/src/protobuf.c
+++ b/src/protobuf.c
@@ -1338,13 +1338,13 @@ parse_pbf_nodes (readosm_string_table * strings,
 	  int max_nodes;
 	  int base = 0;
 	  nd_count = packed_ids.count;
+          nodes = malloc (sizeof (readosm_internal_node) * MAX_NODES);
 	  while (base < nd_count)
 	    {
 		/* processing about 1024 nodes at each time */
 		max_nodes = MAX_NODES;
 		if ((nd_count - base) < MAX_NODES)
 		    max_nodes = nd_count - base;
-		nodes = malloc (sizeof (readosm_internal_node) * max_nodes);
 		for (i = 0; i < max_nodes; i++)
 		  {
 		      /* initializing an array of empty internal Nodes */
@@ -1461,9 +1461,9 @@ parse_pbf_nodes (readosm_string_table * strings,
 			    nd = nodes + i;
 			    destroy_internal_node (nd);
 			}
-		      free (nodes);
 		  }
 	    }
+          free(nodes);
       }
 
 /* memory cleanup */
-- 
GitLab