]> granicus.if.org Git - php/commitdiff
MFH: fix #33019 (socket errors cause memory leaks in php_strerror())
authorAntony Dovgal <tony2001@php.net>
Thu, 12 May 2005 16:27:22 +0000 (16:27 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 12 May 2005 16:27:22 +0000 (16:27 +0000)
patch by jwozniak23 at poczta dot onet dot pl

NEWS
ext/sockets/sockets.c

diff --git a/NEWS b/NEWS
index 267bcb9afd358f2b494c8f282ce432140ca4bb6b..507663e2274475847b7c5845e717eaf53be83246 100644 (file)
--- 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)
index 220126313d519e0b314367e4821ce4d0d164cd40..2a390acaadc50ff07b76f71235a09b8201872887 100644 (file)
@@ -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);