comparison src/emacs.c @ 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 930074eb767f
children 16ced12bd3aa
comparison
equal deleted inserted replaced
24899:64ccdc0f6af9 24900:b57b0a4e4230
543 { 543 {
544 return 0; 544 return 0;
545 } 545 }
546 } 546 }
547 547
548 #ifdef DOUG_LEA_MALLOC
549
550 /* malloc can be invoked even before main (e.g. by the dynamic
551 linker), so the dumped malloc state must be restored as early as
552 possible using this special hook. */
553
554 static void
555 malloc_initialize_hook ()
556 {
557 extern char **environ;
558
559 if (initialized)
560 {
561 if (!malloc_using_checking)
562 /* Work around a bug in glibc's malloc. MALLOC_CHECK_ must be
563 ignored if the heap to be restored was constructed without
564 malloc checking. Can't use unsetenv, since that calls malloc. */
565 {
566 char **p;
567
568 for (p = environ; *p; p++)
569 if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0)
570 {
571 do
572 *p = p[1];
573 while (*++p);
574 break;
575 }
576 }
577
578 malloc_set_state (malloc_state_ptr);
579 free (malloc_state_ptr);
580 }
581 else
582 malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
583 }
584
585 void (*__malloc_initialize_hook) () = malloc_initialize_hook;
586
587 #endif /* DOUG_LEA_MALLOC */
588
548 /* ARGSUSED */ 589 /* ARGSUSED */
549 int 590 int
550 main (argc, argv, envp) 591 main (argc, argv, envp)
551 int argc; 592 int argc;
552 char **argv; 593 char **argv;
561 #endif 602 #endif
562 int no_loadup = 0; 603 int no_loadup = 0;
563 604
564 #ifdef LINUX_SBRK_BUG 605 #ifdef LINUX_SBRK_BUG
565 __sbrk (1); 606 __sbrk (1);
566 #endif
567
568 #ifdef DOUG_LEA_MALLOC
569 if (initialized)
570 {
571 if (!malloc_using_checking)
572 /* Work around a bug in glibc's malloc. MALLOC_CHECK_ must be
573 ignored if the heap to be restored was constructed without
574 malloc checking. Can't use unsetenv, since that calls malloc. */
575 {
576 char **p;
577
578 for (p = envp; *p; p++)
579 if (strncmp (*p, "MALLOC_CHECK_=", 14) == 0)
580 {
581 do
582 *p = p[1];
583 while (*++p);
584 break;
585 }
586 }
587 malloc_set_state (malloc_state_ptr);
588 free (malloc_state_ptr);
589 }
590 else
591 malloc_using_checking = getenv ("MALLOC_CHECK_") != NULL;
592 #endif 607 #endif
593 608
594 #ifdef RUN_TIME_REMAP 609 #ifdef RUN_TIME_REMAP
595 if (initialized) 610 if (initialized)
596 run_time_remap (argv[0]); 611 run_time_remap (argv[0]);