From f4446bbf6f488f4ca028a513e37e95cbc79c91c4 Mon Sep 17 00:00:00 2001 From: Gerd Moellmann Date: Tue, 19 Aug 2003 12:58:35 +0000 Subject: [PATCH] (lisp_align_malloc): Check for memory full when allocating ablocks, which also avoids freeing a pointer into an ablocks structure. --- src/ChangeLog | 6 ++++++ src/alloc.c | 32 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9ac972507e2..73e8de3aa71 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2003-08-19 Gerd Moellmann + * alloc.c (lisp_align_malloc): Check for memory full when + allocating ablocks, which also avoids freeing a pointer into an + ablocks structure. + + * puresize.h (BASE_PURESIZE): Increase to 1100000. + * buffer.c (Fmove_overlay): Set overlay's next pointer unconditionally. diff --git a/src/alloc.c b/src/alloc.c index 7f05cf77937..c4496b6ff7b 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -766,6 +766,23 @@ lisp_align_malloc (nbytes, type) mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); #endif + /* If the memory just allocated cannot be addressed thru a Lisp + object's pointer, and it needs to be, that's equivalent to + running out of memory. */ + if (type != MEM_TYPE_NON_LISP) + { + Lisp_Object tem; + char *end = (char *) base + ABLOCKS_BYTES - 1; + XSETCONS (tem, end); + if ((char *) XCONS (tem) != end) + { + lisp_malloc_loser = base; + free (base); + UNBLOCK_INPUT; + memory_full (); + } + } + /* Initialize the blocks and put them on the free list. Is `base' was not properly aligned, we can't use the last block. */ for (i = 0; i < (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1); i++) @@ -788,21 +805,6 @@ lisp_align_malloc (nbytes, type) val = free_ablock; free_ablock = free_ablock->x.next_free; - /* If the memory just allocated cannot be addressed thru a Lisp - object's pointer, and it needs to be, - that's equivalent to running out of memory. */ - if (val && type != MEM_TYPE_NON_LISP) - { - Lisp_Object tem; - XSETCONS (tem, (char *) val + nbytes - 1); - if ((char *) XCONS (tem) != (char *) val + nbytes - 1) - { - lisp_malloc_loser = val; - free (val); - val = 0; - } - } - #if GC_MARK_STACK && !defined GC_MALLOC_CHECK if (val && type != MEM_TYPE_NON_LISP) mem_insert (val, (char *) val + nbytes, type); -- 2.39.2