From 0c9902ca67fffa547da1b932985e9532854584b2 Mon Sep 17 00:00:00 2001 From: "iposva@google.com" Date: Tue, 15 Nov 2011 17:47:21 +0000 Subject: [PATCH] - Avoid allocating variable length arrays on the stack. - Fix C++ warning about copying vtables. - Use correct delete for PortMap entries. Review URL: http://codereview.chromium.org//8555024 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1538 260f80e4-7a28-3924-810f-c04153c831b5 --- runtime/bin/process_linux.cc | 6 +++++- runtime/bin/process_macos.cc | 6 +++++- runtime/vm/globals.h | 4 +++- runtime/vm/port.cc | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc index 15ecac3fe99..e96d7aa6cbb 100644 --- a/runtime/bin/process_linux.cc +++ b/runtime/bin/process_linux.cc @@ -189,7 +189,7 @@ int Process::Start(const char* path, return errno; } - char* program_arguments[arguments_length + 2]; + char** program_arguments = new char*[arguments_length + 2]; program_arguments[0] = const_cast(path); for (int i = 0; i < arguments_length; i++) { program_arguments[i + 1] = arguments[i]; @@ -206,6 +206,7 @@ int Process::Start(const char* path, pid = fork(); if (pid < 0) { SetChildOsErrorMessage(os_error_message, os_error_message_len); + delete[] program_arguments; close(read_in[0]); close(read_in[1]); close(read_err[0]); @@ -255,6 +256,9 @@ int Process::Start(const char* path, exit(1); } + // The arguments for the spawned process are not needed any longer. + delete[] program_arguments; + int event_fds[2]; result = pipe(event_fds); if (result < 0) { diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc index bd6f150a732..542f05cd805 100644 --- a/runtime/bin/process_macos.cc +++ b/runtime/bin/process_macos.cc @@ -189,7 +189,7 @@ int Process::Start(const char* path, return errno; } - char* program_arguments[arguments_length + 2]; + char** program_arguments = new char*[arguments_length + 2]; program_arguments[0] = const_cast(path); for (int i = 0; i < arguments_length; i++) { program_arguments[i + 1] = arguments[i]; @@ -206,6 +206,7 @@ int Process::Start(const char* path, pid = fork(); if (pid < 0) { SetChildOsErrorMessage(os_error_message, os_error_message_len); + delete[] program_arguments; close(read_in[0]); close(read_in[1]); close(read_err[0]); @@ -255,6 +256,9 @@ int Process::Start(const char* path, exit(1); } + // The arguments for the spawned process are not needed any longer. + delete[] program_arguments; + int event_fds[2]; result = pipe(event_fds); if (result < 0) { diff --git a/runtime/vm/globals.h b/runtime/vm/globals.h index 9dfad15ba2e..bd3c0a63dac 100644 --- a/runtime/vm/globals.h +++ b/runtime/vm/globals.h @@ -315,7 +315,9 @@ template inline D bit_copy(const S& source) { D destination; // This use of memcpy is safe: source and destination cannot overlap. - memcpy(&destination, &source, sizeof(destination)); + memcpy(&destination, + reinterpret_cast(&source), + sizeof(destination)); return destination; } diff --git a/runtime/vm/port.cc b/runtime/vm/port.cc index fb331073a01..1fd8e870780 100644 --- a/runtime/vm/port.cc +++ b/runtime/vm/port.cc @@ -54,7 +54,7 @@ void PortMap::Rehash(intptr_t new_capacity) { new_ports[new_index] = entry; } } - delete map_; + delete[] map_; map_ = new_ports; capacity_ = new_capacity; deleted_ = 0;