@@ -377,12 +377,13 @@ class ProcessStarter {
377377 child_process_handle_ = INVALID_HANDLE_VALUE;
378378
379379 // Transform input strings to system format.
380- const wchar_t * system_path = StringUtilsWin::Utf8ToWide (path_);
381- const wchar_t ** system_arguments;
382- system_arguments = reinterpret_cast <const wchar_t **>(
383- Dart_ScopeAllocate (arguments_length * sizeof (*system_arguments)));
380+ wchar_t * system_path = nullptr ;
381+ StringUtilsWin::Utf8ToWide (path_, &system_path);
382+ wchar_t ** system_arguments;
383+ system_arguments = reinterpret_cast <wchar_t **>(
384+ malloc (arguments_length * sizeof (*system_arguments)));
384385 for (int i = 0 ; i < arguments_length; i++) {
385- system_arguments[i] = StringUtilsWin::Utf8ToWide (arguments[i]);
386+ StringUtilsWin::Utf8ToWide (arguments[i], &(system_arguments[i]) );
386387 }
387388
388389 // Compute command-line length.
@@ -395,7 +396,7 @@ class ProcessStarter {
395396
396397 // Put together command-line string.
397398 command_line_ = reinterpret_cast <wchar_t *>(
398- Dart_ScopeAllocate (command_line_length * sizeof (*command_line_)));
399+ malloc (command_line_length * sizeof (*command_line_)));
399400 int len = 0 ;
400401 int remaining = command_line_length;
401402 int written =
@@ -410,16 +411,21 @@ class ProcessStarter {
410411 remaining -= written;
411412 ASSERT (remaining >= 0 );
412413 }
414+ for (int i = 0 ; i < arguments_length; i++) {
415+ free (system_arguments[i]);
416+ }
417+ free (system_arguments);
418+ free (system_path);
413419
414420 // Create environment block if an environment is supplied.
415421 environment_block_ = nullptr ;
416422 if (environment != nullptr ) {
417423 wchar_t ** system_environment;
418424 system_environment = reinterpret_cast <wchar_t **>(
419- Dart_ScopeAllocate (environment_length * sizeof (*system_environment)));
425+ malloc (environment_length * sizeof (*system_environment)));
420426 // Convert environment strings to system strings.
421427 for (intptr_t i = 0 ; i < environment_length; i++) {
422- system_environment[i] = StringUtilsWin::Utf8ToWide (environment[i]);
428+ StringUtilsWin::Utf8ToWide (environment[i], &(system_environment[i]) );
423429 }
424430
425431 // An environment block is a sequence of zero-terminated strings
@@ -429,7 +435,7 @@ class ProcessStarter {
429435 block_size += wcslen (system_environment[i]) + 1 ;
430436 }
431437 environment_block_ = reinterpret_cast <wchar_t *>(
432- Dart_ScopeAllocate (block_size * sizeof (*environment_block_)));
438+ malloc (block_size * sizeof (*environment_block_)));
433439 intptr_t block_index = 0 ;
434440 for (intptr_t i = 0 ; i < environment_length; i++) {
435441 intptr_t len = wcslen (system_environment[i]);
@@ -442,21 +448,28 @@ class ProcessStarter {
442448 // Block-terminating zero char.
443449 environment_block_[block_index++] = ' \0 ' ;
444450 ASSERT (block_index == block_size);
451+ for (intptr_t i = 0 ; i < environment_length; i++) {
452+ free (system_environment[i]);
453+ }
454+ free (system_environment);
445455 }
446456
447457 system_working_directory_ = nullptr ;
448458 if (working_directory_ != nullptr ) {
449- system_working_directory_ =
450- StringUtilsWin::Utf8ToWide (working_directory_ );
459+ StringUtilsWin::Utf8ToWide (working_directory_,
460+ &system_working_directory_ );
451461 }
452-
453462 attribute_list_ = nullptr ;
454463 }
455464
456465 ~ProcessStarter () {
457466 if (attribute_list_ != nullptr ) {
458467 DeleteProcThreadAttributeList (attribute_list_);
468+ free (attribute_list_);
459469 }
470+ free (command_line_);
471+ free (environment_block_);
472+ free (system_working_directory_);
460473 }
461474
462475 int Start () {
@@ -485,8 +498,8 @@ class ProcessStarter {
485498 (GetLastError () != ERROR_INSUFFICIENT_BUFFER)) {
486499 return CleanupAndReturnError ();
487500 }
488- attribute_list_ = reinterpret_cast <LPPROC_THREAD_ATTRIBUTE_LIST>(
489- Dart_ScopeAllocate (size));
501+ attribute_list_ =
502+ reinterpret_cast <LPPROC_THREAD_ATTRIBUTE_LIST>( malloc (size));
490503 ZeroMemory (attribute_list_, size);
491504 if (!InitializeProcThreadAttributeList (attribute_list_, 1 , 0 , &size)) {
492505 return CleanupAndReturnError ();
@@ -598,8 +611,8 @@ class ProcessStarter {
598611 (GetLastError () != ERROR_INSUFFICIENT_BUFFER)) {
599612 return CleanupAndReturnError ();
600613 }
601- attribute_list_ = reinterpret_cast <LPPROC_THREAD_ATTRIBUTE_LIST>(
602- Dart_ScopeAllocate (size));
614+ attribute_list_ =
615+ reinterpret_cast <LPPROC_THREAD_ATTRIBUTE_LIST>( malloc (size));
603616 ZeroMemory (attribute_list_, size);
604617 if (!InitializeProcThreadAttributeList (attribute_list_, 1 , 0 , &size)) {
605618 return CleanupAndReturnError ();
@@ -701,7 +714,7 @@ class ProcessStarter {
701714 HANDLE exit_handles_[2 ];
702715 HANDLE child_process_handle_;
703716
704- const wchar_t * system_working_directory_;
717+ wchar_t * system_working_directory_;
705718 wchar_t * command_line_;
706719 wchar_t * environment_block_;
707720 std::vector<HANDLE> inherited_handles_;
0 commit comments