]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: remove memory leak in file handle list
authorJaben Carsey <jaben.carsey@intel.com>
Thu, 9 Jan 2014 18:05:24 +0000 (18:05 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 9 Jan 2014 18:05:24 +0000 (18:05 +0000)
The shell was not freeing sufficient memory when freeing a list of files.  The structure contained a pointer which was being left behind.  I made a new function to replace the shared freeing function which frees the “Path” member of the SHELL_COMMAND_FILE_HANDLE structure.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15073 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c

index 935e8397fed3550655a1f54d3371a098fe0e6167..48be39f83242b07dd616fd602d72275c621b8df0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell internal functions for shell commands.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -100,6 +100,37 @@ ShellCommandLibConstructor (
   return (RETURN_SUCCESS);\r
 }\r
 \r
+/**\r
+  Frees list of file handles.\r
+\r
+  @param[in] List     The list to free.\r
+**/\r
+VOID\r
+EFIAPI\r
+FreeFileHandleList (\r
+  IN BUFFER_LIST *List\r
+  )\r
+{\r
+  BUFFER_LIST               *BufferListEntry;\r
+\r
+  if (List == NULL){\r
+    return;\r
+  }\r
+  //\r
+  // enumerate through the buffer list and free all memory\r
+  //\r
+  for ( BufferListEntry = ( BUFFER_LIST *)GetFirstNode(&List->Link)\r
+      ; !IsListEmpty (&List->Link)\r
+      ; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link)\r
+     ){\r
+    RemoveEntryList(&BufferListEntry->Link);\r
+    ASSERT(BufferListEntry->Buffer != NULL);\r
+    SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE*)(BufferListEntry->Buffer))->Path);\r
+    SHELL_FREE_NON_NULL(BufferListEntry->Buffer);\r
+    SHELL_FREE_NON_NULL(BufferListEntry);\r
+  }\r
+}\r
+\r
 /**\r
   Destructor for the library.  free any resources.\r
 \r
@@ -169,7 +200,7 @@ ShellCommandLibDestructor (
     }\r
   }\r
   if (!IsListEmpty(&mFileHandleList.Link)){\r
-    FreeBufferList(&mFileHandleList);\r
+    FreeFileHandleList(&mFileHandleList);\r
   }\r
 \r
   if (mProfileList != NULL) {\r