From 52a232b2d185977dd6fd6e9c54b53aaf17cc0df0 Mon Sep 17 00:00:00 2001 From: Yuguo Zhang Date: Tue, 13 Jun 2017 18:22:59 +0800 Subject: [PATCH] adjust memory allocation functions in windows API ecl_get_commandline_args. the caller and the callee maybe use difference compiler and settings. --- src/c/main.d | 5 +++-- src/cmp/cmpmain.lsp | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/c/main.d b/src/c/main.d index c70404086..684b16f17 100755 --- a/src/c/main.d +++ b/src/c/main.d @@ -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); diff --git a/src/cmp/cmpmain.lsp b/src/cmp/cmpmain.lsp index 5772b5948..4da87142d 100755 --- a/src/cmp/cmpmain.lsp +++ b/src/cmp/cmpmain.lsp @@ -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); } ")