diff options
author | Anatol Belski <ab@php.net> | 2018-09-17 09:48:33 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2018-09-17 10:56:50 +0200 |
commit | 321c0cc3493998f731f0666127c093eff4e119eb (patch) | |
tree | 166b14619222863274ad150ec81b31d548fcc3c1 /ext/opcache/shared_alloc_win32.c | |
parent | 3b475910d69a5bcddaf0b78aa29fdea2e0057d31 (diff) | |
download | php-git-321c0cc3493998f731f0666127c093eff4e119eb.tar.gz |
Fix localized error messages and memory leaks
The FormatMessage API needs to LocalFree the delivered error messages.
In cases where messages are delivered in non ASCII compatible encoding,
the messages might be unreadable. This aligns the error message encoding
with the encoding settings in PHP, the focus is UTF-8 as default.
Initialize error buffer
Avoid code duplication
Diffstat (limited to 'ext/opcache/shared_alloc_win32.c')
-rw-r--r-- | ext/opcache/shared_alloc_win32.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/ext/opcache/shared_alloc_win32.c b/ext/opcache/shared_alloc_win32.c index 5207a59812..9179755849 100644 --- a/ext/opcache/shared_alloc_win32.c +++ b/ext/opcache/shared_alloc_win32.c @@ -23,6 +23,7 @@ #include "zend_shared_alloc.h" #include "zend_accelerator_util_funcs.h" #include "tsrm_win32.h" +#include "win32/winutil.h" #include <winbase.h> #include <process.h> #include <LMCONS.H> @@ -40,25 +41,13 @@ static void *mapping_base; static void zend_win_error_message(int type, char *msg, int err) { - LPVOID lpMsgBuf; HANDLE h; char *ev_msgs[2]; - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); + char *buf = php_win32_error_to_msg(err); h = RegisterEventSource(NULL, TEXT(ACCEL_EVENT_SOURCE)); ev_msgs[0] = msg; - ev_msgs[1] = lpMsgBuf; + ev_msgs[1] = buf; ReportEvent(h, // event log handle EVENTLOG_ERROR_TYPE, // event type 0, // category zero @@ -70,9 +59,9 @@ static void zend_win_error_message(int type, char *msg, int err) NULL); // pointer to data DeregisterEventSource(h); - LocalFree( lpMsgBuf ); - zend_accel_error(type, "%s", msg); + + php_win32_error_msg_free(buf); } static char *create_name_with_username(char *name) |