aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/w32heap.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/w32heap.c b/src/w32heap.c
index ec5b04119bf..60afd1d3174 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -305,9 +305,10 @@ init_heap (void)
305#undef free 305#undef free
306 306
307/* FREEABLE_P checks if the block can be safely freed. */ 307/* FREEABLE_P checks if the block can be safely freed. */
308#define FREEABLE_P(addr) \ 308#define FREEABLE_P(addr) \
309 ((unsigned char *)(addr) < dumped_data \ 309 ((unsigned char *)(addr) > 0 \
310 || (unsigned char *)(addr) >= dumped_data + DUMPED_HEAP_SIZE) 310 && ((unsigned char *)(addr) < dumped_data \
311 || (unsigned char *)(addr) >= dumped_data + DUMPED_HEAP_SIZE))
311 312
312void * 313void *
313malloc_after_dump (size_t size) 314malloc_after_dump (size_t size)
@@ -407,10 +408,10 @@ realloc_after_dump (void *ptr, size_t size)
407 /* If the block lies in the dumped data, do not free it. Only 408 /* If the block lies in the dumped data, do not free it. Only
408 allocate a new one. */ 409 allocate a new one. */
409 p = HeapAlloc (heap, 0, size); 410 p = HeapAlloc (heap, 0, size);
410 if (p) 411 if (!p)
411 CopyMemory (p, ptr, size);
412 else
413 errno = ENOMEM; 412 errno = ENOMEM;
413 else if (ptr)
414 CopyMemory (p, ptr, size);
414 } 415 }
415 /* After dump, keep track of the "brk value" for sbrk(0). */ 416 /* After dump, keep track of the "brk value" for sbrk(0). */
416 if (p) 417 if (p)
@@ -449,7 +450,7 @@ realloc_before_dump (void *ptr, size_t size)
449 of failing the call as below. But this doesn't seem to be 450 of failing the call as below. But this doesn't seem to be
450 worth the added complexity, as loadup allocates only a very 451 worth the added complexity, as loadup allocates only a very
451 small number of large blocks, and never reallocates them. */ 452 small number of large blocks, and never reallocates them. */
452 if (p) 453 if (p && ptr)
453 { 454 {
454 CopyMemory (p, ptr, size); 455 CopyMemory (p, ptr, size);
455 free_before_dump (ptr); 456 free_before_dump (ptr);
@@ -473,6 +474,9 @@ free_after_dump (void *ptr)
473void 474void
474free_before_dump (void *ptr) 475free_before_dump (void *ptr)
475{ 476{
477 if (!ptr)
478 return;
479
476 /* Before dumping. */ 480 /* Before dumping. */
477 if (dumped_data < (unsigned char *)ptr 481 if (dumped_data < (unsigned char *)ptr
478 && (unsigned char *)ptr < bc_limit) 482 && (unsigned char *)ptr < bc_limit)