Code Monkey home page Code Monkey logo

Comments (4)

leethomason avatar leethomason commented on August 16, 2024

The code, as sent, crashes because of this:

    XMLNode* settings = xmlDoc->FirstChildElement("s");

The root element of the xmlDoc is "settings" not "s". I'm not sure why you see the assertion crash and not this; if the test isn't correct, I'd appreciate an update. Here's the test code I'm using:

    {
        const char* xml = "<settings>"
                                "<entry name=\"stringvalue\" type=\"s\" value=\"version1 string\" />"
                                "<entry name=\"intvalue\" type=\"i\" value=\"125\" />"
                                "<entry name=\"floatvalue\" type=\"f\" value=\"3.1415\" />"
                            "</settings>";
        XMLDocument *xmlDoc = new XMLDocument();

        //xmlDoc->LoadFile("config1.cfg");
        xmlDoc->Parse( xml );
        xmlDoc->Print();

        XMLNode* settings = xmlDoc->FirstChildElement("s");

        const char *versionString = settings->ToElement()->Attribute("version");
        printf("version: %s", versionString ? versionString : "");

        delete xmlDoc; // crashes here - XMLDocument destructor

    }

from tinyxml2.

dandee avatar dandee commented on August 16, 2024

Thanks Lee for the quick answer. It turns out that my example code was incorrect because I was focusing on the wrong place. Here's the one that triggers the issue:

#include "tinyxml2.h"
using namespace tinyxml2;

int main()
{
    {
        XMLDocument xmlDoc;

        xmlDoc.NewDeclaration();
        xmlDoc.NewComment("teasing you");
    } // <-- assert happens here...

    return 0;
}

I know that this code is grammatically incorrect (creation of a new elements without using them i.e. Declaration and Comment elements created but not added somewhere) but this should pass anyway (i.e. I can create any number of Declarations without using them in the document).

from tinyxml2.

leethomason avatar leethomason commented on August 16, 2024

The bug is non-destructive: what happens is that the nodes aren't added to
the tree, and the assert is firing because they haven't been deleted by a
walk of the tree.

The good news: The memory will get cleaned up. The "crash" is a mis-firing
assert, as you noted.
The annoying part: The assert isn't correct. I don't want to lose the
assert on an actual memory leak, but this isn't one.

Working on a fix.

lee

On Mon, Oct 22, 2012 at 12:55 PM, Daniel Kolakowski <
[email protected]> wrote:

Thanks Lee for the quick response. My code was incorrect to reproduce the
core of the issue. Here's the one to do it:
#include "tinyxml2.h"
using namespace tinyxml2;

int main()
{
{
XMLDocument xmlDoc;

xmlDoc.NewDeclaration();
xmlDoc.NewComment("Configuration file");

XMLElement *root = xmlDoc.NewElement("settings");
root->SetAttribute("version", 2);

}

return 0;

}


Reply to this email directly or view it on GitHubhttps://github.com//issues/75#issuecomment-9678068.

from tinyxml2.

leethomason avatar leethomason commented on August 16, 2024

Just checked in what I hope is a fix. (It's more delicate code than I would like.) If you allocate memory you don't use, but which will get cleaned up, it should no longer assert.

from tinyxml2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.