From e62591ec3b76de534ec84532c555a7656fa5f91c Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 4 Dec 2019 00:15:39 -0800 Subject: [PATCH] libsnapshot: Call EnsureImageManager before RemoveAllImages Calls to RemoveAllImages may be on uninitialized image manager. Test: apply OTA to self Change-Id: Id57c01ddfdb6985fb2c3c142ee19fd65eef6c131 --- fs_mgr/libsnapshot/snapshot.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 33c122b9f..80d73c3cf 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -132,7 +132,9 @@ bool SnapshotManager::BeginUpdate() { // Purge the ImageManager just in case there is a corrupt lp_metadata file // lying around. (NB: no need to return false on an error, we can let the // update try to progress.) - images_->RemoveAllImages(); + if (EnsureImageManager()) { + images_->RemoveAllImages(); + } auto state = ReadUpdateState(file.get()); if (state != UpdateState::None) { @@ -1203,7 +1205,7 @@ bool SnapshotManager::RemoveAllSnapshots(LockedFile* lock) { // being cancelled due to some corrupted state in an lp_metadata file. // Note that we do not do this if some cow images are still mapped, // since we must not remove backing storage if it's in use. - if (!images_->RemoveAllImages()) { + if (!EnsureImageManager() || !images_->RemoveAllImages()) { LOG(ERROR) << "Could not remove all snapshot artifacts"; return false; }