Check for null of cow_writer_ before call Finalize()

Test: fake-ota on small verbose, make sure update_engine doesn't crash
Bug: 179231797

Change-Id: I7df45f93fc16444c51d8738b244cf65dc3bb8b7e
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