I am using TBXML for XML feed parsing and instruments to detect memory leaks.
Instruments tells me there is a memory leak in function
- (TBXMLAttribute*) nextAvailableAttribute {
currentAttribute++;
if (!currentAttributeBuffer) {
currentAttributeBuffer = calloc(1, sizeof(TBXMLAttributeBuffer));
currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
currentAttribute = 0;
} else if (currentAttribute >= MAX_ATTRIBUTES) {
currentAttributeBuffer->next = calloc(1, sizeof(TBXMLAttributeBuffer));
currentAttributeBuffer->next->previous = currentAttributeBuffer;
currentAttributeBuffer = currentAttributeBuffer->next;
currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
currentAttribute = 0;
}
return ¤tAttributeBuffer->attributes[currentAttribute];
}
at the line
currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
Does any one solved it before?
BEWARE…. instruments is telling you WHERE the leaked memory was originally created, NOT that the issue is in that line… for instance, if you do something with the attribute returned and leak it elsewhere, instruments will show THE line above, where it was created, NOT where you leaked it….