title: How can I fix this clang warning: "Object with +0 retain counts returned to caller where +1 (owning) retain count is expected"?
body: <p>I have a piece of Objective-C code that looks like the following:</p>
  
  <pre><code>- (NSString *)copyData:(NSData *)data
  {
      NSString *path = [[[self outputDirectory] stringByAppendingPathComponent:@"archive"] stringByAppendingPathExtension:@"zip"];
      NSLog(@"Copying data to %@", path);
      [data writeToFile:path atomically:NO];
      return path;
  }
  </code></pre>
  
  <p>The code is called from an initializer that looks like this:</p>
  
  <pre><code>- (id)initWithData:(NSData *)data
  {
      if ((self = [super init]) != nil) {
          NSString *path = [self copyData:data];        // Line 41 (referenced in warning, shown below)
          return [self initWithContentsOfFile:path];
      }
      return self;
  }
  </code></pre>
  
  <p>When running the clang static analyzer, I get the following warnings for the <code>path</code> variable:</p>
  
  <blockquote>
    <p>Potential leak of an object allocated on line 41 and stored into 'path'</p>
    
    <p>Object with +0 retain counts returned to caller where +1 (owning) retain count is expected</p>
  </blockquote>
  
  <p>I'm confused. My understanding is that <code>stringByAppendingPathComponent</code> should return an autoreleased string, so it <em>should</em> have a net retain count of 0. (Obviously I don't <em>want</em> to retain it.)</p>
  
  <p>I've tried altering <code>copyData:</code> to return the following, but it didn't get rid of the warning:</p>
  
  <pre><code>return [[path retain] autorelease];
  </code></pre>
  
  <p>So what's the deal with this warning?</p>