Fix crash issues 55/307655/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 12 Mar 2024 06:15:06 +0000 (15:15 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 12 Mar 2024 06:15:06 +0000 (15:15 +0900)
If the context is default, tizen-core increases reference count of
default main context.

Change-Id: I3bfce046063dc6e013b1308f45526ff59c0d1b3d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
tizen_base/context.cc
tizen_base/context_manager.cc

index e0b3365cb1d67306e0cc3b886dbd23084493f4ed..a652d55eeeee1ea7f1e9e71ec3a65aa547bf5e45 100644 (file)
@@ -25,7 +25,10 @@ namespace tizen_core {
 
 Context::Context(std::string name, bool use_thread)
     : name_(std::move(name)),
-      handle_(use_thread ? g_main_context_new() : nullptr) {}
+      handle_(use_thread ? g_main_context_new() : nullptr) {
+  if (handle_ == nullptr)
+    handle_ = g_main_context_ref(g_main_context_default());
+}
 
 Context::~Context() {
   if (handle_ != nullptr)
index 10c57ebb2735f8d51a14f1f11cd9b56a09f49e09..c77bdb9837f6bdb868c0dccb57702a9170c83864 100644 (file)
@@ -68,6 +68,11 @@ std::shared_ptr<Context> ContextManager::Find(const std::string& name) {
 
 std::shared_ptr<Context> ContextManager::FindFromThisThread() {
   auto handle = g_main_context_get_thread_default();
+  if (handle == nullptr) {
+    _W("Use default context");
+    handle = g_main_context_default();
+  }
+
   std::lock_guard<std::recursive_mutex> lock(mutex_);
   for (const auto& iter : contexts_) {
     auto& context = iter.second;