AlanQuatermain/ParserExample — Issue #3: Chance of EXC_BAD_ACCESS
Author: 0x8badf00d
Created: 2012-01-30 19:23:30+00:00
State: open

In AQParser.m method static void __startElementNS if if ( (attributes[i+3] != NULL) && (attributes[i+4] != NULL) ) is not true then attrValue gets released, chance of EXC_BAD_ACCESS

NSString * attrValue = @""; // attrValue pointer points to string literal
if ( (attributes[i+3] != NULL) && (attributes[i+4] != NULL) )
{
NSUInteger length = attributes[i+4] - attributes[i+3];
attrValue = [[NSString alloc] initWithBytes: attributes[i+3] length: length encoding: NSUTF8StringEncoding]; // attrValue retain count +1
}

[attrDict setObject: attrValue forKey: attrQualified];
[attrLocalName release];
[attrQualified release];
[attrValue release];

// Updated code autoreleased attrValue object

NSString * attrValue = @""; // attrValue pointer points to string literal
if ( (attributes[i+3] != NULL) && (attributes[i+4] != NULL) )
{
NSUInteger length = attributes[i+4] - attributes[i+3];
attrValue = [[[NSString alloc] initWithBytes: attributes[i+3] length: length encoding: NSUTF8StringEncoding] autorelease]; // attrValue retain count +1
}

[attrDict setObject: attrValue forKey: attrQualified];
[attrLocalName release];
[attrQualified release];