[xml] xmlNewNode allocates memory that ist already in use



At the moment I am working on a  project which makes use of configuration
files that are saved as xml documents.
To read and handle this configuration files under borland c++ builder 4.0 I
have tried to use the libxml2.lib / libxml2.dll.
This worked well, as long as I used the quad word alignment to compile my
project.
Then following problem  occured: I had to compile my project with byte
alignment, and suddenly libxml2 didn't work any more.

Two solutions were offered to me: Either I set the alignemnt with #pragma
option -a1 to byte alignment before the relevant code passages or I build
a static library of libxml2 with byte alignment.

With the second solution a new problem occured which I want to describe
here:

Following two lines of code:

      temp2 = (xmlChar *)IntToStr(i_value).c_str();
      nodePtr3 = xmlNewTextChild(NodePtr3, NULL, (xmlChar *)"value",
temp2);

After the call of xmlNewTextChild there is just "0" in the part of memory
to which temp2 adresses.
I attached the fault to following lines in tree.c xmlNewNode(...)

      cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
      if (cur == NULL) {
            xmlGenericError(xmlGenericErrorContext, "xmlNewNode : malloc
failed\n");
            return(NULL);
      }
      memset(cur, 0, sizeof(xmlNode));

xmlMalloc allocates a part of memory to which temp2 also adresses.
When I compile the programm with these lines of code the fault doesn't
occur:

      String s = IntToStr(i_value);
      temp2 = (xmlChar *)s.c_str();
      nodePtr3 = xmlNewTextChild(NodePtr3, NULL, (xmlChar *)"value",
temp2);

Has anyone an idea how I can eliminate this fault?

Thanks
Thomas Kutzer





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]