Do not allocate error buffer at the start of every request.

This commit is contained in:
Ilia Alshanetsky 2004-05-16 15:34:53 +00:00
parent ed5ce047db
commit bb88a86240

View File

@ -322,7 +322,7 @@ static char *php_strerror(int error TSRMLS_DC)
buf = hstrerror(error);
#else
{
sprintf(SOCKETS_G(strerror_buf), "Host lookup error %d", error);
spprintf(&(SOCKETS_G(strerror_buf), "Host lookup error %d", error);
buf = SOCKETS_G(strerror_buf);
}
#endif
@ -336,7 +336,7 @@ static char *php_strerror(int error TSRMLS_DC)
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &tmp, 0, NULL)) {
strlcpy(SOCKETS_G(strerror_buf), (char *) tmp, 10000);
SOCKETS_G(strerror_buf) = estrndup(tmp);
LocalFree(tmp);
buf = SOCKETS_G(strerror_buf);
@ -503,8 +503,6 @@ PHP_MINFO_FUNCTION(sockets)
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(sockets)
{
SOCKETS_G(strerror_buf) = emalloc(16384);
return SUCCESS;
}
/* }}} */
@ -512,8 +510,11 @@ PHP_RINIT_FUNCTION(sockets)
/* {{{ PHP_RSHUTDOWN_FUNCTION */
PHP_RSHUTDOWN_FUNCTION(sockets)
{
efree(SOCKETS_G(strerror_buf));
if (SOCKETS_G(strerror_buf)) {
efree(SOCKETS_G(strerror_buf));
SOCKETS_G(strerror_buf) = NULL;
}
return SUCCESS;
}
/* }}} */