lib: do not allocate/free thread funcnames

  This avoids memory heap fragmentation and imposses less load on the
system memory allocator.

* thread.h: FUNCNAME_LEN defined to 64 (ISO C99 says max 63)

Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
[changed FUNCNAME_LEN to a less arbitrary value]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/lib/thread.c b/lib/thread.c
index 3740147..86d0ff8 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -235,7 +235,7 @@
   struct cpu_thread_history *new;
   new = XCALLOC (MTYPE_THREAD_STATS, sizeof (struct cpu_thread_history));
   new->func = a->func;
-  new->funcname = XSTRDUP(MTYPE_THREAD_FUNCNAME, a->funcname);
+  strcpy(new->funcname, a->funcname);
   return new;
 }
 
@@ -244,7 +244,6 @@
 {
   struct cpu_thread_history *hist = a;
  
-  XFREE (MTYPE_THREAD_FUNCNAME, hist->funcname);
   XFREE (MTYPE_THREAD_STATS, hist);
 }
 
@@ -303,7 +302,7 @@
   void *args[3] = {&tmp, vty, &filter};
 
   memset(&tmp, 0, sizeof tmp);
-  tmp.funcname = (char *)"TOTAL";
+  strcpy(tmp.funcname, "TOTAL");
   tmp.types = filter;
 
 #ifdef HAVE_RUSAGE
@@ -577,8 +576,6 @@
   for (t = list->head; t; t = next)
     {
       next = t->next;
-      if (t->funcname)
-        XFREE (MTYPE_THREAD_FUNCNAME, t->funcname);
       XFREE (MTYPE_THREAD, t);
       list->count--;
       m->alloc--;
@@ -636,11 +633,11 @@
 }
 
 /* Trim blankspace and "()"s */
-static char *
-strip_funcname (const char *funcname) 
+void
+strip_funcname (char *dest, const char *funcname)
 {
-  char buff[100];
-  char tmp, *ret, *e, *b = buff;
+  char buff[FUNCNAME_LEN];
+  char tmp, *e, *b = buff;
 
   strncpy(buff, funcname, sizeof(buff));
   buff[ sizeof(buff) -1] = '\0';
@@ -656,10 +653,8 @@
 
   tmp = *e;
   *e = '\0';
-  ret  = XSTRDUP (MTYPE_THREAD_FUNCNAME, b);
+  strcpy (dest, b);
   *e = tmp;
-
-  return ret;
 }
 
 /* Get new thread.  */
@@ -669,12 +664,7 @@
 {
   struct thread *thread = thread_trim_head (&m->unuse);
 
-  if (thread)
-    {
-      if (thread->funcname)
-        XFREE(MTYPE_THREAD_FUNCNAME, thread->funcname);
-    }
-  else
+  if (! thread)
     {
       thread = XCALLOC (MTYPE_THREAD, sizeof (struct thread));
       m->alloc++;
@@ -685,7 +675,7 @@
   thread->func = func;
   thread->arg = arg;
   
-  thread->funcname = strip_funcname(funcname);
+  strip_funcname (thread->funcname, funcname);
 
   return thread;
 }
@@ -953,7 +943,6 @@
 {
   *fetch = *thread;
   thread->type = THREAD_UNUSED;
-  thread->funcname = NULL;  /* thread_call will free fetch's copied pointer */
   thread_add_unuse (m, thread);
   return fetch;
 }
@@ -1187,7 +1176,7 @@
       struct cpu_thread_history tmp;
       
       tmp.func = thread->func;
-      tmp.funcname = thread->funcname;
+      strcpy(tmp.funcname, thread->funcname);
       
       thread->hist = hash_get (cpu_record, &tmp, 
                     (void * (*) (void *))cpu_record_hash_alloc);
@@ -1227,8 +1216,6 @@
 		 realtime/1000, cputime/1000);
     }
 #endif /* CONSUMED_TIME_CHECK */
-
-  XFREE (MTYPE_THREAD_FUNCNAME, thread->funcname);
 }
 
 /* Execute thread */
@@ -1249,10 +1236,8 @@
   dummy.func = func;
   dummy.arg = arg;
   dummy.u.val = val;
-  dummy.funcname = strip_funcname (funcname);
+  strip_funcname (dummy.funcname, funcname);
   thread_call (&dummy);
 
-  XFREE (MTYPE_THREAD_FUNCNAME, dummy.funcname);
-
   return NULL;
 }