Browse Source

fix memory errors in XML Editor and UIML View parsing

Kolja Strohm 1 year ago
parent
commit
eec14de20d
3 changed files with 28 additions and 23 deletions
  1. 13 13
      JSON.cpp
  2. 14 9
      UIMLView.cpp
  3. 1 1
      XML.cpp

+ 13 - 13
JSON.cpp

@@ -1362,11 +1362,11 @@ JSONValidationResult* JSONValidator::validate(
                 }
                 else
                 {
+                    XML::Editor tmp = zConstraints->selectChildsByAttribute(
+                        "name", i.val());
                     JSONValidationResult* res = validateMultipleTypes(
                         zValue->asObject()->zValue(i.val()),
-                        zConstraints->selectChildsByAttribute("name", i.val())
-                            .begin()
-                            .val(),
+                        tmp.begin().val(),
                         p);
                     if (!res->isValid())
                     {
@@ -1384,6 +1384,7 @@ JSONValidationResult* JSONValidator::validate(
                 if (!zValue->asObject()->hasValue(
                         constraint->getAttributeValue("name")))
                 {
+                    XML::Editor tmp = constraint->selectChildren();
                     Text p = path;
                     p += ".";
                     p += constraint->getAttributeValue("name");
@@ -1392,17 +1393,13 @@ JSONValidationResult* JSONValidator::validate(
                             dynamic_cast<JSONValue*>(zValue->getThis()),
                             dynamic_cast<XML::Element*>(
                                 zConstraints->getThis()),
-                            new JSONMissingOneOf(
-                                p, constraint->selectChildren()));
+                            new JSONMissingOneOf(p, tmp));
                     return new JSONTypeMissmatch(path,
                         dynamic_cast<JSONValue*>(zValue->getThis()),
                         dynamic_cast<XML::Element*>(zConstraints->getThis()),
                         new JSONMissingValue(p,
                             dynamic_cast<XML::Element*>(
-                                constraint->selectChildren()
-                                    .begin()
-                                    .val()
-                                    ->getThis())));
+                                tmp.begin()->getThis())));
                 }
             }
         }
@@ -1418,9 +1415,12 @@ JSONValidationResult* JSONValidator::validateMultipleTypes(
     Text childPath) const
 {
     if (zPossibleChildConstraints->getChildCount() == 1)
+    {
+        XML::Editor children = zPossibleChildConstraints->selectChildren();
         return validate(zChildValue,
-            zPossibleChildConstraints->selectChildren().begin().val(),
+            children.begin().val(),
             childPath); // only one type is possible
+    }
     bool hasTypeAttr = 0;
     RCArray<XML::Element> possibleConstraints;
     if (zPossibleChildConstraints->hasAttribute("typeSpecifiedBy"))
@@ -1437,10 +1437,10 @@ JSONValidationResult* JSONValidator::validateMultipleTypes(
                     zPossibleChildConstraints->selectChildsByName("object")
                         .whereChildWithAttributeExists("name", typeAttr))
                 {
+                    XML::Editor nameChildren
+                        = constraint->selectChildsByAttribute("name", typeAttr);
                     XML::Element* typeAttrContraints
-                        = constraint->selectChildsByAttribute("name", typeAttr)
-                              .begin()
-                              .val();
+                        = nameChildren.begin().val();
                     JSONValidationResult* res = validateMultipleTypes(
                         typeV, typeAttrContraints, childPath + "." + typeAttr);
                     if (res->isValid())

+ 14 - 9
UIMLView.cpp

@@ -494,10 +494,7 @@ Zeichnung* UIMLTable::parseElement(
                 Zeichnung* z
                     = generalFactory.parseElement(*i.val(), generalFactory);
                 if (t->getSpaltenAnzahl() < c) t->addSpalte(Text(c - 1));
-                if (z)
-                    t->setZeichnungZ(Text(c - 1),
-                        line,
-                        dynamic_cast<Zeichnung*>(z->getThis()));
+                if (z) t->setZeichnungZ(Text(c - 1), line, z);
                 c++;
             }
         }
@@ -555,7 +552,7 @@ Zeichnung* UIMLFrame::parseElement(
     for (auto i = element.getChilds(); i; i++)
     {
         Zeichnung* z = generalFactory.parseElement(*i.val(), generalFactory);
-        if (z) f->addMember(dynamic_cast<Zeichnung*>(z->getThis()));
+        if (z) f->addMember(z);
     }
     return f;
 }
@@ -700,7 +697,8 @@ void UIMLView::setUIML(XML::Element* uiml)
     {
         for (auto i = dom->getChilds(); i; i++)
         {
-            parseElement(*i.val(), *this);
+            Zeichnung* z = parseElement(*i.val(), *this);
+            if (z) z->release();
         }
     }
 }
@@ -754,7 +752,12 @@ void UIMLView::layout()
 Text UIMLView::addMember(Text uiml)
 {
     XML::Element* e = new XML::Element(uiml);
-    if (parseElement(*e, *this)) dom->addChildAtFront(e);
+    Zeichnung* z = parseElement(*e, *this);
+    if (z)
+    {
+        dom->addChildAtFront(e);
+        z->release();
+    }
     return e->getAttributeValue("id");
 }
 
@@ -778,7 +781,7 @@ Text UIMLView::addMember(Text uiml, Text parentId)
                 {
                     dynamic_cast<Fenster*>(
                         members->z(parentId, parentId.getLength()))
-                        ->addMember(dynamic_cast<Zeichnung*>(z->getThis()));
+                        ->addMember(z);
                     ed2.begin()->addChild(e);
                 }
                 return e->getAttributeValue("id");
@@ -965,7 +968,9 @@ Zeichnung* UIMLView::parseElement(
                 break;
             }
         }
-        if (z) members->set(id, id.getLength(), z);
+        if (z)
+            members->set(
+                id, id.getLength(), dynamic_cast<Zeichnung*>(z->getThis()));
     }
     else
         z->getThis();

+ 1 - 1
XML.cpp

@@ -661,7 +661,7 @@ Editor Editor::selectChildren() const
     RCArray<Element>* list = new RCArray<Element>();
     for (auto i : *elements)
     {
-        for (auto j = i->selectChildren().begin(); j; j++)
+        for (Element* j : i->selectChildren())
         {
             list->add(dynamic_cast<XML::Element*>(j->getThis()));
         }