[gnu.emacs.bug] realloc bug in Emacs 18.53

pereira@AI.SRI.COM (Fernando Pereira) (02/25/89)

Changes to malloc.c in version 18.53 broke realloc. This causes
problems for the Sun support code because SunView functions call
realloc. In particular, Emacs fails an integrity check in free and
dumps core when menu_destroy (a SunView function) tries to free a
malloc block whose header has been corrupted by realloc. The changes
below solve the problem

*** malloc.c-18.53	Fri Feb 24 17:55:48 1989
--- malloc.c	Fri Feb 24 18:07:08 1989
***************
*** 578,584 ****
    register int nunits;
  
!   if ((p = (struct mhead *) mem) == 0)
      return malloc (n);
!   p -= (8 / sizeof (struct mhead));
    nunits = p -> mh_index;
    ASSERT (p -> mh_alloc == ISALLOC);
--- 578,584 ----
    register int nunits;
  
!   if (mem == 0)
      return malloc (n);
!   p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7));
    nunits = p -> mh_index;
    ASSERT (p -> mh_alloc == ISALLOC);
***************
*** 598,602 ****
  
    /* See if desired size rounds to same power of 2 as actual size. */
!   nbytes = (n + sizeof *p + EXTRA + 7) & ~7;
  
    /* If ok, use the same block, just marking its size as changed.  */
--- 598,602 ----
  
    /* See if desired size rounds to same power of 2 as actual size. */
!   nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
  
    /* If ok, use the same block, just marking its size as changed.  */


Fernando Pereira
Artificial Intelligence Center
SRI International

pereira@ai.sri.com

jr@bbn.com (John Robinson) (02/28/89)

In article <8902250646.AA00675@drakes.ai.sri.com>, pereira@AI (Fernando Pereira) writes:
>
>Changes to malloc.c in version 18.53 broke realloc. This causes
>problems for the Sun support code ...

and in a lot of other places as well.  I had trouble over a vanilla
terminal-telnet conection.  Your patch fixed it, however.  Thanks.
--
/jr
jr@bbn.com or bbn!jr

weltyc@cs.rpi.edu (Christopher A. Welty) (03/24/89)

In article <8902250646.AA00675@drakes.ai.sri.com> pereira@AI.SRI.COM (Fernando Pereira) writes:
>
>Changes to malloc.c in version 18.53 broke realloc. This causes
>problems for the Sun support code because SunView functions call
>realloc. In particular, Emacs fails an integrity check in free and
>dumps core when menu_destroy (a SunView function) tries to free a
>malloc block whose header has been corrupted by realloc. The changes
>below solve the problem

Before I make these changes myself I'm wondering if anyone else has
had trouble with it, they seem pretty harmless, but I'm always wary of
mucking with the emacs memory management stuff...I haven't seen any
other comments on this bug in this group.


Christopher Welty  ---  Asst. Director, RPI CS Labs | "Porsche:  Fahren in
weltyc@cs.rpi.edu             ...!njin!nyser!weltyc |  seiner schoensten Form"