--- metrics.c-xxx	2008-02-14 12:34:24.000000000 +0100
+++ metrics.c	2008-02-14 13:35:06.000000000 +0100
@@ -117,7 +117,7 @@
   return hval % NHASH;
 }
 
-static net_dev_stats *hash_lookup(char *name, const int enter, 
+static net_dev_stats *hash_lookup(char *devname, size_t nlen, const int enter, 
 				  const double pkts_in, 
 				  const double pkts_out, 
 				  const double bytes_in, 
@@ -125,12 +125,15 @@
 {
   int hval;
   net_dev_stats *stats;
+  char *name=strndup(devname,nlen);
 
   hval = hashval(name);
   for (stats = netstats[hval]; stats != NULL; stats = stats->next)
   {
-    if (strcmp(name, stats->name) == 0)
+    if (strcmp(name, stats->name) == 0) {
+      free(name);
       return stats;
+    }
   }
 
   if (enter)
@@ -139,9 +142,10 @@
     if ( stats == NULL )
     {   
       err_msg("unable to allocate memory for /proc/net/dev/stats in hash_lookup()");
+      free(name);
       return NULL;
     }
-    stats->name = name;
+    stats->name = strndup(devname,nlen);
     stats->pkts_in   = pkts_in;
     stats->pkts_out  = pkts_out;
     stats->bytes_in  = bytes_in;
@@ -149,6 +153,7 @@
     stats->next = netstats[hval];
     netstats[hval] = stats;
   }
+  free(name);
   return stats;
 }
 
@@ -214,7 +219,7 @@
 	    {
 	       /*  skip past the interface tag portion of this line */
 	       /*  but save the name of the interface (hash key) */
-	       char *devname, *src;
+	       char *src;
 	       size_t n = 0;
 
 	       while (p != 0x00 && isblank(*p))
@@ -225,7 +230,6 @@
 		     n++;
 		     p++;
 		  }
-	       devname = strndup(src, n);
 
 	       p = index(p, ':')+1;
 	       if ( ((*(p-2) != 'o') && (*(p-3) != 'l')) && 
@@ -235,7 +239,7 @@
 		     double temp = 0.;
 		     /* Check for data from the last read for this */
 		     /* interface.  If nothing exists, add to the table. */
-		     net_dev_stats *ns = hash_lookup(devname, 1, 
+		     net_dev_stats *ns = hash_lookup(src, n, 1, 
 						     0., 0., 0., 0.);
 		     if ( ns == NULL )
 		        {
@@ -302,7 +306,7 @@
 	    {
 	       /*  skip past the interface tag portion of this line */
 	       /*  but save the name of the interface (hash key) */
-	       char *devname, *src;
+	       char *src;
 	       size_t n = 0;
 
 	       while (p != 0x00 && isblank(*p))
@@ -313,7 +317,6 @@
 		     n++;
 		     p++;
 		  }
-	       devname = strndup(src, n);
 
 	       p = index(p, ':')+1;
 	       if ( ((*(p-2) != 'o') && (*(p-3) != 'l')) && 
@@ -323,7 +326,7 @@
 		     double temp = 0.;
 		     /* Check for data from the last read for this */
 		     /* interface.  If nothing exists, add to the table. */
-		     net_dev_stats *ns = hash_lookup(devname, 1, 
+		     net_dev_stats *ns = hash_lookup(src, n, 1, 
 						     0., 0., 0., 0.);
 		     if ( ns == NULL )
 		        {
@@ -390,7 +393,7 @@
 	    {
 	       /*  skip past the interface tag portion of this line */
 	       /*  but save the name of the interface (hash key) */
-	       char *devname, *src;
+	       char *src;
 	       size_t n = 0;
 
 	       while (p != 0x00 && isblank(*p))
@@ -401,7 +404,6 @@
 		     n++;
 		     p++;
 		  }
-	       devname = strndup(src, n);
 
 	       p = index(p, ':')+1;
 	       if ( ((*(p-2) != 'o') && (*(p-3) != 'l')) && 
@@ -411,7 +413,7 @@
 		     double temp = 0.;
 		     /* Check for data from the last read for this */
 		     /* interface.  If nothing exists, add to the table. */
-		     net_dev_stats *ns = hash_lookup(devname, 1, 
+		     net_dev_stats *ns = hash_lookup(src, n, 1, 
 						     0., 0., 0., 0.);
 		     if ( ns == NULL )
 		        {
@@ -478,7 +480,7 @@
 	    {
 	       /*  skip past the interface tag portion of this line */
 	       /*  but save the name of the interface (hash key) */
-	       char *devname, *src;
+	       char *src;
 	       size_t n = 0;
 
 	       while (p != 0x00 && isblank(*p))
@@ -489,7 +491,6 @@
 		     n++;
 		     p++;
 		  }
-	       devname = strndup(src, n);
 
 	       p = index(p, ':')+1;
 	       if ( ((*(p-2) != 'o') && (*(p-3) != 'l')) && 
@@ -499,7 +500,7 @@
 		     double temp = 0.;
 		     /* Check for data from the last read for this */
 		     /* interface.  If nothing exists, add to the table. */
-		     net_dev_stats *ns = hash_lookup(devname, 1, 
+		     net_dev_stats *ns = hash_lookup(src, n, 1, 
 						     0., 0., 0., 0.);
 		     if ( ns == NULL )
 		        {
