From 0241684ea77e8aa20ad2cb3903589559f4a7b009 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 26 Oct 2005 05:05:16 +0000 Subject: 2005-10-26 Paul Jakma * (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. --- lib/ChangeLog | 10 ++++++++++ lib/if.c | 2 +- lib/if_rmap.c | 22 ++++++++++++---------- lib/memtypes.c | 6 +++++- lib/memtypes.h | 4 ++++ lib/pqueue.c | 18 ++++++++---------- lib/routemap.c | 8 ++++---- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 26b478bf..8abae69a 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2005-10-26 Paul Jakma + + * (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 * sockopt.c: (setsockopt_multicast_ipv4) If IP_ADD_MEMBERSHIP diff --git a/lib/if.c b/lib/if.c index a57da352..5e440c33 100644 --- a/lib/if.c +++ b/lib/if.c @@ -495,7 +495,7 @@ DEFUN (no_interface_desc, 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 6730e94c..e6f753c2 100644 --- a/lib/if_rmap.c +++ b/lib/if_rmap.c @@ -47,12 +47,12 @@ static void 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 @@ if_rmap_hash_alloc (void *arg) 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_rmap_set (const char *ifname, enum if_rmap_type type, 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_rmap_unset (const char *ifname, enum if_rmap_type type, 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_rmap_unset (const char *ifname, enum if_rmap_type type, 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 f7c07fbb..4aac2f78 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 @@ struct memory_list memory_list_lib[] = { 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 @@ struct memory_list memory_list_lib[] = { 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 e3120796..a0eb893d 100644 --- a/lib/memtypes.h +++ b/lib/memtypes.h @@ -52,6 +52,7 @@ enum MTYPE_KEY, MTYPE_KEYCHAIN, MTYPE_IF_RMAP, + MTYPE_IF_RMAP_NAME, MTYPE_SOCKUNION, MTYPE_PRIVS, MTYPE_ZLOG, @@ -59,6 +60,9 @@ enum 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 2bbafe7c..a974a49e 100644 --- a/lib/pqueue.c +++ b/lib/pqueue.c @@ -20,6 +20,7 @@ Boston, MA 02111-1307, USA. */ #include +#include "memory.h" #include "pqueue.h" /* priority queue using heap sort */ @@ -110,12 +111,10 @@ pqueue_create (void) { 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 @@ pqueue_create (void) 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 @@ pqueue_expand (struct pqueue *queue) { 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 a9d94f27..85491ead 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -314,7 +314,7 @@ route_map_index_delete (struct route_map_index *index, int notify) /* 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 @@ DEFUN (rmap_call, 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 @@ DEFUN (no_rmap_call, if (index->nextrm) { - free (index->nextrm); + XFREE (MTYPE_ROUTE_MAP_NAME, index->nextrm); index->nextrm = NULL; } -- cgit v1.2.1