Skip to content

Commit

Permalink
free cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuomingliang committed Sep 5, 2013
1 parent 356cd00 commit 8cd5249
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/io/procops.c
Expand Up @@ -105,31 +105,30 @@ MVMint64 MVM_proc_spawn(MVMThreadContext *tc, MVMString *cmd, MVMString *cwd, MV
int i;

char * const cmdin = MVM_string_utf8_encode_C_string(tc, cmd);
char * const _cwd = MVM_string_utf8_encode_C_string(tc, cwd);
const MVMuint64 size = MVM_repr_elems(tc, env);
char **_env = malloc((size + 1) * sizeof(char *));
MVMIter * const iter = (MVMIter *)MVM_iter(tc, env);
MVMString * const equal = MVM_string_ascii_decode_nt(tc, tc->instance->VMString, "=");

#ifdef _WIN32
const char comspec[] = "ComSpec";
const MVMuint16 acp = GetACP(); /* We should get ACP at runtime. */
wchar_t * const wcomspec = ANSIToUnicode(acp, comspec);
wchar_t * const wcomspec = ANSIToUnicode(acp, "ComSpec");
wchar_t * const wcmd = _wgetenv(wcomspec);
char * const _cmd = UnicodeToUTF8(wcmd);

free(wcomspec);

args[0] = _cmd;
args[1] = "/c";
args[2] = cmdin;
args[3] = NULL;
#else
char sh[] = "/bin/sh";
args[0] = sh;
args[0] = "/bin/sh";
args[1] = "-c";
#endif

args[2] = cmdin;
args[3] = NULL;
#endif

MVMROOT(tc, iter, {
i = 0;
while(MVM_iter_istrue(tc, iter)) {
Expand All @@ -144,21 +143,23 @@ MVMint64 MVM_proc_spawn(MVMThreadContext *tc, MVMString *cmd, MVMString *cwd, MV
});

process_options.args = args;
process_options.cwd = MVM_string_utf8_encode_C_string(tc, cwd);
process_options.cwd = _cwd;
process_options.flags = UV_PROCESS_DETACHED | UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS | UV_PROCESS_WINDOWS_HIDE;
process_options.env = _env;
result = uv_spawn(tc->loop, &process, &process_options);

#ifdef _WIN32
free(_cmd);
#endif

free(cmdin);
free(_cwd);

i = 0;
while(_env[i])
free(_env[i++]);

free(_env);

#ifdef _WIN32
free(_cmd);
#endif
return result;
}

Expand Down

0 comments on commit 8cd5249

Please sign in to comment.