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

PATCH: Src/mem.c



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



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