Fixing Potential leaks found in CLANG

Discussion in 'iPhone/iPad Programming' started by midntdj, Oct 29, 2009.

  1. macrumors newbie

    Joined:
    Sep 23, 2009
    #1
    I just started to use CLANG to help find any leaks with in my code. I have a some code that CLANG shows a potential leak, but I'm not sure what I need to do to resolve it. Any help would be greatly appreciated (assuming there is something wrong with how I implemented the audio).

    I'm not sure that this is truly a leak or just a warning that CLANG doesn't like. In either case, I want to clean up my code so there are no warnings or potential leaks.

    Here is the code that has the potential leak (baseURL is what CLANG is complaining about):
    Code:
    
    	id sndpath = [[NSBundle mainBundle] pathForResource:@"Select" ofType:@"caf" inDirectory:@"/"];
    	CFURLRef baseURL = (CFURLRef)[[NSURL alloc] initFileURLWithPath:sndpath];
    
    	AudioServicesCreateSystemSoundID (baseURL, &btnTouchID);
    
    
    This is called in my viewDidLoad routine to set up the sound when a button is touched.

    In te dealloc routine I do dispose of the btnTouchID.

    Is there a better way to define your SoundID?

    Thanks.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You're creating baseURL but not releasing it in that method, which is why Clang is complaining. Either release it manually, autorelease it, or use the autorelease convenience method instead:

    Code:
    CFURLRef baseURL = (CFURLRef)[NSURL fileURLWithPath:sndpath];
     
  3. thread starter macrumors newbie

    Joined:
    Sep 23, 2009
    #3
    Thanks kainjow for your help. The autorelease convenience method you listed, corrected the CLANG warning. I had tried earlier to manually releasing the method, but CLANG still gave me the warning.

    By changing the intifileURLWithPath to use fileURLWithPath seems to be the better solution.

    Thank you again.
     

Share This Page