changeset 24900:b57b0a4e4230

[DOUG_LEA_MALLOC] (malloc_initialize_hook): Move the handling of MALLOC_CHECK_ envvar here. (main): Moved from here. [DOUG_LEA_MALLOC] (malloc_initialize_hook): New function, assigned to the global __malloc_initialize_hook pointer. (main): Move malloc_set_state call into malloc_initialize_hook so that it happens as early as possible.
author Karl Heuer <kwzh@gnu.org>
date Tue, 29 Jun 1999 17:14:31 +0000
parents 64ccdc0f6af9
children f294890b7555
files src/emacs.c
diffstat 1 files changed, 41 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/emacs.c	Tue Jun 29 17:06:17 1999 +0000
+++ b/src/emacs.c	Tue Jun 29 17:14:31 1999 +0000
@@ -545,6 +545,47 @@
     }
 }
 
+#ifdef DOUG_LEA_MALLOC
+
+/* malloc can be invoked even before main (e.g. by the dynamic
+   linker), so the dumped malloc state must be restored as early as
+   possible using this special hook.  */
+
+static void
+malloc_initialize_hook ()
+{
+  extern char **environ;
+
+  if (initialized)
+    {
+      if (!malloc_using_checking)
+	/* Work around a bug in glibc's malloc.  MALLOC_CHECK_ must be
+	   ignored if the heap to be restored was constructed without
+	   malloc checking.  Can't use unsetenv, since that calls malloc.  */
+	{
+	  char **p;
+
+	  for (p = environ; *p; p++)
+	    if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0)
+	      {
+		do
+		  *p = p[1];
+		while (*++p);
+		break;
+	      }
+	}
+
+      malloc_set_state (malloc_state_ptr);
+      free (malloc_state_ptr);
+    }
+  else
+    malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
+}
+
+void (*__malloc_initialize_hook) () = malloc_initialize_hook;
+
+#endif /* DOUG_LEA_MALLOC */
+
 /* ARGSUSED */
 int
 main (argc, argv, envp)
@@ -565,32 +606,6 @@
   __sbrk (1);
 #endif
 
-#ifdef DOUG_LEA_MALLOC
-  if (initialized)
-    {
-      if (!malloc_using_checking)
-	/* Work around a bug in glibc's malloc.  MALLOC_CHECK_ must be
-	   ignored if the heap to be restored was constructed without
-	   malloc checking.  Can't use unsetenv, since that calls malloc.  */
-	{
-	  char **p;
-
-	  for (p = envp; *p; p++)
-	    if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0)
-	      {
-		do
-		  *p = p[1];
-		while (*++p);
-		break;
-	      }
-	}
-      malloc_set_state (malloc_state_ptr);
-      free (malloc_state_ptr);
-    }
-  else
-    malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
-#endif
-
 #ifdef RUN_TIME_REMAP
   if (initialized)
     run_time_remap (argv[0]);