Mem leak in virtual_realpath() in tsrm_virtual_cwd.c

php.internals

Pete Dishman

23 years ago
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

Ilia A.

23 years ago
On July 28, 2003 10:48 am, Pete Dishman wrote:
> 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().
You are quite correct, virtual_realpath does indeed appear to leak. I will test the patch you've suggested further and if it does not prove to have any side effects commit it. Ilia

Pete Dishman

23 years ago
Excellent, If this does get committed, will it make it in to 4.3.3 ? Thanks, Pete Dishman "Ilia Alshanetsky" <ilia@prohost.org> wrote in message news:200307281357.03571.ilia@prohost.org...
> On July 28, 2003 10:48 am, Pete Dishman wrote: > > 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(). > > You are quite correct, virtual_realpath does indeed appear to leak. I will > test the patch you've suggested further and if it does not prove to have
any

Jani Taskinen

23 years ago
It's already committed and will be in 4.3.3. --Jani On Tue, 29 Jul 2003, Pete Dishman wrote: