Transfer memory ownership when stacking ExtentWriters.
The ExtentWriter implementations are meant to be stacked in a way that
the underlying extent writer can't be reused. Calling End() on the top
of the stack will call End() on every ExtentWriter.
This patch enforces this design decision in the interface transfering
the ownership of the ExtentWriter when stacking them using a unique_ptr
instead of a plain pointer.
Bug: 23604708
Test: Updated unittests.
Change-Id: Ie3b5b9cbb3058359c487a783f6fb3c0ac65bde00
diff --git a/extent_writer_unittest.cc b/extent_writer_unittest.cc
index 9da8adb..0750ebc 100644
--- a/extent_writer_unittest.cc
+++ b/extent_writer_unittest.cc
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
+#include <chromeos/make_unique_ptr.h>
#include <chromeos/secure_blob.h>
#include <gtest/gtest.h>
@@ -189,8 +190,8 @@
chromeos::Blob data(kBlockSize * 2);
test_utils::FillWithData(&data);
- DirectExtentWriter direct_writer;
- ZeroPadExtentWriter zero_pad_writer(&direct_writer);
+ ZeroPadExtentWriter zero_pad_writer(
+ chromeos::make_unique_ptr(new DirectExtentWriter()));
EXPECT_TRUE(zero_pad_writer.Init(fd_, extents, kBlockSize));
size_t bytes_to_write = data.size();