Skip to content

Commit 71dc7bb

Browse files
committed
unify and fix VirtualAlloc(fixed_addr) error logging
1 parent 96963bf commit 71dc7bb

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

Zend/zend_alloc.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,15 @@ static void zend_mm_munmap(void *addr, size_t size)
436436
static void *zend_mm_mmap_fixed(void *addr, size_t size)
437437
{
438438
#ifdef _WIN32
439-
return VirtualAlloc(addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
439+
void *ptr = VirtualAlloc(addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
440+
if (ptr == NULL) {
441+
#if ZEND_MM_ERROR
442+
stderr_last_error("VirtualAlloc() failed");
443+
#endif
444+
return NULL;
445+
}
446+
ZEND_ASSERT(ptr == addr);
447+
return ptr;
440448
#else
441449
int flags = MAP_PRIVATE | MAP_ANON;
442450
#if defined(MAP_EXCL)
@@ -451,11 +459,7 @@ static void *zend_mm_mmap_fixed(void *addr, size_t size)
451459
#endif
452460
return NULL;
453461
} else if (ptr != addr) {
454-
if (munmap(ptr, size) != 0) {
455-
#if ZEND_MM_ERROR
456-
fprintf(stderr, "\nmunmap() failed: [%d] %s\n", errno, strerror(errno));
457-
#endif
458-
}
462+
zend_mm_munmap(ptr, size);
459463
return NULL;
460464
}
461465
return ptr;
@@ -1846,11 +1850,7 @@ static zend_mm_heap *zend_mm_init(void)
18461850

18471851
if (UNEXPECTED(chunk == NULL)) {
18481852
#if ZEND_MM_ERROR
1849-
#ifdef _WIN32
1850-
stderr_last_error("Can't initialize heap");
1851-
#else
1852-
fprintf(stderr, "\nCan't initialize heap: [%d] %s\n", errno, strerror(errno));
1853-
#endif
1853+
fprintf(stderr, "Can't initialize heap\n");
18541854
#endif
18551855
return NULL;
18561856
}
@@ -2978,11 +2978,7 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void
29782978
chunk = (zend_mm_chunk*)handlers->chunk_alloc(&tmp_storage, ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE);
29792979
if (UNEXPECTED(chunk == NULL)) {
29802980
#if ZEND_MM_ERROR
2981-
#ifdef _WIN32
2982-
stderr_last_error("Can't initialize heap");
2983-
#else
2984-
fprintf(stderr, "\nCan't initialize heap: [%d] %s\n", errno, strerror(errno));
2985-
#endif
2981+
fprintf(stderr, "Can't initialize heap\n");
29862982
#endif
29872983
return NULL;
29882984
}
@@ -3025,11 +3021,7 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void
30253021
if (!storage) {
30263022
handlers->chunk_free(&tmp_storage, chunk, ZEND_MM_CHUNK_SIZE);
30273023
#if ZEND_MM_ERROR
3028-
#ifdef _WIN32
3029-
stderr_last_error("Can't initialize heap");
3030-
#else
3031-
fprintf(stderr, "\nCan't initialize heap: [%d] %s\n", errno, strerror(errno));
3032-
#endif
3024+
fprintf(stderr, "Can't initialize heap\n");
30333025
#endif
30343026
return NULL;
30353027
}

0 commit comments

Comments
 (0)