[LLVMbugs] [Bug 15924] New: Leaked blocks with optimization when copied in a certain way

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue May 7 00:41:48 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15924

            Bug ID: 15924
           Summary: Leaked blocks with optimization when copied in a
                    certain way
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: spoon.reloaded at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following simple code shows leaks when profiled with the Leaks instrument,
with the following configuration:
* Latest Xcode (4.6.2) with all updates
* Apple LLVM compiler
* ARC enabled
* Release build configuration
* "-Os" (Fastest, smallest) optimization
* iOS simulator
* various versions of simulator iOS were tried, all produced same result


- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  for (int i = 0; i < 10; i++) {
    void (^block)() = ^{
      NSLog(@"%d", i);
    };
    id x = block;
    [x copy];
  }

  return YES;
}


The Leaks instrument shows 10 leaked blocks. Turning off optimization will
cause it to not leak. The strange thing is, looking at the memory management
history for each of the leaked blocks, it looks like there's a malloc from the
copy, followed a release, which should normally deallocate it; but nevertheless
it still shows as leaked.

Also, this issue is very sensitive to the particular form of the code. For
example, changing the type of variable "x" from "id" to "void (^)()" will
eliminate the leak. Changing type of variable "block" from "void (^)()" to "id"
will also eliminate the leak.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130507/c240be8e/attachment.html>


More information about the llvm-bugs mailing list