Do not call malloc during terminate 73/306873/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 28 Feb 2024 12:51:32 +0000 (21:51 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Mon, 4 Mar 2024 04:51:51 +0000 (04:51 +0000)
There was some strange crash issue during application terminate.

That crash comes at malloc.c during destruct JsonParser.

So, let we just remove some potential of mallocate memory during terminate,
what might not neccessary.

Change-Id: I93dc70b0c069f90a94e526f7916f9c54e1565a7f
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/builder/tree-node-manipulator.cpp
dali-toolkit/internal/builder/tree-node-manipulator.h

index 3f7e73e..aa23c76 100644 (file)
@@ -162,17 +162,9 @@ void TreeNodeManipulator::RemoveChildren()
 {
   DALI_ASSERT_DEBUG(mNode && "Operation on NULL JSON node");
 
-  CollectNodes collector;
+  DeleteNodesWithoutSelf otherDeletor(mNode);
 
-  DepthFirst(mNode, collector);
-
-  for(CollectNodes::iterator iter = collector.nodes.begin(); iter != collector.nodes.end(); ++iter)
-  {
-    if(*iter != mNode)
-    {
-      delete *iter;
-    }
-  }
+  DepthFirst(mNode, otherDeletor);
 
   mNode->mFirstChild = NULL;
   mNode->mLastChild  = NULL;
index 0852497..f881f58 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCRIPT_TREE_NODE_MANIPULATOR_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -215,6 +215,29 @@ struct CollectNodes
 };
 
 /*
+ * Delete nodes immediately, instead of self
+ */
+struct DeleteNodesWithoutSelf
+{
+  DeleteNodesWithoutSelf(TreeNode* self)
+  : mSelf(self){};
+
+  /*
+   * Call operator to add nodes to the list
+   */
+  void operator()(TreeNode*& n)
+  {
+    DALI_ASSERT_DEBUG(n && "Operation on NULL JSON node");
+    if(mSelf != n)
+    {
+      delete n;
+    }
+  }
+
+  const TreeNode* mSelf; ///< self node what we should not remove.
+};
+
+/*
  * Depth first walk of nodes applying given operation (unary_function)
  */
 template<typename Operation>