Memory leak in - (MPURLRequestParameter *)oauthNonceParameter, MPOAuthCredentialConcreteStore

24 views
Skip to first unread message

Giullo

unread,
Mar 26, 2009, 6:04:41 AM3/26/09
to OAuth Objective-C
Hi,
i downloaded the library for an upcoming iphone app which needs to
interact with an OAuth service. I've noticed that there's a memory
leakage in this method

- (MPURLRequestParameter *)oauthNonceParameter {
MPURLRequestParameter *aRequestParameter = [[MPURLRequestParameter
alloc] init];
aRequestParameter.name = @"oauth_nonce";

NSString *generatedNonce = nil;
CFUUIDRef generatedUUID = CFUUIDCreate(kCFAllocatorDefault);
generatedNonce = (NSString *)CFUUIDCreateString(kCFAllocatorDefault,
generatedUUID);

CFRelease(generatedUUID);

aRequestParameter.value = generatedNonce;

return [aRequestParameter autorelease];
}

each time i fire a method request there's a 64byte string leaked from
this method.

i tried to change the method to something like this:

- (MPURLRequestParameter *)oauthNonceParameter {
MPURLRequestParameter *aRequestParameter = [[MPURLRequestParameter
alloc] init];
aRequestParameter.name = @"oauth_nonce";

//NSString *generatedNonce = nil;
CFUUIDRef generatedUUID = CFUUIDCreate(kCFAllocatorDefault);
//generatedNonce = (NSString *)CFUUIDCreateString
(kCFAllocatorDefault, generatedUUID);
CFStringRef tmpCString = CFUUIDCreateString(kCFAllocatorDefault,
generatedUUID);
NSString *generatedNonce = [NSString stringWithString:tmpCString];
CFRelease(tmpCString);
CFRelease(generatedUUID);

aRequestParameter.value = generatedNonce;

return [aRequestParameter autorelease];
}

and i cut the leakage in half (32 bytes on each call), but its still
present :(

any idea how to solve this?

regards, giuliano

Karl Adam

unread,
Mar 26, 2009, 6:32:20 AM3/26/09
to oauth-ob...@googlegroups.com
You're correct that the string returned by CFUUIDCreateString() was
being leaked, however that's the only leak in this function, and your
change to it would effectively cause the library to stop creating
valid oauth method requests since you've removed the nonce parameter's
value. I went ahead and double checked for any other remaining leaks
by using clang. I've found zero other leaks in the current repository
code(r107), however there is an OS level leak when you perform
synchronous URL requests, so if you're doing that then you'll see that
leak. It's suggested that you always use synchronous network I/O
regardless though so as not to block the UI on slow networks.

_Karl

Karl Adam

unread,
Mar 26, 2009, 6:42:22 AM3/26/09
to oauth-ob...@googlegroups.com
Actually, no, you'll still be able to create proper nonce parameters
with your change, but the rest still holds in regards to synchronous
url requests which are likely the source of your leaks. Have you tried
using Instruments to locate the original source of your leaks?

_Karl

Giullo

unread,
Mar 26, 2009, 6:42:42 AM3/26/09
to OAuth Objective-C
hi karl,
thanks for the fast reply :)
i dont' understand why you say that my changes would change the
function behaviour:

i've checked the MPURLRequestParameter class and noticed the the value
property has copy in declaration, so in theory the string value should
be correctly copied, regardles of how it was obtained (hope this make
sense to you, english is not my first language :))

anyway, ill ignore the leak for now and go ahead with the app
development

regards, giuliano

Giullo

unread,
Mar 26, 2009, 6:44:49 AM3/26/09
to OAuth Objective-C
you beat me on the reply :)

instruments signals leaks in the c++ stl library with my changes made
to the method .. it will be a generic 32bytes block or either a
NSCFString

Karl Adam

unread,
Mar 26, 2009, 6:49:26 AM3/26/09
to oauth-ob...@googlegroups.com
What C++ STL Library? If there is a leak C++ library code that would
suggest the CFUUID library has a leak. I'll investigate further and
try to reproduce this. Are you observing this behavior on Mac OS X or
iPhone?

_Karl

Giullo

unread,
Mar 26, 2009, 6:54:13 AM3/26/09
to OAuth Objective-C
libstdc++.6.dylib std::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_Rep::_S_create(unsigned long, unsigned long,
std::allocator<char> const&)

this is one the entries instruments signals me. im testing on the
iphone simulator, not the actual device

regards, giuliano

ps: i there a way to attach an image to the post other the linking the
image to imageshack or similar?

Giullo

unread,
Mar 26, 2009, 6:55:10 AM3/26/09
to OAuth Objective-C
another one is

std::_Rb_tree<void*, void*, std::_Identity<void*>, std::less<void*>,
std::allocator<void*> >::_M_create_node(void* const&)

Reply all
Reply to author
Forward
0 new messages