Skip to content

Commit 817fd19

Browse files
committed
call VirtualQuery only if VirtualFree failed first
1 parent e6ea363 commit 817fd19

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Zend/zend_alloc.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,30 @@ stderr_last_error(char *msg)
419419
static void zend_mm_munmap(void *addr, size_t size)
420420
{
421421
#ifdef _WIN32
422-
MEMORY_BASIC_INFORMATION mbi;
423-
if (VirtualQuery(addr, &mbi, sizeof(mbi)) == 0) {
422+
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
423+
/** ERROR_INVALID_ADDRESS is expected when addr is not range start address */
424+
if (GetLastError() != ERROR_INVALID_ADDRESS) {
424425
#if ZEND_MM_ERROR
425-
stderr_last_error("VirtualQuery() failed");
426+
stderr_last_error("VirtualFree() failed");
426427
#endif
427-
}
428-
addr = mbi.AllocationBase;
429-
430-
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
428+
return;
429+
}
430+
SetLastError(0);
431+
432+
MEMORY_BASIC_INFORMATION mbi;
433+
if (VirtualQuery(addr, &mbi, sizeof(mbi)) == 0) {
434+
#if ZEND_MM_ERROR
435+
stderr_last_error("VirtualQuery() failed");
436+
#endif
437+
return;
438+
}
439+
addr = mbi.AllocationBase;
440+
441+
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
431442
#if ZEND_MM_ERROR
432-
stderr_last_error("VirtualFree() failed");
443+
stderr_last_error("VirtualFree() failed");
433444
#endif
445+
}
434446
}
435447
#else
436448
if (munmap(addr, size) != 0) {

0 commit comments

Comments
 (0)