Pārlūkot izejas kodu

[cpp] Change traversal order of Json::~Json(). Old order would grow stack much more than needed, leading to crashes when freeing big Json trees.

badlogic 5 gadi atpakaļ
vecāks
revīzija
9fabc60323
1 mainītis faili ar 17 papildinājumiem un 11 dzēšanām
  1. 17 11
      spine-cpp/spine-cpp/src/spine/Json.cpp

+ 17 - 11
spine-cpp/spine-cpp/src/spine/Json.cpp

@@ -114,17 +114,23 @@ Json::Json(const char *value) :
 }
 
 Json::~Json() {
-	delete _child;
-
-	if (_valueString) {
-		SpineExtension::free(_valueString, __FILE__, __LINE__);
-	}
-
-	if (_name) {
-		SpineExtension::free(_name, __FILE__, __LINE__);
-	}
-
-	delete _next;
+    spine::Json* curr = nullptr;
+    spine::Json* next = _child;
+    do {
+        curr = next;
+        if (curr) {
+            next = curr->_next;
+        }
+        delete curr;
+    } while(next);
+
+    if (_valueString) {
+        SpineExtension::free(_valueString, __FILE__, __LINE__);
+    }
+
+    if (_name) {
+        SpineExtension::free(_name, __FILE__, __LINE__);
+    }
 }
 
 const char *Json::skip(const char *inValue) {