ylechelle / OpenUDID

[OpenUDID IS NOW DEPRECATED] Open source initiative for a universal and persistent UDID solution for iOS
OpenUDID.org
2.09k stars 435 forks source link

Memory leak in valueWithError method #34

Open orarbel opened 12 years ago

orarbel commented 12 years ago

NSString * guuid = [(NSString ) [defaults objectForKey:kAppGUUID] retain]; if(guuid == nil) { //generate a new uuid and store it in user defaults CFUUIDRef uuid = CFUUIDCreate(NULL); guuid = (NSString ) CFUUIDCreateString(NULL, uuid); CFRelease(uuid); }

if guuid was nil and created within the if block, it is never released

gurre commented 12 years ago

I can confirm this bug. Instruments output:

Address Category Event Type RefCt Timestamp Size Responsible Library Responsible Caller 0x2a78b0 Malloc 128 Bytes Malloc 1 00:04.481.486 128 libsystem_c.dylib vasprintf_l 0x2a78b0 Malloc 128 Bytes Free 0 00:04.486.926 -128 Foundation NSLogv 0x2a78b0 CFString (store) Malloc 1 00:04.488.444 64 TheApp +[OpenUDID valueWithError:]

postmechanical commented 11 years ago

Just ran into Instruments reporting this leak as well which is odd since I'm using the version with the following:

NSString * appUID = (NSString *) [defaults objectForKey:kOpenUDIDAppUIDKey];
if(appUID == nil)
{
  // generate a new uuid and store it in user defaults
  CFUUIDRef uuid = CFUUIDCreate(NULL);
  appUID = (NSString *) CFUUIDCreateString(NULL, uuid);
  CFRelease(uuid);
}
orarbel commented 11 years ago

why is it weird? it's the same code as i reported that leaks

yizhaorong commented 8 years ago

NSString * appUID = (NSString *) [defaults objectForKey:kOpenUDIDAppUIDKey]; if(appUID == nil) { // generate a new uuid and store it in user defaults CFUUIDRef uuid = CFUUIDCreate(NULL); appUID = (CFBridgingRelease(CFUUIDCreateString(NULL, uuid))); CFRelease(uuid); }