From 10750526a6c9c05b6730263494ed6fbb2fa9949a Mon Sep 17 00:00:00 2001 From: JihCheng Chiu Date: Sat, 11 Jun 2022 01:53:11 +0800 Subject: [PATCH] fix segmentation fault of GraphicsComposerAidlCommandTest When we run the VTS of GraphicsComposerAidlCommandTest, we always meet segmentation fault issue in some test items. VTS test items crashed when it deleted the layer or display from resource manager and try to go next loop. The problem is the test item try to delete the layer iterator or display iterator in the loop, so the iterator become an invalid iterator. Then it try to use the invalid iterator for going to next iterator. This behavior caused segmentation fault. We use different way to fix deleting layer and deleting display. Delete layer: Test item always delete all layer for each display, so we always delete layer via get the first iterator until the resource manager is empty. Delete display: Test item only delete virtual display, so we move the physical display to a temporary map. After delete all virtual display, we swap the temporary map and original map. Bug: 243781450 Test: 1. test GraphicsComposerAidlCommandTest.SetLayerColorTransform for deleting layer 2. test GraphicsComposerAidlCommandTest.SetOutputBuffer for deleting disply Change-Id: Id467df658e78ed29fdfc039cabc119f8bf62d69d --- graphics/composer/aidl/vts/VtsComposerClient.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/graphics/composer/aidl/vts/VtsComposerClient.cpp b/graphics/composer/aidl/vts/VtsComposerClient.cpp index 2b607038fe..5bc7296f21 100644 --- a/graphics/composer/aidl/vts/VtsComposerClient.cpp +++ b/graphics/composer/aidl/vts/VtsComposerClient.cpp @@ -488,10 +488,13 @@ bool VtsComposerClient::verifyComposerCallbackParams() { } bool VtsComposerClient::destroyAllLayers() { - for (const auto& it : mDisplayResources) { - const auto& [display, resource] = it; + std::unordered_map physicalDisplays; + while (!mDisplayResources.empty()) { + const auto& it = mDisplayResources.begin(); + const auto& [display, resource] = *it; - for (auto layer : resource.layers) { + while (!resource.layers.empty()) { + auto layer = *resource.layers.begin(); const auto status = destroyLayer(display, layer); if (!status.isOk()) { ALOGE("Unable to destroy all the layers, failed at layer %" PRId64 " with error %s", @@ -507,8 +510,12 @@ bool VtsComposerClient::destroyAllLayers() { status.getDescription().c_str()); return false; } + } else { + auto extractIter = mDisplayResources.extract(it); + physicalDisplays.insert(std::move(extractIter)); } } + mDisplayResources.swap(physicalDisplays); mDisplayResources.clear(); return true; }