Rob Shearman : shell32: Memory allocated by CommandLineToArgvW should be that got from LocalAlloc/ LocalReAlloc, not from GlobalAlloc.

Alexandre Julliard julliard at winehq.org
Fri Feb 15 05:36:00 CST 2008


Module: wine
Branch: master
Commit: 4510346b4f69e91c05cf28f9b80604352fbb6772
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4510346b4f69e91c05cf28f9b80604352fbb6772

Author: Rob Shearman <rob at codeweavers.com>
Date:   Thu Feb 14 14:38:58 2008 +0000

shell32: Memory allocated by CommandLineToArgvW should be that got from LocalAlloc/LocalReAlloc, not from GlobalAlloc.

Use LMEM_FIXED instead of 0 in calls to LocalAlloc to emphasise that 
we're getting a direct pointer, not a handle to memory.

Remove hargv as it is confusing and unnecessary.

---

 dlls/shell32/shell32_main.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/dlls/shell32/shell32_main.c b/dlls/shell32/shell32_main.c
index a64381f..336a519 100644
--- a/dlls/shell32/shell32_main.c
+++ b/dlls/shell32/shell32_main.c
@@ -85,7 +85,6 @@ extern const char * const SHELL_Authors[];
 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
 {
     DWORD argc;
-    HGLOBAL hargv;
     LPWSTR  *argv;
     LPCWSTR cs;
     LPWSTR arg,s,d;
@@ -97,20 +96,18 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
         /* Return the path to the executable */
         DWORD len, size=16;
 
-        hargv=LocalAlloc(0, size);
-        argv=LocalLock(hargv);
+        argv=LocalAlloc(LMEM_FIXED, size);
         for (;;)
         {
             len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
             if (!len)
             {
-                LocalFree(hargv);
+                LocalFree(argv);
                 return NULL;
             }
             if (len < size) break;
             size*=2;
-            hargv=LocalReAlloc(hargv, size, 0);
-            argv=LocalLock(hargv);
+            argv=LocalReAlloc(argv, size, 0);
         }
         argv[0]=(LPWSTR)(argv+1);
         if (numargs)
@@ -160,8 +157,7 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
     /* Allocate in a single lump, the string array, and the strings that go with it.
      * This way the caller can make a single GlobalFree call to free both, as per MSDN.
      */
-    hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
-    argv=GlobalLock(hargv);
+    argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
     if (!argv)
         return NULL;
     cmdline=(LPWSTR)(argv+argc);




More information about the wine-cvs mailing list