Comments (4)
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.
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.
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.
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)
- hello, i'm replacing your "placement new" with my old new, can you tell me if the code is safe? HOT 1
- LFS64 removal on musl-1.2.4
- Question: parsing a xml string back into an XMLDocument HOT 1
- CMake targets are not exported? HOT 1
- CMake install question HOT 2
- Converting CString to UTF-8 for saving to TinyXML2 HOT 1
- Problems occur when building a project
- XMLPrinter printer( fp ) not recognised on arduino ide compiler HOT 2
- Why return XML_ ERROR_ PARSING? HOT 2
- Documentation error? HOT 2
- Turkish Characters Support HOT 1
- When will tinyxml release a new version? HOT 1
- Assessment of the difficulty in porting CPU architecture for tinyXML2 HOT 1
- Support for char8_t and std::u8string HOT 2
- Using IntText(); HOT 1
- FirstChildElement and namespace prefixes.
- Bug with XMLElement::Attribute - it returns 0 instead of "value" if it can't find the attribute -
- Is the Doxygen tagfile published anywhere?
- v10: MinGW DLL build behavior change
- porty guide from tinyxml1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyxml2.