From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27738 invoked from network); 3 Sep 1997 18:26:24 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 3 Sep 1997 18:26:24 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id OAA14942; Wed, 3 Sep 1997 14:18:13 -0400 (EDT) Resent-Date: Wed, 3 Sep 1997 14:18:13 -0400 (EDT) Date: Wed, 3 Sep 1997 11:17:28 -0700 Message-Id: <199709031817.LAA11561@xemacs.eng.sun.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Martin Buchholz To: Zsh Workers Subject: PATCH: Src/mem.c X-Mailer: VM 6.33 under 20.3 "Vienna" XEmacs Lucid (beta14) Reply-To: Martin Buchholz Resent-Message-ID: <"Fg6Ve2.0.Mf3.bdQ3q"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3478 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu I am not on this mailing list (I am busy enough hacking XEmacs). I was reading mem.c as an educational experience, and found the following small bugs: For some reason, zrealloc does not check for memory errors. Whatever it does, it should perform the same checks as zalloc. BTW, I am a satisfied user of zsh. The only thing on my wish list is the ability to modify the command line using a user-specified function before trying to resolve it as a command. Martin $ gnudiff -U3 mem.c.orig mem.c --- mem.c.orig Wed Sep 3 10:52:08 1997 +++ mem.c Wed Sep 3 10:59:17 1997 @@ -46,7 +46,7 @@ pushheap() saves the states of all currently allocated heaps and popheap() resets them to the last state saved and destroys the information about that state. If you called pushheap() and - allocated some meory on the heaps and then come to a place where + allocated some memory on the heaps and then come to a place where you don't need the allocated memory anymore but you still want to allocate memory on the heap, you should call freeheap(). This works like popheap(), only that it doesn't free the information @@ -69,10 +69,10 @@ If we use zsh's own allocator we use a simple trick to avoid that the (*real*) heap fills up with empty zsh-heaps: we allocate a large block of memory before allocating a heap pool, this memory - is freed again immediatly after the pool is allocated. If there - are only small blocks on the free list this guarentees that the + is freed again immediately after the pool is allocated. If there + are only small blocks on the free list this guarantees that the memory for the pool is at the end of the memory which means that - we can give it back to the systems when the pool is freed. + we can give it back to the system when the pool is freed. */ #ifdef ZSH_MEM_WARNING @@ -411,9 +411,14 @@ zrealloc(void *ptr, size_t size) { if (ptr) { - if (size) + if (size) { /* Do normal realloc */ - return realloc(ptr, size); + if (!(ptr = (void *) realloc(ptr, size))) { + zerr("fatal error: out of memory", NULL, 0); + exit(1); + } + return ptr; + } else /* If ptr is not NULL, but size is zero, * * then object pointed to is freed. */