Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix a memleak: A second call to *nix version of dlerror() frees the e…
…rror

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.
  • Loading branch information
helly25 committed Dec 17, 2003
1 parent 094861d commit 490fd0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions ext/standard/dl.c
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion win32/winutil.c
Expand Up @@ -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
Expand Down

0 comments on commit 490fd0e

Please sign in to comment.