Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeChild crashes in certain circumstances #143

Open
GoogleCodeExporter opened this issue Aug 4, 2015 · 1 comment
Open

removeChild crashes in certain circumstances #143

GoogleCodeExporter opened this issue Aug 4, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

This code sometimes (quite rarely but stable) crashes with EXC_BAD_ACCESS:

GDataXMLNode *child = [element.children objectAtIndex:0];
[element removeChild:child];

This happens because in removeChild: method, 'child' object gets deallocated 
(when [self releaseCachedValues] is called) before it's XMLNode is retrieved 
and removed from parent.

Initial method is:

- (void)removeChild:(GDataXMLNode *)child {
 // this is safe for attributes too
 if (xmlNode_ != NULL) {

   [self releaseCachedValues];  //<< here child refCount is set to 0 and sometimes it is removed instantly

   xmlNodePtr node = [child XMLNode];  //<< as child pointer is invalid, crash occurs here

   xmlUnlinkNode(node);

   // if the child node was borrowing its xmlNodePtr, then we need to
   // explicitly free it, since there is probably no owning object that will
   // free it on dealloc
   if (![child shouldFreeXMLNode]) {
     xmlFreeNode(node);
   }
 }
}

To avoid crash, the method should be modified as following:

- (void)removeChild:(GDataXMLNode *)child {
 // this is safe for attributes too
 if (xmlNode_ != NULL) {

   xmlNodePtr node = [child XMLNode];

   xmlUnlinkNode(node);

   // if the child node was borrowing its xmlNodePtr, then we need to
   // explicitly free it, since there is probably no owning object that will
   // free it on dealloc
   if (![child shouldFreeXMLNode]) {
     xmlFreeNode(node);
   }

   [self releaseCachedValues];   //<< we release child collection after we finished accessing 'child'
 }
}

Original issue reported on code.google.com by [email protected] on 6 Jun 2012 at 1:44

@GoogleCodeExporter
Copy link
Author

this isn't work for me thx for the search

Original comment by [email protected] on 28 Jan 2014 at 3:30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant