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



Hi Csaba,

Thanks X 1000 man!
It worked by doing xmlStrDup()! But I am just wondering why it would not
crash when running on iOS 3.2 or older.

Thanks,
Chi Yin Luk
 
Warshaw Group 
540 Broadway, 4th floor 
New York, NY 10012
phone: 212.966.4056, x. 201
fax: 212.966.4017 
email: chiyinl warshawgroup com
http://www.warshawgroup.com

-----Original Message-----
From: Csaba Raduly [mailto:rcsaba gmail com] 
Sent: Thursday, October 14, 2010 3:28 AM
To: Chi Yin Luk
Cc: xml gnome org
Subject: Re: [xml] xmlFreeDoc() on iOS 4 - crashes

Hi,

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(doc);

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]