Bug 685847 - Crash in [@ ILFindLastID ]. r=jimm
authorBrian R. Bondy <netzen@gmail.com>
Mon, 12 Sep 2011 07:25:41 -0700
changeset 76885 da2f5b63ba1e7c9c0b7efccbc7a5ca1608d792e4
parent 76884 b991feb93d32ea9c9d8a6b711125d185ce9f6ca3
child 76907 c9479e3f6c54a969f32add6c87b06acc8530dc9e
child 77074 308778dc874b01e4c68fc825e7a892343b3c7172
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjimm
bugs685847
milestone9.0a1
Bug 685847 - Crash in [@ ILFindLastID ]. r=jimm
xpcom/io/nsLocalFileWin.cpp
xpcom/io/nsLocalFileWin.h
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -100,17 +100,16 @@ unsigned char *_mbsstr( const unsigned c
 }
 #endif
 
 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000
 #endif
 
 ILCreateFromPathWPtr nsLocalFile::sILCreateFromPathW = NULL;
-ILFreePtr nsLocalFile::sILFree = NULL;
 SHOpenFolderAndSelectItemsPtr nsLocalFile::sSHOpenFolderAndSelectItems = NULL;
 PRLibrary *nsLocalFile::sLibShell = NULL;
 
 class nsDriveEnumerator : public nsISimpleEnumerator
 {
 public:
     nsDriveEnumerator();
     virtual ~nsDriveEnumerator();
@@ -2734,39 +2733,38 @@ nsLocalFile::RevealClassic()
   return NS_OK;
 }
 
 nsresult 
 nsLocalFile::RevealUsingShell()
 {
   // All of these shell32.dll related pointers should be non NULL 
   // on XP and later.
-  if (!sLibShell || !sILCreateFromPathW || 
-      !sILFree || !sSHOpenFolderAndSelectItems) {
+  if (!sLibShell || !sILCreateFromPathW || !sSHOpenFolderAndSelectItems) {
     return NS_ERROR_FAILURE;
   }
 
   PRBool isDirectory;
   nsresult rv = IsDirectory(&isDirectory);
   NS_ENSURE_SUCCESS(rv, rv);
 
   HRESULT hr;
   if (isDirectory) {
     // We have a directory so we should open the directory itself.
     ITEMIDLIST *dir = sILCreateFromPathW(mResolvedPath.get());
     if (!dir) {
       return NS_ERROR_FAILURE;
     }
 
     const ITEMIDLIST* selection[] = { dir };
-    UINT count = sizeof(selection) / sizeof(ITEMIDLIST);
+    UINT count = PR_ARRAY_SIZE(selection);
 
     //Perform the open of the directory.
     hr = sSHOpenFolderAndSelectItems(dir, count, selection, 0);
-    sILFree(dir);
+    CoTaskMemFree(dir);
   }
   else {
     // Obtain the parent path of the item we are revealing.
     nsCOMPtr<nsIFile> parentDirectory;
     rv = GetParent(getter_AddRefs(parentDirectory));
     NS_ENSURE_SUCCESS(rv, rv);
     nsAutoString parentDirectoryPath;
     rv = parentDirectory->GetPath(parentDirectoryPath);
@@ -2776,28 +2774,28 @@ nsLocalFile::RevealUsingShell()
     ITEMIDLIST *dir = sILCreateFromPathW(parentDirectoryPath.get());
     if (!dir) {
       return NS_ERROR_FAILURE;
     }
 
     // Set the item in the directory to select to the file we want to reveal.
     ITEMIDLIST *item = sILCreateFromPathW(mResolvedPath.get());
     if (!item) {
-      sILFree(dir);
+      CoTaskMemFree(dir);
       return NS_ERROR_FAILURE;
     }
     
     const ITEMIDLIST* selection[] = { item };
-    UINT count = sizeof(selection) / sizeof(ITEMIDLIST);
+    UINT count = PR_ARRAY_SIZE(selection);
 
     //Perform the selection of the file.
     hr = sSHOpenFolderAndSelectItems(dir, count, selection, 0);
 
-    sILFree(dir);
-    sILFree(item);
+    CoTaskMemFree(dir);
+    CoTaskMemFree(item);
   }
   
   if (SUCCEEDED(hr)) {
     return NS_OK;
   }
   else {
     return NS_ERROR_FAILURE;
   }
@@ -3101,19 +3099,16 @@ nsLocalFile::GlobalInit()
     // loading the library here.
     sLibShell = PR_LoadLibrary("shell32.dll");
     if (sLibShell) {
       // ILCreateFromPathW is available in XP and up.
       sILCreateFromPathW = (ILCreateFromPathWPtr) 
                            PR_FindFunctionSymbol(sLibShell, 
                                                  "ILCreateFromPathW");
 
-      // ILFree is available in XP and up.
-      sILFree = (ILFreePtr) PR_FindFunctionSymbol(sLibShell, "ILFree");
-
       // SHOpenFolderAndSelectItems is available in XP and up.
       sSHOpenFolderAndSelectItems = (SHOpenFolderAndSelectItemsPtr) 
                                      PR_FindFunctionSymbol(sLibShell, 
                                                            "SHOpenFolderAndSelectItems");
     }
 }
 
 void
--- a/xpcom/io/nsLocalFileWin.h
+++ b/xpcom/io/nsLocalFileWin.h
@@ -59,18 +59,17 @@
 DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0);
 #endif
 
 #include "shlobj.h"
 
 #include <sys/stat.h>
 
 typedef LPITEMIDLIST (WINAPI *ILCreateFromPathWPtr)(PCWSTR);
-typedef void (WINAPI *ILFreePtr)(LPITEMIDLIST);
-typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsPtr)(LPCITEMIDLIST, UINT, 
+typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsPtr)(PCIDLIST_ABSOLUTE, UINT, 
                                                         PCUITEMID_CHILD_ARRAY,
                                                         DWORD);
 
 class nsLocalFile : public nsILocalFileWin,
                     public nsIHashable
 {
 public:
     NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
@@ -135,14 +134,13 @@ private:
     nsresult SetModDate(PRInt64 aLastModifiedTime, const PRUnichar *filePath);
     nsresult HasFileAttribute(DWORD fileAttrib, PRBool *_retval);
     nsresult AppendInternal(const nsAFlatString &node,
                             PRBool multipleComponents);
     nsresult RevealClassic(); // Reveals the path using explorer.exe cmdline
     nsresult RevealUsingShell(); // Uses newer shell API to reveal the path
 
     static ILCreateFromPathWPtr sILCreateFromPathW;
-    static ILFreePtr sILFree;
     static SHOpenFolderAndSelectItemsPtr sSHOpenFolderAndSelectItems;
     static PRLibrary *sLibShell;
 };
 
 #endif