Skip to content

Commit 3145d6c

Browse files
committed
Report mem leaks to stderr if no Win debugger is present
Formerly, we sent output regarding memory leaks always to the debugger on Windows, but this appears to be not useful especially for the PHPTs, which usually are not run under a debugger, and so important info will not be available there.
1 parent 98b01a1 commit 3145d6c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

main/main.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,11 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void
16811681
snprintf(memory_leak_buf, 512, "Last leak repeated %lu time%s\n", leak_count, (leak_count>1?"s":""));
16821682
}
16831683
# if defined(PHP_WIN32)
1684-
OutputDebugString(memory_leak_buf);
1684+
if (IsDebuggerPresent()) {
1685+
OutputDebugString(memory_leak_buf);
1686+
} else {
1687+
fprintf(stderr, "%s", memory_leak_buf);
1688+
}
16851689
# else
16861690
fprintf(stderr, "%s", memory_leak_buf);
16871691
# endif
@@ -1695,7 +1699,11 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void
16951699

16961700
snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((uint32_t *) data));
16971701
# if defined(PHP_WIN32)
1698-
OutputDebugString(memory_leak_buf);
1702+
if (IsDebuggerPresent()) {
1703+
OutputDebugString(memory_leak_buf);
1704+
} else {
1705+
fprintf(stderr, "%s", memory_leak_buf);
1706+
}
16991707
# else
17001708
fprintf(stderr, "%s", memory_leak_buf);
17011709
# endif
@@ -1718,7 +1726,11 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void
17181726
snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null] Script: '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
17191727
}
17201728
# if defined(PHP_WIN32)
1721-
OutputDebugString(memory_leak_buf);
1729+
if (IsDebuggerPresent()) {
1730+
OutputDebugString(memory_leak_buf);
1731+
} else {
1732+
fprintf(stderr, "%s", memory_leak_buf);
1733+
}
17221734
# else
17231735
fprintf(stderr, "%s", memory_leak_buf);
17241736
# endif

0 commit comments

Comments
 (0)