Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: pws-21: Re: BUG: 3.1.5-pws-21: lfs



Geoff Wing wrote:
> Peter Stephenson <pws@xxxxxxxxxxxxxxxxx> typed:
> :Geoff Wing wrote:
> :> :I get a near continuous spew out of:
> :> :	BUG: attempt to free storage at invalid address
> 
> First time through malloc():
>  (m = sbrk(4096)) @ mem.c:760  gives   m = 0x53b24

Ahaahaaha.  See if this works.  It's probably got too many casts 'n' stuff
but I wanted it to be not too unsafe.  There are a few assumptions anyway,
but this time it looks like we're stuck with turning a pointer into an
integer.

--- Src/mem.c.sbrk	Wed Jun  9 16:18:04 1999
+++ Src/mem.c	Mon Jun 14 18:30:34 1999
@@ -777,6 +777,7 @@
 	for (mp = NULL, m = m_free; m && m->len < size; mp = m, m = m->next);
     }
     if (!m) {
+	long nal;
 	/* no matching free block was found, we have to request new
 	   memory from the system */
 	n = (size + M_HSIZE + M_ALLOC + m_pgsz - 1) & ~(m_pgsz - 1);
@@ -785,6 +786,14 @@
 	    DPUTS(1, "MEM: allocation error at sbrk.");
 	    unqueue_signals();
 	    return NULL;
+	}
+	if ((nal = ((long)(char *)m) & (M_ALIGN-1))) {
+	    if ((char *)sbrk(M_ALIGN - nal) == (char *)-1) {
+		DPUTS(1, "MEM: allocation error at sbrk.");
+		unqueue_signals();
+		return NULL;
+	    }
+	    m = (struct m_hdr *) ((char *)m + (M_ALIGN - nal));
 	}
 	/* set m_low, for the check in free() */
 	if (!m_low)

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author