From: Marcus Boerger Date: Wed, 17 Dec 2003 11:20:35 +0000 (+0000) Subject: Fix a memleak: A second call to *nix version of dlerror() frees the error X-Git-Tag: php-5.0.0b3RC1~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=490fd0eaf272a44cab1885496e94afdb52a8bf66;p=php Fix a memleak: A second call to *nix version of dlerror() frees the error 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. --- diff --git a/ext/standard/dl.c b/ext/standard/dl.c index 4d25471192..1b8164e415 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -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; } diff --git a/win32/winutil.c b/win32/winutil.c index 2c3797d168..220fea294c 100644 --- a/win32/winutil.c +++ b/win32/winutil.c @@ -20,8 +20,12 @@ 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