Hi,
I'm currently developing an extension and believe I've found a memory leak
in virtual_realpath(). My extension is calling this function via the macro
VCWD_REALPATH().
It seems this function allocates memory with CWD_STATE_COPY() but then never
frees it. This also seems to be the case in virtual_filepath_ex(), which is
the function below.
I've been testing with PHP v4.1.1 but I've checked 4.3.2 and the function
still has the same problem.
virtual_realpath is currently defined as:
CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC)
{
cwd_state new_state;
int retval;
CWD_STATE_COPY(&new_state, &CWDG(cwd));
retval = virtual_file_ex(&new_state, path, NULL);
if (!retval) {
int len =
new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
memcpy(real_path, new_state.cwd, len);
real_path[len] = '\0';
return real_path;
}
return NULL;
}
Changing this to include calls to CWD_STATE_FREE(&new_state) before both
returns seems to be the correct thing to do and resolves my memory leak.
Most of the other functions in this file use CWD_STATE_COPY along with
CWD_STATE_FREE, is it just an oversight that these two functions
(virtual_realpath and virtual_filepath_ex) don't or is there something more
complex going on?
I wasn't sure whether to submit this as a bug report or just to send a note
here, sorry if I picked the wrong one. Also I'm working on windows and
don't currently have CVS access or the ability to produce diff's if this is
a definite bug.
Thanks in advance,
Pete Dishman
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php