diff options
| author | Eli Zaretskii | 2015-07-27 21:16:46 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2015-07-27 21:16:46 +0300 |
| commit | 094d5e9ef0fac319816c00cc52e0a0f2ef41be37 (patch) | |
| tree | 792914d8eccfdd757bb0ce9fccce4cc0c0ac34b6 | |
| parent | 3266513eb7b7972cc63884338f821ca774a06cfa (diff) | |
| download | emacs-094d5e9ef0fac319816c00cc52e0a0f2ef41be37.tar.gz emacs-094d5e9ef0fac319816c00cc52e0a0f2ef41be37.zip | |
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.
| -rw-r--r-- | src/w32heap.c | 18 |
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 | ||
| 312 | void * | 313 | void * |
| 313 | malloc_after_dump (size_t size) | 314 | malloc_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) | |||
| 473 | void | 474 | void |
| 474 | free_before_dump (void *ptr) | 475 | free_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) |