views:

278

answers:

2

Further to this question I've fixed a bunch of memory leaks in BEncoding.m (originally from here)

I've fixed all the obvious memory leaks, but Clang has found four "Leak of returned object" bugs, which I'm not sure how to sort:

The full messages/appropriate bits of code are:

NSMutableData *data = [[NSMutableData alloc] init];

[1] Method returns an Objective-C object with a +1 retain count (owning reference)

[...]
snprintf(buffer, 32, "%lu:", [object length]);
[data appendBytes:buffer length:strlen(buffer)];
[data appendData:object];
return data;

[3] Object returned to caller as an owning reference (single retain count transferred to caller)

+1  A: 

It sounds like the objects aren't being properly autoreleased before they're returned, which violates the Objective-C memory management conventions.

Chuck
+3  A: 

you want:

return [data autorelease];

since you're handing it to the caller.

Nick Brosnahan