From db4444f0cebf4e63e666a7d6d18141c127535efd Mon Sep 17 00:00:00 2001 From: Chris Elliott Date: Fri, 21 Mar 2003 10:10:16 +0000 Subject: [PATCH] fix memory leak as Dimitri suggested git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19658 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/filefn.cpp | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index cb7d82c331..5543a2e3ec 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -214,34 +214,43 @@ void wxPathList::Add (const wxString& path) // Add paths e.g. from the PATH environment variable void wxPathList::AddEnvList (const wxString& envVariable) { - static const wxChar PATH_TOKS[] = + static const wxChar PATH_TOKS[] = #ifdef __WINDOWS__ - wxT(" ;"); // Don't seperate with colon in DOS (used for drive) + /* + The space has been removed from the tokenizers, otherwise a + path such as "C:\Program Files" would be split into 2 paths: + "C:\Program" and "Files" + */ +// wxT(" ;"); // Don't seperate with colon in DOS (used for drive) + wxT(";"); // Don't seperate with colon in DOS (used for drive) #else wxT(" :;"); #endif - wxChar *val = wxGetenv (WXSTRINGCAST envVariable); - if (val && *val) + wxChar *val = wxGetenv (WXSTRINGCAST envVariable); + if (val && *val) { - wxChar *s = copystring (val); - wxChar *save_ptr, *token = wxStrtok (s, PATH_TOKS, &save_ptr); + wxChar *s = copystring (val); + wxChar *save_ptr, *token = wxStrtok (s, PATH_TOKS, &save_ptr); - if (token) - { - Add (copystring (token)); - while (token) - { - if ((token = wxStrtok ((wxChar *) NULL, PATH_TOKS, &save_ptr)) != NULL) - Add (wxString(token)); - } - } + if (token) + { + Add(token); + while (token) + { + if ( (token = wxStrtok ((wxChar *) NULL, PATH_TOKS, &save_ptr)) + != NULL ) + { + Add(token); + } + } + } - // suppress warning about unused variable save_ptr when wxStrtok() is a - // macro which throws away its third argument - save_ptr = token; + // suppress warning about unused variable save_ptr when wxStrtok() is a + // macro which throws away its third argument + save_ptr = token; - delete [] s; + delete [] s; } }