From: Antony Dovgal Date: Thu, 12 May 2005 16:27:22 +0000 (+0000) Subject: MFH: fix #33019 (socket errors cause memory leaks in php_strerror()) X-Git-Tag: php-4.4.0RC1~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5706984256009ea4e0d3319979468822f8459bb;p=php MFH: fix #33019 (socket errors cause memory leaks in php_strerror()) patch by jwozniak23 at poczta dot onet dot pl --- diff --git a/NEWS b/NEWS index 267bcb9afd..507663e227 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,8 @@ PHP 4 NEWS them sort based on the current locale. (Derick) - Changed sha1_file() and md5_file() functions to use streams instead of low level IO. (Uwe) +- Fixed bug #33019 (socket errors cause memory leaks in php_strerror()). + (jwozniak23 at poczta dot onet dot pl, Tony). - Fixed bug #32974 (pcntl calls malloc() from a signal handler). (Wez) - Fixed bug #32936 (http redirects URLs are not checked for control chars). (Ilia) - Fixed bug #32932 (Oracle LDAP: ldap_get_entries invalid pointer). (Jani) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 220126313d..2a390acaad 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -354,6 +354,10 @@ static char *php_strerror(int error TSRMLS_DC) buf = hstrerror(error); #else { + if (SOCKETS_G(strerror_buf)) { + efree(SOCKETS_G(strerror_buf)); + } + spprintf(&(SOCKETS_G(strerror_buf)), 0, "Host lookup error %d", error); buf = SOCKETS_G(strerror_buf); } @@ -368,6 +372,11 @@ 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)) { + + if (SOCKETS_G(strerror_buf)) { + efree(SOCKETS_G(strerror_buf)); + } + SOCKETS_G(strerror_buf) = estrdup(tmp); LocalFree(tmp);