[ros-diffs] [weiden] 28073: Fix a memory leak in the dir command

weiden at svn.reactos.org weiden at svn.reactos.org
Wed Aug 1 16:32:57 CEST 2007


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=28073&r1=28072&r2=28073&view=diff
==============================================================================
--- 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, &params, &entries, &stFlags))
 		{
 			nErrorLevel = 1;
-			return 1;
+			goto cleanup;
 		}
 
 	/* read the parameters */
 	if (!DirReadParam(rest, &params, &entries, &stFlags) || CheckCtrlBreak(BREAK_INPUT))
 	{
 		nErrorLevel = 1;
-		return 1;
+		goto cleanup;
 	}
 
 	/* default to current directory */
 	if(entries == 0) {
 		if(!add_entry(&entries, &params, _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




More information about the Ros-diffs mailing list