From 7d201b58faa8f80205e243af35d8dbc09966982b Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Tue, 10 Oct 2023 11:49:12 -0700 Subject: [PATCH] Ensure AIMapper and underlying IMPL outlive IMapperProvider ... as a static vendor::mapper::IMapperProvider provider; may be destructed during a clean process exit (during __cxa_finalize()) but the underlying IMPL may still be in use on other threads. Bug: b/304343434 Test: boot Cuttlefish Change-Id: I80687494c61210d527908b5a67375950ca45c8ea --- .../graphics/mapper/utils/IMapperProvider.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/graphics/mapper/stable-c/implutils/include/android/hardware/graphics/mapper/utils/IMapperProvider.h b/graphics/mapper/stable-c/implutils/include/android/hardware/graphics/mapper/utils/IMapperProvider.h index 957fdc95ed..c4d1a0d56b 100644 --- a/graphics/mapper/stable-c/implutils/include/android/hardware/graphics/mapper/utils/IMapperProvider.h +++ b/graphics/mapper/stable-c/implutils/include/android/hardware/graphics/mapper/utils/IMapperProvider.h @@ -106,15 +106,15 @@ class IMapperProvider { static_assert(std::is_constructible_v, "Implementation must have a no-args constructor"); std::once_flag mLoadOnceFlag; - std::optional mImpl; - AIMapper mMapper = {}; + IMPL* _Nullable mImpl; + AIMapper* _Nullable mMapper; static IMPL& impl() { return *reinterpret_cast*>(provider::sIMapperInstance)->mImpl; } void bindV5() { - mMapper.v5 = { + mMapper->v5 = { .importBuffer = [](const native_handle_t* _Nonnull handle, buffer_handle_t _Nullable* _Nonnull outBufferHandle) -> AIMapper_Error { return impl().importBuffer(handle, outBufferHandle); }, @@ -208,13 +208,14 @@ class IMapperProvider { LOG_ALWAYS_FATAL_IF(provider::sIMapperInstance != nullptr, "AIMapper implementation already loaded!"); provider::sIMapperInstance = this; - mImpl.emplace(); - mMapper.version = IMPL::version; + mImpl = new IMPL(); + mMapper = new AIMapper(); + mMapper->version = IMPL::version; if (IMPL::version >= AIMAPPER_VERSION_5) { bindV5(); } }); - *outImplementation = &mMapper; + *outImplementation = mMapper; return AIMAPPER_ERROR_NONE; } };