string. This behavior is also adapted to the win build so that the buffer
returned by FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER) can be freed too.
handle = DL_LOAD(libpath);
if (!handle) {
php_error_docref(NULL TSRMLS_CC, error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
+ GET_DL_ERROR(); /* free the buffer storing the error */
efree(libpath);
RETURN_FALSE;
}
PHPAPI char *php_win_err(int error)
{
- char *buf;
+ static char *buf = NULL;
+ if (buf) {
+ free(buf);
+ buf = NULL;
+ }
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL