Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: runtime/bin/directory_win.cc

Issue 16929007: - Do NOT mix malloc/free and new/delete! (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 #include "bin/file.h" 9 #include "bin/file.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
11 11
12 #include <errno.h> // NOLINT 12 #include <errno.h> // NOLINT
13 #include <sys/stat.h> // NOLINT 13 #include <sys/stat.h> // NOLINT
14 14
15 #include "bin/log.h" 15 #include "bin/log.h"
16 16
17 #undef DeleteFile 17 #undef DeleteFile
18 18
19 namespace dart { 19 namespace dart {
20 namespace bin { 20 namespace bin {
21 21
22 PathBuffer::PathBuffer() : length_(0) { 22 PathBuffer::PathBuffer() : length_(0) {
23 data_ = new wchar_t[MAX_PATH + 1]; 23 data_ = calloc(PATH_MAX + 1, sizeof(wchar_t)); // NOLINT
24 } 24 }
25 25
26 char* PathBuffer::AsString() const { 26 char* PathBuffer::AsString() const {
27 return StringUtils::WideToUtf8(AsStringW()); 27 return StringUtils::WideToUtf8(AsStringW());
28 } 28 }
29 29
30 wchar_t* PathBuffer::AsStringW() const { 30 wchar_t* PathBuffer::AsStringW() const {
31 return reinterpret_cast<wchar_t*>(data_); 31 return reinterpret_cast<wchar_t*>(data_);
32 } 32 }
33 33
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 if (FindClose(reinterpret_cast<HANDLE>(lister_)) == 0) { 209 if (FindClose(reinterpret_cast<HANDLE>(lister_)) == 0) {
210 return kListError; 210 return kListError;
211 } 211 }
212 212
213 return kListDone; 213 return kListDone;
214 } 214 }
215 215
216 216
217 void DirectoryListingEntry::ResetLink() {
218 if (link_ != NULL && (parent_ == NULL || parent_->link_ != link_)) {
219 delete link_;
220 link_ = NULL;
221 }
222 if (parent_ != NULL) {
223 link_ = parent_->link_;
224 }
225 }
226
227
217 static bool DeleteFile(wchar_t* file_name, PathBuffer* path) { 228 static bool DeleteFile(wchar_t* file_name, PathBuffer* path) {
218 if (!path->AddW(file_name)) return false; 229 if (!path->AddW(file_name)) return false;
219 230
220 if (DeleteFileW(path->AsStringW()) != 0) { 231 if (DeleteFileW(path->AsStringW()) != 0) {
221 return true; 232 return true;
222 } 233 }
223 234
224 // If we failed because the file is read-only, make it writeable and try 235 // If we failed because the file is read-only, make it writeable and try
225 // again. This mirrors Linux/Mac where a directory containing read-only files 236 // again. This mirrors Linux/Mac where a directory containing read-only files
226 // can still be recursively deleted. 237 // can still be recursively deleted.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 MoveFileExW(system_path, system_new_path, flags); 468 MoveFileExW(system_path, system_new_path, flags);
458 free(const_cast<wchar_t*>(system_path)); 469 free(const_cast<wchar_t*>(system_path));
459 free(const_cast<wchar_t*>(system_new_path)); 470 free(const_cast<wchar_t*>(system_new_path));
460 return (move_status != 0); 471 return (move_status != 0);
461 } 472 }
462 473
463 } // namespace bin 474 } // namespace bin
464 } // namespace dart 475 } // namespace dart
465 476
466 #endif // defined(TARGET_OS_WINDOWS) 477 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698