Skip to content

Commit 0736b8a

Browse files
committed
dedup munmap call /w error handling
1 parent a2dcb03 commit 0736b8a

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

Zend/zend_alloc.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,23 @@ stderr_last_error(char *msg)
416416
/* OS Allocation */
417417
/*****************/
418418

419+
static void zend_mm_munmap(void *addr, size_t size)
420+
{
421+
#ifdef _WIN32
422+
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
423+
#if ZEND_MM_ERROR
424+
stderr_last_error("VirtualFree() failed");
425+
#endif
426+
}
427+
#else
428+
if (munmap(addr, size) != 0) {
429+
#if ZEND_MM_ERROR
430+
fprintf(stderr, "\nmunmap() failed: [%d] %s\n", errno, strerror(errno));
431+
#endif
432+
}
433+
#endif
434+
}
435+
419436
#ifndef HAVE_MREMAP
420437
static void *zend_mm_mmap_fixed(void *addr, size_t size)
421438
{
@@ -435,11 +452,7 @@ static void *zend_mm_mmap_fixed(void *addr, size_t size)
435452
#endif
436453
return NULL;
437454
} else if (ptr != addr) {
438-
if (munmap(ptr, size) != 0) {
439-
#if ZEND_MM_ERROR
440-
fprintf(stderr, "\nmunmap() failed: [%d] %s\n", errno, strerror(errno));
441-
#endif
442-
}
455+
zend_mm_munmap(ptr, size);
443456
return NULL;
444457
}
445458
return ptr;
@@ -483,23 +496,6 @@ static void *zend_mm_mmap(size_t size)
483496
#endif
484497
}
485498

486-
static void zend_mm_munmap(void *addr, size_t size)
487-
{
488-
#ifdef _WIN32
489-
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
490-
#if ZEND_MM_ERROR
491-
stderr_last_error("VirtualFree() failed");
492-
#endif
493-
}
494-
#else
495-
if (munmap(addr, size) != 0) {
496-
#if ZEND_MM_ERROR
497-
fprintf(stderr, "\nmunmap() failed: [%d] %s\n", errno, strerror(errno));
498-
#endif
499-
}
500-
#endif
501-
}
502-
503499
/***********/
504500
/* Bitmask */
505501
/***********/

0 commit comments

Comments
 (0)