2005-10-26 Paul Jakma <paul.jakma@sun.com>

	* (general) Cleanup a some calls to XFREE,strdup, etc. to use
	  the memory.h macros.
	* memtypes.c: Add MTYPE_IF_RMAP_NAME, MTYPE_PQUEUE,
	  MTYPE_PQUEUE_DATA and MTYPE_HOST.
	* memtypes.h: update auto-built file.
	* if_rmap.c: Use MTYPE_IF_RMAP_NAME.
	* pqueue.c: Use the two MTYPE_PQUEUE mtypes for allocations.
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 26b478b..8abae69 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,13 @@
+2005-10-26 Paul Jakma <paul.jakma@sun.com>
+
+	* (general) Cleanup a some calls to XFREE,strdup, etc. to use
+	  the memory.h macros.
+	* memtypes.c: Add MTYPE_IF_RMAP_NAME, MTYPE_PQUEUE,
+	  MTYPE_PQUEUE_DATA and MTYPE_HOST.
+	* memtypes.h: update auto-built file.
+	* if_rmap.c: Use MTYPE_IF_RMAP_NAME.
+	* pqueue.c: Use the two MTYPE_PQUEUE mtypes for allocations.
+
 2005-10-20 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
 	* sockopt.c: (setsockopt_multicast_ipv4) If IP_ADD_MEMBERSHIP
diff --git a/lib/if.c b/lib/if.c
index a57da35..5e440c3 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -495,7 +495,7 @@
 
   ifp = vty->index;
   if (ifp->desc)
-    XFREE (0, ifp->desc);
+    XFREE (MTYPE_TMP, ifp->desc);
   ifp->desc = NULL;
 
   return CMD_SUCCESS;
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index 6730e94..e6f753c 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -47,12 +47,12 @@
 if_rmap_free (struct if_rmap *if_rmap)
 {
   if (if_rmap->ifname)
-    free (if_rmap->ifname);
+    XFREE (MTYPE_IF_RMAP_NAME, if_rmap->ifname);
 
   if (if_rmap->routemap[IF_RMAP_IN])
-    free (if_rmap->routemap[IF_RMAP_IN]);
+    XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
   if (if_rmap->routemap[IF_RMAP_OUT])
-    free (if_rmap->routemap[IF_RMAP_OUT]);
+    XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
 
   XFREE (MTYPE_IF_RMAP, if_rmap);
 }
@@ -90,7 +90,7 @@
   struct if_rmap *if_rmap;
 
   if_rmap = if_rmap_new ();
-  if_rmap->ifname = strdup (ifarg->ifname);
+  if_rmap->ifname = XSTRDUP (MTYPE_IF_RMAP_NAME, ifarg->ifname);
 
   return if_rmap;
 }
@@ -140,14 +140,16 @@
   if (type == IF_RMAP_IN)
     {
       if (if_rmap->routemap[IF_RMAP_IN])
-	free (if_rmap->routemap[IF_RMAP_IN]);
-      if_rmap->routemap[IF_RMAP_IN] = strdup (routemap_name);
+	XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
+      if_rmap->routemap[IF_RMAP_IN] 
+        = XSTRDUP (MTYPE_IF_RMAP_NAME, routemap_name);
     }
   if (type == IF_RMAP_OUT)
     {
       if (if_rmap->routemap[IF_RMAP_OUT])
-	free (if_rmap->routemap[IF_RMAP_OUT]);
-      if_rmap->routemap[IF_RMAP_OUT] = strdup (routemap_name);
+	XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
+      if_rmap->routemap[IF_RMAP_OUT] 
+        = XSTRDUP (MTYPE_IF_RMAP_NAME, routemap_name);
     }
 
   if (if_rmap_add_hook)
@@ -173,7 +175,7 @@
       if (strcmp (if_rmap->routemap[IF_RMAP_IN], routemap_name) != 0)
 	return 0;
 
-      free (if_rmap->routemap[IF_RMAP_IN]);
+      XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
       if_rmap->routemap[IF_RMAP_IN] = NULL;      
     }
 
@@ -184,7 +186,7 @@
       if (strcmp (if_rmap->routemap[IF_RMAP_OUT], routemap_name) != 0)
 	return 0;
 
-      free (if_rmap->routemap[IF_RMAP_OUT]);
+      XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
       if_rmap->routemap[IF_RMAP_OUT] = NULL;      
     }
 
diff --git a/lib/memtypes.c b/lib/memtypes.c
index f7c07fb..4aac2f7 100644
--- a/lib/memtypes.c
+++ b/lib/memtypes.c
@@ -6,7 +6,7 @@
  * The script is sensitive to the format (though not whitespace), see
  * the top of memtypes.awk for more details.
  *
- * $Id: memtypes.c,v 1.8 2005/10/18 04:20:33 paul Exp $
+ * $Id: memtypes.c,v 1.9 2005/10/26 05:05:16 paul Exp $
  */
 
 #include "zebra.h"
