<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Leaked blocks with optimization when copied in a certain way"
   href="http://llvm.org/bugs/show_bug.cgi?id=15924">15924</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Leaked blocks with optimization when copied in a certain way
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spoon.reloaded@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>