Index: trunk/src/sh_mem.c
===================================================================
--- trunk/src/sh_mem.c	(revision 144)
+++ trunk/src/sh_mem.c	(revision 149)
@@ -47,5 +47,4 @@
 #undef  FIL__
 #define FIL__  _("sh_mem.c")
-static int eblock = 0;
 
 #ifdef MEM_DEBUG
@@ -74,47 +73,13 @@
 unsigned long Mem_Current = 0, Mem_Max = 0;
 
-#if 0
-#define MEM_DETAILS 
-#endif
-
-#ifdef MEM_DETAILS
-int           max_upto_032 = 0;
-int           max_upto_064 = 0;
-int           max_upto_128 = 0;
-int           max_upto_256 = 0;
-int           max_upto_512 = 0;
-int           max_upto_1024 = 0;
-int           max_upto_4096 = 0;
-int           max_upto_inf = 0;
-
-int           now_upto_032 = 0;
-int           now_upto_064 = 0;
-int           now_upto_128 = 0;
-int           now_upto_256 = 0;
-int           now_upto_512 = 0;
-int           now_upto_1024 = 0;
-int           now_upto_4096 = 0;
-int           now_upto_inf = 0;
-
-int           tot_upto_032 = 0;
-int           tot_upto_064 = 0;
-int           tot_upto_128 = 0;
-int           tot_upto_256 = 0;
-int           tot_upto_512 = 0;
-int           tot_upto_1024 = 0;
-int           tot_upto_4096 = 0;
-int           tot_upto_inf = 0;
-#endif
-
 #ifdef HAVE_PTHREAD
 SH_MUTEX_RECURSIVE(mutex_mem);
 #endif
 
+/* define MEM_LOG to an absolute filename to enable this */
 #ifdef MEM_LOG
 void sh_mem_dump ()
 {
   memlist_t   * this = memlist;
-
-
   FILE * fd;
 
@@ -123,13 +88,20 @@
 
   fd = fopen(MEM_LOG, "w");
+  if (!fd)
+    {
+      perror(MEM_LOG);
+      _exit(EXIT_FAILURE);
+    }
 
   while (this != NULL)
     {
-      fprintf (fd, "%20s %5d %ld\n",  this->file, this->line, this->size);
+      fprintf (fd, "## %20s %5d %ld\n",  this->file, this->line, this->size);
+      fprintf (fd, "%10p %8ld\n", (void *)this->address, this->size);
       this = this->next;
     }
   fclose(fd);
-  SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem);
-  return;
+
+  SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem);
+  _exit(EXIT_SUCCESS);
 }
 #else
@@ -162,18 +134,4 @@
 		   Mem_Max, Mem_Current);
 
-#ifdef MEM_DETAILS
-  fprintf(stderr, "\n");
-  fprintf(stderr, "__SIZE_____TOTAL___MAXIMUM___\n");
-  fprintf(stderr, "    32    %6d    %6d\n", tot_upto_032, max_upto_032);
-  fprintf(stderr, "    64    %6d    %6d\n", tot_upto_064, max_upto_064);
-  fprintf(stderr, "   128    %6d    %6d\n", tot_upto_128, max_upto_128);
-  fprintf(stderr, "   256    %6d    %6d\n", tot_upto_256, max_upto_256);
-  fprintf(stderr, "   512    %6d    %6d\n", tot_upto_512, max_upto_512);
-  fprintf(stderr, "  1024    %6d    %6d\n", tot_upto_1024, max_upto_1024);
-  fprintf(stderr, "  4096    %6d    %6d\n", tot_upto_4096, max_upto_4096);
-  fprintf(stderr, "   inf    %6d    %6d\n", tot_upto_inf, max_upto_inf);
-  fprintf(stderr, "\n");
-#endif
-
   this = memlist;
 
@@ -199,4 +157,5 @@
   SH_MUTEX_RECURSIVE_INIT(mutex_mem);
   SH_MUTEX_RECURSIVE_LOCK(mutex_mem);
+
   sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_MSTAMP,
 		   Mem_Max, Mem_Current);
@@ -229,5 +188,4 @@
     }
 
-  /* if (nerr > 0) abort(); */
 
   SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem);
@@ -249,13 +207,9 @@
   if ( the_realAddress  == NULL ) 
     {
-      if (eblock == 0)
-	{
-	  eblock = 1;
-	  (void) safe_logger (0, 0, NULL);
-	  eblock = 0;
-	}
+      (void) safe_logger (0, 0, NULL);
+
       /* use _exit() rather than exit() - we malloc() in atexit() functions 
        */
-      _exit (42);
+      _exit (EXIT_FAILURE);
     }
   
