emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 094d5e9: Handle NULL pointers in w32heap.c allocati


From: Eli Zaretskii
Subject: [Emacs-diffs] master 094d5e9: Handle NULL pointers in w32heap.c allocation routines
Date: Mon, 27 Jul 2015 18:18:02 +0000

branch: master
commit 094d5e9ef0fac319816c00cc52e0a0f2ef41be37
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Handle NULL pointers in w32heap.c allocation routines
    
    * src/w32heap.c (FREEABLE_P): Consider a NULL pointer "not
    freeable".
    (realloc_after_dump, realloc_before_dump, free_before_dump):
    Handle NULL pointers gracefully, as Emacs now seems to expect
    that.
---
 src/w32heap.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/w32heap.c b/src/w32heap.c
index ec5b041..60afd1d 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -305,9 +305,10 @@ init_heap (void)
 #undef free
 
 /* FREEABLE_P checks if the block can be safely freed.  */
-#define FREEABLE_P(addr)                                        \
-    ((unsigned char *)(addr) < dumped_data                      \
-     || (unsigned char *)(addr) >= dumped_data + DUMPED_HEAP_SIZE)
+#define FREEABLE_P(addr)                                               \
+    ((unsigned char *)(addr) > 0                                       \
+     && ((unsigned char *)(addr) < dumped_data                         \
+        || (unsigned char *)(addr) >= dumped_data + DUMPED_HEAP_SIZE))
 
 void *
 malloc_after_dump (size_t size)
@@ -407,10 +408,10 @@ realloc_after_dump (void *ptr, size_t size)
       /* If the block lies in the dumped data, do not free it.  Only
          allocate a new one.  */
       p = HeapAlloc (heap, 0, size);
-      if (p)
-       CopyMemory (p, ptr, size);
-      else
+      if (!p)
        errno = ENOMEM;
+      else if (ptr)
+       CopyMemory (p, ptr, size);
     }
   /* After dump, keep track of the "brk value" for sbrk(0).  */
   if (p)
@@ -449,7 +450,7 @@ realloc_before_dump (void *ptr, size_t size)
         of failing the call as below.  But this doesn't seem to be
         worth the added complexity, as loadup allocates only a very
         small number of large blocks, and never reallocates them.  */
-      if (p)
+      if (p && ptr)
        {
          CopyMemory (p, ptr, size);
          free_before_dump (ptr);
@@ -473,6 +474,9 @@ free_after_dump (void *ptr)
 void
 free_before_dump (void *ptr)
 {
+  if (!ptr)
+    return;
+
   /* Before dumping.  */
   if (dumped_data < (unsigned char *)ptr
       && (unsigned char *)ptr < bc_limit)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]