adjust memory allocation functions in windows API ecl_get_commandline_args.

the caller and the callee maybe use difference compiler and settings.
This commit is contained in:
Yuguo Zhang 2017-06-13 18:22:59 +08:00
parent 040ec49138
commit 52a232b2d1
2 changed files with 7 additions and 2 deletions

View file

@ -939,6 +939,7 @@ si_pointer(cl_object x)
#if defined(ECL_MS_WINDOWS_HOST)
void
ecl_get_commandline_args(int* argc, char*** argv) {
/* the caller should use LocalFree to release the memory of strings in argv and argv itself */
LPWSTR *wArgs;
int i;
@ -946,10 +947,10 @@ ecl_get_commandline_args(int* argc, char*** argv) {
return;
wArgs = CommandLineToArgvW(GetCommandLineW(), argc);
*argv = (char**)malloc(sizeof(char*)*(*argc));
*argv = (char**)LocalAlloc(0, sizeof(char*)*(*argc));
for (i=0; i<*argc; i++) {
int len = wcslen(wArgs[i]);
(*argv)[i] = (char*)malloc(2*(len+1));
(*argv)[i] = (char*)LocalAlloc(0, 2*(len+1));
wcstombs((*argv)[i], wArgs[i], len+1);
}
LocalFree(wArgs);

View file

@ -333,6 +333,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
~A
} ECL_CATCH_ALL_END;
si_exit(0);
for (int i = 0; i < argc; i++) {
LocalFree(argv[i]);
}
LocalFree(argv);
}
")