<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 --- - False positive: malloced pointers wrapped in NSValues"
   href="http://llvm.org/bugs/show_bug.cgi?id=18262">18262</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive: malloced pointers wrapped in NSValues
          </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>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>razielim@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>This one's perhaps a bit mean - I'd be seriously impressed with the SA if it
saw through this. Anyway, there may be a way to fix it as an enhancement.

This is happening inside a subclass which is created at runtime, so we need to
store the memory pointer inside an associated object; new ivars are not
available.

- (void)createInstanceMutex {
    // Create the instance release mutex

    pthread_mutex_t * instanceMutex = calloc( sizeof( pthread_mutex_t ), 1 );
    pthread_mutex_init( instanceMutex, &mutexAttributes );

    // Hold an associated object with the mutex

    objc_setAssociatedObject( self, @selector( releaseLock ), [NSValue
valueWithPointer: instanceMutex], OBJC_ASSOCIATION_RETAIN_NONATOMIC );
}

then elsewhere:

- (void)destroyInstanceMutex {

    pthread_mutex_t * instanceMutex = [self releaseLock];
    if( NULL != instanceMutex )
    {
        pthread_mutex_destroy( instanceMutex );
        free( instanceMutex );
        objc_setAssociatedObject( self, @selector( releaseLock ), Nil,
OBJC_ASSOCIATION_ASSIGN );
    }
}

The SA warns that there is a potential leak of memory at the line:

objc_setAssociatedObject( self, @selector( releaseLock ), [NSValue
valueWithPointer: instanceMutex], OBJC_ASSOCIATION_RETAIN_NONATOMIC );

Presumably because that's the last reference to 'instanceMutex', but the SA
should perhaps suppress the warning if the pointer is being wrapped in an
NSValue and that NSValue kept referencable.

For extra credit, it could check if that NSValue is ever read and its pointer
value freed.</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>