From: Antony Dovgal Date: Thu, 12 May 2005 16:26:26 +0000 (+0000) Subject: fix #33019 (socket errors cause memory leaks in php_strerror()) X-Git-Tag: php-5.0.1b1~250 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cee979d5a9a594c8f1fee5e386bb73298ed30965;p=php fix #33019 (socket errors cause memory leaks in php_strerror()) patch by jwozniak23 at poczta dot onet dot pl --- diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 8c2486e6ea..b45da19b8a 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -321,6 +321,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); } @@ -335,6 +339,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);