@@ -60,6 +60,7 @@
   { MTYPE_KEY,			"Key"				},
   { MTYPE_KEYCHAIN,		"Key chain"			},
   { MTYPE_IF_RMAP,		"Interface route map"		},
+  { MTYPE_IF_RMAP_NAME,		"I.f. route map name",		},
   { MTYPE_SOCKUNION,		"Socket union"			},
   { MTYPE_PRIVS,		"Privilege information"		},
   { MTYPE_ZLOG,			"Logging"			},
@@ -67,6 +68,9 @@
   { MTYPE_WORK_QUEUE,		"Work queue"			},
   { MTYPE_WORK_QUEUE_ITEM,	"Work queue item"		},
   { MTYPE_WORK_QUEUE_NAME,	"Work queue name string"	},
+  { MTYPE_PQUEUE,		"Priority queue"		},
+  { MTYPE_PQUEUE_DATA,		"Priority queue data"		},
+  { MTYPE_HOST,			"Host config"			},
   { -1, NULL },
 };
 
diff --git a/lib/memtypes.h b/lib/memtypes.h
index e312079..a0eb893 100644
--- a/lib/memtypes.h
+++ b/lib/memtypes.h
@@ -52,6 +52,7 @@
   MTYPE_KEY,
   MTYPE_KEYCHAIN,
   MTYPE_IF_RMAP,
+  MTYPE_IF_RMAP_NAME,
   MTYPE_SOCKUNION,
   MTYPE_PRIVS,
   MTYPE_ZLOG,
@@ -59,6 +60,9 @@
   MTYPE_WORK_QUEUE,
   MTYPE_WORK_QUEUE_ITEM,
   MTYPE_WORK_QUEUE_NAME,
+  MTYPE_PQUEUE,
+  MTYPE_PQUEUE_DATA,
+  MTYPE_HOST,
   MTYPE_RTADV_PREFIX,
   MTYPE_VRF,
   MTYPE_VRF_NAME,
diff --git a/lib/pqueue.c b/lib/pqueue.c
index 2bbafe7..a974a49 100644
--- a/lib/pqueue.c
+++ b/lib/pqueue.c
@@ -20,6 +20,7 @@
 
 #include <zebra.h>
 
+#include "memory.h"
 #include "pqueue.h"
 
 /* priority queue using heap sort */
@@ -110,12 +111,10 @@
 {
   struct pqueue *queue;
 
-  queue = (struct pqueue *) malloc (sizeof (struct pqueue));
-  memset (queue, 0, sizeof (struct pqueue));
+  queue = XCALLOC (MTYPE_PQUEUE, sizeof (struct pqueue));
 
-  queue->array = (void **)
-    malloc (DATA_SIZE * PQUEUE_INIT_ARRAYSIZE);
-  memset (queue->array, 0, DATA_SIZE * PQUEUE_INIT_ARRAYSIZE);
+  queue->array = XCALLOC (MTYPE_PQUEUE_DATA, 
+                          DATA_SIZE * PQUEUE_INIT_ARRAYSIZE);
   queue->array_size = PQUEUE_INIT_ARRAYSIZE;
 
   /* By default we want nothing to happen when a node changes. */
@@ -126,8 +125,8 @@
 void
 pqueue_delete (struct pqueue *queue)
 {
-  free (queue->array);
-  free (queue);
+  XFREE (MTYPE_PQUEUE_DATA, queue->array);
+  XFREE (MTYPE_PQUEUE, queue);
 }
 
 static int
@@ -135,14 +134,13 @@
 {
   void **newarray;
 
-  newarray = (void **) malloc (queue->array_size * DATA_SIZE * 2);
+  newarray = XCALLOC (MTYPE_PQUEUE_DATA, queue->array_size * DATA_SIZE * 2);
   if (newarray == NULL)
     return 0;
 
-  memset (newarray, 0, queue->array_size * DATA_SIZE * 2);
   memcpy (newarray, queue->array, queue->array_size * DATA_SIZE);
 
-  free (queue->array);
+  XFREE (MTYPE_PQUEUE_DATA, queue->array);
   queue->array = newarray;
   queue->array_size *= 2;
 
diff --git a/lib/routemap.c b/lib/routemap.c
index a9d94f2..85491ea 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -314,7 +314,7 @@
 
   /* Free 'char *nextrm' if not NULL */
   if (index->nextrm)
-    free (index->nextrm);
+    XFREE (MTYPE_ROUTE_MAP_NAME, index->nextrm);
 
     /* Execute event hook. */
   if (route_map_master.event_hook && notify)
@@ -1175,8 +1175,8 @@
   if (index)
     {
       if (index->nextrm)
-          free (index->nextrm);
-      index->nextrm = strdup (argv[0]);
+          XFREE (MTYPE_ROUTE_MAP_NAME, index->nextrm);
+      index->nextrm = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[0]);
     }
   return CMD_SUCCESS;
 }
@@ -1193,7 +1193,7 @@
 
   if (index->nextrm)
     {
-      free (index->nextrm);
+      XFREE (MTYPE_ROUTE_MAP_NAME, index->nextrm);
       index->nextrm = NULL;
     }