]> granicus.if.org Git - php/commitdiff
Fix a memleak: A second call to *nix version of dlerror() frees the error
authorMarcus Boerger <helly@php.net>
Wed, 17 Dec 2003 11:20:35 +0000 (11:20 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 17 Dec 2003 11:20:35 +0000 (11:20 +0000)
string. This behavior is also adapted to the win build so that the buffer
returned by FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER) can be freed too.

ext/standard/dl.c
win32/winutil.c

index 4d25471192b5587316c406036cfffa80cc5a4a9a..1b8164e415cae26cc31a6701bf24c49bf19e6b36 100644 (file)
@@ -141,6 +141,7 @@ void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
        handle = DL_LOAD(libpath);
        if (!handle) {
                php_error_docref(NULL TSRMLS_CC, error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
+               GET_DL_ERROR(); /* free the buffer storing the error */
                efree(libpath);
                RETURN_FALSE;
        }
index 2c3797d1687f50ef83a570349f0b98e168d39c31..220fea294ccb5d49d8b799f8820257ad7998a897 100644 (file)
 
 PHPAPI char *php_win_err(int error)
 {
-       char *buf;
+       static char *buf = NULL;
 
+       if (buf) {
+               free(buf);
+               buf = NULL;
+       }
        FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |   FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL