Add missing exception handling 39/292939/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 May 2023 08:22:11 +0000 (08:22 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 May 2023 08:22:11 +0000 (08:22 +0000)
The bundle_dup() should not throw an exception. This patch adds
a missing exception handling.

Change-Id: I2131f7b29950805fa99de29c665f2adf7db9a73e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/stub.cc

index 9f555b6..7d8b84f 100644 (file)
@@ -298,9 +298,14 @@ extern "C" EXPORT_API bundle* bundle_dup(bundle* b_from) {
     return nullptr;
   }
 
-  auto* h = reinterpret_cast<Bundle*>(b_from);
-  auto* b = new (std::nothrow) Bundle(*h);
-  if (b == nullptr) {
+  Bundle* b;
+  try {
+    auto* h = reinterpret_cast<Bundle*>(b_from);
+    b = new Bundle(*h);
+  } catch (const Exception& e) {
+    set_last_result(e.GetErrorCode());
+    return nullptr;
+  } catch (const std::bad_alloc& e) {
     set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
     return nullptr;
   }