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.
This commit is contained in:
Rob Shearman 2008-02-14 14:38:58 +00:00 committed by Alexandre Julliard
parent 3d55b590b5
commit 4510346b4f
1 changed files with 4 additions and 8 deletions

View File

@ -85,7 +85,6 @@ extern const char * const SHELL_Authors[];
LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs) LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
{ {
DWORD argc; DWORD argc;
HGLOBAL hargv;
LPWSTR *argv; LPWSTR *argv;
LPCWSTR cs; LPCWSTR cs;
LPWSTR arg,s,d; LPWSTR arg,s,d;
@ -97,20 +96,18 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
/* Return the path to the executable */ /* Return the path to the executable */
DWORD len, size=16; DWORD len, size=16;
hargv=LocalAlloc(0, size); argv=LocalAlloc(LMEM_FIXED, size);
argv=LocalLock(hargv);
for (;;) for (;;)
{ {
len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR)); len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
if (!len) if (!len)
{ {
LocalFree(hargv); LocalFree(argv);
return NULL; return NULL;
} }
if (len < size) break; if (len < size) break;
size*=2; size*=2;
hargv=LocalReAlloc(hargv, size, 0); argv=LocalReAlloc(argv, size, 0);
argv=LocalLock(hargv);
} }
argv[0]=(LPWSTR)(argv+1); argv[0]=(LPWSTR)(argv+1);
if (numargs) 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. /* 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. * 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=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
argv=GlobalLock(hargv);
if (!argv) if (!argv)
return NULL; return NULL;
cmdline=(LPWSTR)(argv+argc); cmdline=(LPWSTR)(argv+argc);