Skip to content

Commit db844b1

Browse files
ssudapiscisaureus
ssuda
authored andcommitted
process: don't use strdup()
file and cwd can be directly used from Utf8Value. Conflicts: src/process_wrap.cc
1 parent 3546383 commit db844b1

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/process_wrap.cc

+5-10
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ class ProcessWrap : public HandleWrap {
139139

140140
// options.file
141141
Local<Value> file_v = js_options->Get(String::NewSymbol("file"));
142-
if (!file_v.IsEmpty() && file_v->IsString()) {
143-
String::Utf8Value file(file_v->ToString());
144-
options.file = strdup(*file);
142+
String::Utf8Value file(file_v->IsString() ? file_v : Local<Value>());
143+
if (file.length() > 0) {
144+
options.file = *file;
145145
} else {
146146
return ThrowException(Exception::TypeError(String::New("Bad argument")));
147147
}
@@ -162,12 +162,10 @@ class ProcessWrap : public HandleWrap {
162162

163163
// options.cwd
164164
Local<Value> cwd_v = js_options->Get(String::NewSymbol("cwd"));
165-
if (!cwd_v.IsEmpty() && cwd_v->IsString()) {
166-
String::Utf8Value cwd(cwd_v->ToString());
165+
String::Utf8Value cwd(cwd_v->IsString() ? cwd_v : Local<Value>());
167166
if (cwd.length() > 0) {
168-
options.cwd = strdup(*cwd);
167+
options.cwd = *cwd;
169168
}
170-
}
171169

172170
// options.env
173171
Local<Value> env_v = js_options->Get(String::NewSymbol("envPairs"));
@@ -228,9 +226,6 @@ class ProcessWrap : public HandleWrap {
228226
delete [] options.args;
229227
}
230228

231-
free(options.cwd);
232-
free((void*)options.file);
233-
234229
if (options.env) {
235230
for (int i = 0; options.env[i]; i++) free(options.env[i]);
236231
delete [] options.env;

0 commit comments

Comments
 (0)