<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 warning: Use of memory after it is freed (use of pointer, not memory)"
   href="http://llvm.org/bugs/show_bug.cgi?id=16499">16499</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive warning: Use of memory after it is freed (use of pointer, not memory)
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>ruslan_baratov@yahoo.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>Clang static analyzer give false warning that memory used after it is freed.
Warning is bogus because only pointer value is used, but not memory it points
to.

Example:
<span class="quote">>cat test.cpp </span >
#include <iostream> // std::cout
#include <stdlib.h> // malloc

void f() {
  char *buffer = (char *)malloc(10);
  free(buffer);
  std::cout << (void *)buffer << std::endl;
      // OK, memory freed, but only pointer value needed
}

<span class="quote">>clang++ --analyze test.cpp </span >
test.cpp:7:3: warning: Use of memory after it is freed
  std::cout << (void *)buffer << std::endl;
  ^            ~~~~~~~~~~~~~~
1 warning generated.

This is simplified version of warning that can be found in libc++ sources 
libcxx/src/debug.cpp, '__libcpp_db::__erase_i' method.

Environment:
<span class="quote">>clang++ --version</span >
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

<span class="quote">>uname -a</span >
Darwin mac-osx-x64 11.4.2 Darwin Kernel Version 11.4.2 ...</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>