@@ -274,60 +228,4 @@
     Max_Alloc_Count = Now_Alloc_Count;
 
-#ifdef MEM_DETAILS
-  if (size <= 32)
-    { 
-      ++now_upto_032;
-      ++tot_upto_032;
-      if (now_upto_032 > max_upto_032) max_upto_032 = now_upto_032;
-    }
-  else if  (size <= 64)
-    { 
-      ++now_upto_064;
-      ++tot_upto_064;
-      if (now_upto_064 > max_upto_064) max_upto_064 = now_upto_064;
-    }
-  else if  (size <= 128)
-    { 
-      ++now_upto_128;
-      ++tot_upto_128;
-      if (now_upto_128 > max_upto_128) max_upto_128 = now_upto_128;
-    }
-  else if  (size <= 256)
-    { 
-      ++now_upto_256;
-      ++tot_upto_256;
-      if (now_upto_256 > max_upto_256) max_upto_256 = now_upto_256;
-    }
-  else if  (size <= 512)
-    { 
-      ++now_upto_512;
-      ++tot_upto_512;
-      if (now_upto_512 > max_upto_512) max_upto_512 = now_upto_512;
-    }
-  else if  (size <= 1024)
-    { 
-      ++now_upto_1024;
-      ++tot_upto_1024;
-      if (now_upto_1024 > max_upto_1024) max_upto_1024 = now_upto_1024;
-    }
-  else if  (size <= 4096)
-    { 
-      ++now_upto_4096;
-      ++tot_upto_4096;
-      if (now_upto_4096 > max_upto_4096) max_upto_4096 = now_upto_4096;
-    }
-  else 
-    { 
-      ++now_upto_inf;
-      ++tot_upto_inf;
-      if (now_upto_inf > max_upto_inf) max_upto_inf = now_upto_inf;
-
-      fprintf(stderr, "\n___BIGSIZE___");
-      fprintf(stderr, "   %6d  -> %16s  %10d \n", size, file, line);
-      fprintf(stderr, "\n");
-
-    }
-#endif
-
   Mem_Current += size;
   Mem_Max = ( (Mem_Current > Mem_Max) ? Mem_Current : Mem_Max);
@@ -337,11 +235,7 @@
   if ( this == NULL) 
     {
-      if (eblock == 0)
-	{
-	  eblock = 1;
-	  (void) safe_logger(0, 0, NULL);
-	  eblock = 0;
-	}
-      _exit(42);
+      (void) safe_logger(0, 0, NULL);
+
+      _exit(EXIT_FAILURE);
     }
   else
@@ -374,4 +268,5 @@
   SH_MUTEX_RECURSIVE_INIT(mutex_mem);
   SH_MUTEX_RECURSIVE_LOCK(mutex_mem);
+
   if ( a == NULL ) 
     {
@@ -424,23 +319,4 @@
   --Now_Alloc_Count;
 
-#ifdef MEM_DETAILS
-  if (size <= 32)
-    --now_upto_032;
-  else if  (size <= 64)
-    --now_upto_064;
-  else if  (size <= 128)
-    --now_upto_128;
-  else if  (size <= 256)
-    --now_upto_256;
-  else if  (size <= 512)
-    --now_upto_512;
-  else if  (size <= 1024)
-    --now_upto_1024;
-  else if  (size <= 4096)
-    --now_upto_4096;
-  else 
-    --now_upto_inf;
-#endif
-
   Mem_Current -= size;
  out:
@@ -475,19 +351,16 @@
   theAddress = malloc(size);
 
-  if ( theAddress == NULL ) 
-    {
-      if (eblock == 0)
-	{
-	  eblock = 1;
-	  (void) safe_logger(0, 0, NULL);
-	  eblock = 0;
-	}
+  if ( theAddress != NULL ) 
+    {
+      SL_RETURN( theAddress, _("sh_mem_malloc"));
+    }
+  else
+    {
+      (void) safe_logger(0, 0, NULL);
+
       /* use _exit() rather than exit() - we malloc() in atexit()  
        */
-      _exit (42);
-    }
-  /* memset (theAddress, 0, 1); *//* needs testing */
-
-  SL_RETURN( theAddress, _("sh_mem_malloc"));
-}
-#endif
+      _exit (EXIT_FAILURE);
+    }
+}
+#endif
