VM: Fix asan memory leak in some standalone tests

Fixes #28350

R=vegorov@google.com

Review-Url: https://codereview.chromium.org/2653583002 .
This commit is contained in:
Martin Kustermann 2017-01-23 19:45:28 +01:00
parent cc40d8bbe4
commit 3f0ea0f50e
3 changed files with 32 additions and 16 deletions

View file

@ -124,12 +124,22 @@ void FUNCTION_NAME(Directory_FillWithDirectoryListing)(
Dart_Handle path = Dart_GetNativeArgument(args, 1);
Dart_Handle recursive = Dart_GetNativeArgument(args, 2);
Dart_Handle follow_links = Dart_GetNativeArgument(args, 3);
// Pass the list that should hold the directory listing to the
// SyncDirectoryListing object, which adds elements to it.
SyncDirectoryListing sync_listing(results, DartUtils::GetStringValue(path),
DartUtils::GetBooleanValue(recursive),
DartUtils::GetBooleanValue(follow_links));
Directory::List(&sync_listing);
Dart_Handle dart_error;
{
// Pass the list that should hold the directory listing to the
// SyncDirectoryListing object, which adds elements to it.
SyncDirectoryListing sync_listing(results, DartUtils::GetStringValue(path),
DartUtils::GetBooleanValue(recursive),
DartUtils::GetBooleanValue(follow_links));
Directory::List(&sync_listing);
dart_error = sync_listing.dart_error();
}
if (Dart_IsError(dart_error)) {
Dart_PropagateError(dart_error);
} else if (!Dart_IsNull(dart_error)) {
Dart_ThrowException(dart_error);
}
}
@ -401,7 +411,8 @@ bool SyncDirectoryListing::HandleDirectory(const char* dir_name) {
Dart_Handle dir = Dart_New(directory_type_, Dart_Null(), 1, &dir_name_dart);
Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &dir);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
dart_error_ = result;
return false;
}
return true;
}
@ -412,7 +423,8 @@ bool SyncDirectoryListing::HandleLink(const char* link_name) {
Dart_Handle link = Dart_New(link_type_, Dart_Null(), 1, &link_name_dart);
Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &link);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
dart_error_ = result;
return false;
}
return true;
}
@ -423,7 +435,8 @@ bool SyncDirectoryListing::HandleFile(const char* file_name) {
Dart_Handle file = Dart_New(file_type_, Dart_Null(), 1, &file_name_dart);
Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &file);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
dart_error_ = result;
return false;
}
return true;
}
@ -435,10 +448,11 @@ bool SyncDirectoryListing::HandleError() {
args[0] = DartUtils::NewString("Directory listing failed");
args[1] = DartUtils::NewString(error() ? "Invalid path" : CurrentPath());
args[2] = dart_os_error;
Dart_ThrowException(Dart_New(
dart_error_ = Dart_New(
DartUtils::GetDartType(DartUtils::kIOLibURL, "FileSystemException"),
Dart_Null(), 3, args));
return true;
Dart_Null(), 3, args);
return false;
}

View file

@ -196,7 +196,9 @@ class SyncDirectoryListing : public DirectoryListing {
const char* dir_name,
bool recursive,
bool follow_links)
: DirectoryListing(dir_name, recursive, follow_links), results_(results) {
: DirectoryListing(dir_name, recursive, follow_links),
results_(results),
dart_error_(Dart_Null()) {
add_string_ = DartUtils::NewString("add");
directory_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Directory");
file_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "File");
@ -208,12 +210,15 @@ class SyncDirectoryListing : public DirectoryListing {
virtual bool HandleLink(const char* file_name);
virtual bool HandleError();
Dart_Handle dart_error() { return dart_error_; }
private:
Dart_Handle results_;
Dart_Handle add_string_;
Dart_Handle directory_type_;
Dart_Handle file_type_;
Dart_Handle link_type_;
Dart_Handle dart_error_;
DISALLOW_ALLOCATION()
DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing);

View file

@ -389,9 +389,6 @@ io/socket_info_ipv6_test: SkipByDesign
[ $builder_tag == asan && $arch == x64 ]
io/process_detached_test: Pass, Slow
io/directory_error_test: Fail # Issue 28350
io/directory_fuzz_test: Fail # Issue 28350
io/directory_list_nonexistent_test: Fail # Issue 28350
io/stdout_bad_argument_test: Fail # Issue 28353
io/file_blocking_lock_test: Fail # Issue 28353