From 343af902e7a0fb341ebf717a82ae83a5898789e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Artur=20=C5=9Awigo=C5=84?= Date: Mon, 20 Dec 2021 14:44:06 +0100 Subject: [PATCH] [AT-SPI] Use a std::shared_ptr for Bridge BridgeImpl was constructed with an unpaired `new`, causing a memory leak. Using a smart pointer guarantees that the memory will be freed at the end of application lifetime. Change-Id: Ib983d600cda082fa68e87c7d67130770acb78bef --- dali/devel-api/adaptor-framework/accessibility-bridge.h | 2 +- dali/internal/accessibility/bridge/bridge-impl.cpp | 10 +++++----- dali/internal/accessibility/bridge/dummy-atspi.cpp | 2 +- dali/internal/accessibility/bridge/dummy-atspi.h | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dali/devel-api/adaptor-framework/accessibility-bridge.h b/dali/devel-api/adaptor-framework/accessibility-bridge.h index 90f9fb5..1ef28d0 100644 --- a/dali/devel-api/adaptor-framework/accessibility-bridge.h +++ b/dali/devel-api/adaptor-framework/accessibility-bridge.h @@ -353,7 +353,7 @@ struct DALI_ADAPTOR_API Bridge * * @return The current bridge object **/ - static Bridge* GetCurrentBridge(); + static std::shared_ptr GetCurrentBridge(); /** * @brief Blocks auto-initialization of AT-SPI bridge diff --git a/dali/internal/accessibility/bridge/bridge-impl.cpp b/dali/internal/accessibility/bridge/bridge-impl.cpp index 116e703..1a7ca8b 100644 --- a/dali/internal/accessibility/bridge/bridge-impl.cpp +++ b/dali/internal/accessibility/bridge/bridge-impl.cpp @@ -665,7 +665,7 @@ bool INITIALIZED_BRIDGE = false; * @return The BridgeImpl instance * @note This method is to check environment variable first. If ATSPI is disable using env, it returns dummy bridge instance. */ -Bridge* CreateBridge() +std::shared_ptr CreateBridge() { INITIALIZED_BRIDGE = true; @@ -678,7 +678,7 @@ Bridge* CreateBridge() return Dali::Accessibility::DummyBridge::GetInstance(); } - return new BridgeImpl; + return std::make_shared(); } catch(const std::exception&) { @@ -691,9 +691,9 @@ Bridge* CreateBridge() // Dali::Accessibility::Bridge class implementation -Bridge* Bridge::GetCurrentBridge() +std::shared_ptr Bridge::GetCurrentBridge() { - static Bridge* bridge; + static std::shared_ptr bridge; if(bridge) { @@ -741,7 +741,7 @@ void Bridge::EnableAutoInit() auto accessible = Accessibility::Accessible::Get(rootLayer, true); - auto* bridge = Bridge::GetCurrentBridge(); + auto bridge = Bridge::GetCurrentBridge(); bridge->AddTopLevelWindow(accessible); bridge->SetApplicationName(applicationName); bridge->Initialize(); diff --git a/dali/internal/accessibility/bridge/dummy-atspi.cpp b/dali/internal/accessibility/bridge/dummy-atspi.cpp index a518df9..4fd124b 100644 --- a/dali/internal/accessibility/bridge/dummy-atspi.cpp +++ b/dali/internal/accessibility/bridge/dummy-atspi.cpp @@ -66,7 +66,7 @@ Accessibility::Accessible* Accessibility::Component::GetAccessibleAtPoint(Access return nullptr; } -Accessibility::Bridge* Accessibility::Bridge::GetCurrentBridge() +std::shared_ptr Accessibility::Bridge::GetCurrentBridge() { return Accessibility::DummyBridge::GetInstance(); } diff --git a/dali/internal/accessibility/bridge/dummy-atspi.h b/dali/internal/accessibility/bridge/dummy-atspi.h index 80079c1..81b287d 100644 --- a/dali/internal/accessibility/bridge/dummy-atspi.h +++ b/dali/internal/accessibility/bridge/dummy-atspi.h @@ -25,11 +25,11 @@ namespace Dali::Accessibility { struct DummyBridge : Dali::Accessibility::Bridge { - static DummyBridge* GetInstance() + static std::shared_ptr GetInstance() { - static DummyBridge instance; + static auto instance = std::make_shared(); - return &instance; + return instance; } const std::string& GetBusName() const override -- 2.7.4