Change source to be a unique_ptr.
The current code keeps a pointer to a local variable which doesn't
work too well. Change this to a unique_ptr and allocate the source
object that will be used instead.
Test: All unit tests pass.
Test: fastboot -w flashall on a mokey which crashed without this change.
Change-Id: Ief5437374181e514928c45dd540b42898901a137
diff --git a/fastboot/task_test.cpp b/fastboot/task_test.cpp
index 1e25b6f..9cde1a8 100644
--- a/fastboot/task_test.cpp
+++ b/fastboot/task_test.cpp
@@ -192,8 +192,7 @@
GTEST_SKIP();
}
- LocalImageSource s;
- fp->source = &s;
+ fp->source.reset(new LocalImageSource);
fp->sparse_limit = std::numeric_limits<int64_t>::max();
fastboot::MockFastbootDriver fb;
@@ -239,8 +238,7 @@
GTEST_SKIP();
}
- LocalImageSource s;
- fp->source = &s;
+ fp->source.reset(new LocalImageSource);
fastboot::MockFastbootDriver fb;
fp->fb = &fb;
@@ -260,7 +258,7 @@
ParseFastbootInfoLine(fp.get(), android::base::Tokenize(test.first, " "));
auto flash_task = task->AsFlashTask();
ASSERT_FALSE(flash_task == nullptr);
- ASSERT_EQ(FlashTask::IsDynamicParitition(fp->source, flash_task), test.second);
+ ASSERT_EQ(FlashTask::IsDynamicParitition(fp->source.get(), flash_task), test.second);
}
}
@@ -269,8 +267,7 @@
GTEST_SKIP();
}
- LocalImageSource s;
- fp->source = &s;
+ fp->source.reset(new LocalImageSource);
fp->sparse_limit = std::numeric_limits<int64_t>::max();
fastboot::MockFastbootDriver fb;
@@ -301,7 +298,7 @@
for (auto& test : patternmatchtest) {
std::vector<std::unique_ptr<Task>> tasks = ParseFastbootInfo(fp.get(), test.first);
tasks.erase(std::remove_if(tasks.begin(), tasks.end(), remove_if_callback), tasks.end());
- ASSERT_EQ(OptimizedFlashSuperTask::CanOptimize(fp->source, tasks), test.second);
+ ASSERT_EQ(OptimizedFlashSuperTask::CanOptimize(fp->source.get(), tasks), test.second);
}
}
@@ -312,8 +309,7 @@
GTEST_SKIP();
}
- LocalImageSource s;
- fp->source = &s;
+ fp->source.reset(new LocalImageSource);
fp->sparse_limit = std::numeric_limits<int64_t>::max();
fastboot::MockFastbootDriver fb;
@@ -362,7 +358,7 @@
contains_optimized_task = true;
}
if (auto flash_task = task->AsFlashTask()) {
- if (FlashTask::IsDynamicParitition(fp->source, flash_task)) {
+ if (FlashTask::IsDynamicParitition(fp->source.get(), flash_task)) {
return false;
}
}