Author: weiden
Date: Wed Aug 1 18:32:57 2007
New Revision: 28073
URL:
http://svn.reactos.org/svn/reactos?rev=28073&view=rev
Log:
Fix a memory leak in the dir command
Modified:
trunk/reactos/base/shell/cmd/dir.c
Modified: trunk/reactos/base/shell/cmd/dir.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=2…
==============================================================================
--- trunk/reactos/base/shell/cmd/dir.c (original)
+++ trunk/reactos/base/shell/cmd/dir.c Wed Aug 1 18:32:57 2007
@@ -1954,10 +1954,11 @@
TCHAR cDrive;
TCHAR szPath[MAX_PATH];
TCHAR szFilespec[MAX_PATH];
- LPTSTR* params;
+ LPTSTR* params = NULL;
INT entries = 0;
UINT loop = 0;
DIRSWITCHFLAGS stFlags;
+ INT ret = 1;
/* Initialize variables */
cDrive = 0;
@@ -1992,21 +1993,21 @@
if (!DirReadParam(dircmd, ¶ms, &entries, &stFlags))
{
nErrorLevel = 1;
- return 1;
+ goto cleanup;
}
/* read the parameters */
if (!DirReadParam(rest, ¶ms, &entries, &stFlags) ||
CheckCtrlBreak(BREAK_INPUT))
{
nErrorLevel = 1;
- return 1;
+ goto cleanup;
}
/* default to current directory */
if(entries == 0) {
if(!add_entry(&entries, ¶ms, _T("."))) {
nErrorLevel = 1;
- return 1;
+ goto cleanup;
}
}
@@ -2016,7 +2017,7 @@
if (DirParsePathspec (params[loop], szPath, szFilespec) ||
CheckCtrlBreak(BREAK_INPUT))
{
nErrorLevel = 1;
- return 1;
+ goto cleanup;
}
/* <Debug :>
@@ -2047,7 +2048,7 @@
if(cDrive != szPath[0] && !stFlags.bBareFormat) {
if (!PrintDirectoryHeader (szPath, &stFlags)) {
nErrorLevel = 1;
- return 1;
+ goto cleanup;
}
cDrive = szPath[0];
@@ -2058,7 +2059,7 @@
if (DirList (szPath, szFilespec, &stFlags))
{
nErrorLevel = 1;
- return 1;
+ goto cleanup;
}
}
@@ -2068,8 +2069,13 @@
recurse_dir_cnt,
recurse_bytes,
&stFlags);
-
- return 0;
+
+ ret = 0;
+
+cleanup:
+ freep(params);
+
+ return ret;
}
#endif