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

ext/sockets/sockets.c

index 8c2486e6ea1cc4c047e11b68305044d4b231a0ae..b45da19b8a420cc25ba42a434a861e48576a09d7 100644 (file)
@@ -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);