From b67792520cd64cf1875fc14084dce1bd78e33b6b Mon Sep 17 00:00:00 2001 From: Karl Heuer Date: Tue, 29 Jun 1999 17:14:31 +0000 Subject: [PATCH] [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. --- src/emacs.c | 55 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 859e1dd9fd..5721c2c982 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -545,27 +545,17 @@ argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr) } } -/* ARGSUSED */ -int -main (argc, argv, envp) - int argc; - char **argv; - char **envp; -{ - char stack_bottom_variable; - int skip_args = 0; - extern int errno; - extern int sys_nerr; -#ifdef HAVE_SETRLIMIT - struct rlimit rlim; -#endif - int no_loadup = 0; +#ifdef DOUG_LEA_MALLOC -#ifdef LINUX_SBRK_BUG - __sbrk (1); -#endif +/* 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; -#ifdef DOUG_LEA_MALLOC if (initialized) { if (!malloc_using_checking) @@ -575,7 +565,7 @@ main (argc, argv, envp) { char **p; - for (p = envp; *p; p++) + for (p = environ; *p; p++) if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0) { do @@ -584,11 +574,36 @@ main (argc, argv, envp) 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) + int argc; + char **argv; + char **envp; +{ + char stack_bottom_variable; + int skip_args = 0; + extern int errno; + extern int sys_nerr; +#ifdef HAVE_SETRLIMIT + struct rlimit rlim; +#endif + int no_loadup = 0; + +#ifdef LINUX_SBRK_BUG + __sbrk (1); #endif #ifdef RUN_TIME_REMAP -- 2.20.1