Check for null of cow_writer_ before call Finalize() am: 6a4d1ec1d0 am: 904efb9d95 am: 54c03f335c

Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1576643

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I9cbdb0af93fceeaa7f1b6dc23942b9c4085435ef
diff --git a/payload_consumer/vabc_partition_writer.cc b/payload_consumer/vabc_partition_writer.cc
index 2479132..aa8c3ce 100644
--- a/payload_consumer/vabc_partition_writer.cc
+++ b/payload_consumer/vabc_partition_writer.cc
@@ -153,17 +153,23 @@
 void VABCPartitionWriter::CheckpointUpdateProgress(size_t next_op_index) {
   // No need to call fsync/sync, as CowWriter flushes after a label is added
   // added.
+  // if cow_writer_ failed, that means Init() failed. This function shouldn't be
+  // called if Init() fails.
+  TEST_AND_RETURN(cow_writer_ != nullptr);
   cow_writer_->AddLabel(next_op_index);
 }
 
 [[nodiscard]] bool VABCPartitionWriter::FinishedInstallOps() {
   // Add a hardcoded magic label to indicate end of all install ops. This label
   // is needed by filesystem verification, don't remove.
+  TEST_AND_RETURN_FALSE(cow_writer_ != nullptr);
   return cow_writer_->AddLabel(kEndOfInstallLabel);
 }
 
 VABCPartitionWriter::~VABCPartitionWriter() {
-  cow_writer_->Finalize();
+  if (cow_writer_) {
+    cow_writer_->Finalize();
+  }
 }
 
 }  // namespace chromeos_update_engine