Re: [xml] xmlFreeDoc() on iOS 4 - crashes


On Wed, Oct 13, 2010 at 9:54 PM, Chi Yin Luk  wrote:
I am using libxml2.2.7.3.dylib on my iPhone application.

The application is targeting iOS 3.2, but the xmlFreeDoc() fails when the
application is running on iPhone 4, but not on iOS 3.2 or before.

I also tried targeting iOS 4 and running on iPhone 4, same problem exist.

The problem is if I assign the encocoding of xmlDocPtr , then call
xmlFreeDoc to free the xmlDocPtr, it crashes with message:

“pointer being freed was not allocated”

The snippet of code as follow:

xmlDocPtr doc;
doc = xmlNewDoc((cost xmlChar*)XML_DEFAULT_VERSION);
doc->encoding =”utf-8”;

xmlFreeDoc does a xmlFree on doc->encoding, but you set it to a string
which was not dynamically allocated. In effect, you are calling
xmlFree on the "utf-8" string literal. This is wrong. You need to do
at least this:

doc->encoding = xmlStrDup("utf-8");

GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ L w++$ tv+ b++ DI D++ 5++
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

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