Error EXC_BAD_ACCESS on NSXMLParser Release

I see intermittent collapse in [parser release]. I would say that I see it in about 5% of cases, and the data that I process varies between each failure. Why I can’t understand why.

Before I submit an Apple bug report (which, with luck, will not be reproducible in the sample code), can anyone come across this and find out what might happen?

    NSData *d = [data copy]; // data is typically 2K-13K bytes
    @synchronized (xmlParserLock) {
        [[NSURLCache sharedURLCache] setMemoryCapacity:0];
        [[NSURLCache sharedURLCache] setDiskCapacity:0];

        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSXMLParser *parser = [[NSXMLParser alloc] initWithData:d];
        [parser setDelegate:self];
        [parser setShouldProcessNamespaces:NO];
        [parser setShouldReportNamespacePrefixes:NO];
        [parser setShouldResolveExternalEntities:NO];
        [parser parse];
        [parser release];
        [pool release];
    }
    [d release];

And here is the output of gdb 'where', which points to [parser release]:

#0  0x93d08d12 in xmlCharEncCloseFunc ()
#1  0x93cfc0e3 in xmlFreeParserInputBuffer ()
#2  0x93cfc08f in xmlFreeInputStream ()
#3  0x93cfbdac in xmlFreeParserCtxt ()
#4  0x961384d6 in -[NSXMLParser dealloc] ()
#5  0x00149de7 in -[MyParserClass parseResponse] (self=0x104e9f0, _cmd=0x1766dc) at /Users/mike/Documents/MyApp/Classes/MyParserClass.m:60

Thanks in advance for your help!

+3
source share
4 answers

I think I realized this - some code elsewhere in the application uses XML functions such as:

xmlCtxtReadMemory()
xmlClearParserCtxt();
xmlFreeParserCtxt();
xmlCleanupParser();
xmlFreeDoc();

, , , , . NSXMLParser, , .

, , , NSXMLParser, , , . , , XML - !

+4

, . . . , , .

0

. , parserDidEndDocument: .

.

Thierry

0

You need to delete your data only after the parsing is complete. In the delegate method called parserDidEndDocument: release data.

I hope for this help.

Thierry

0
source

Source: https://habr.com/ru/post/1705432/


All Articles