zsh-workers
 help / color / mirror / code / Atom feed
From: Martin Buchholz <mrb@Eng.Sun.COM>
To: Zsh Workers <zsh-workers@math.gatech.edu>
Subject: PATCH: Src/mem.c
Date: Wed, 3 Sep 1997 11:17:28 -0700	[thread overview]
Message-ID: <199709031817.LAA11561@xemacs.eng.sun.com> (raw)

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.      */


                 reply	other threads:[~1997-09-03 18:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199709031817.LAA11561@xemacs.eng.sun.com \
    --to=mrb@eng.sun.com \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).