[LLVMbugs] [Bug 16499] New: False positive warning: Use of memory after it is freed (use of pointer, not memory)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 30 13:24:55 PDT 2013


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

            Bug ID: 16499
           Summary: False positive warning: Use of memory after it is
                    freed (use of pointer, not memory)
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: ruslan_baratov at yahoo.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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:
>cat test.cpp 
#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
}

>clang++ --analyze test.cpp 
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:
>clang++ --version
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

>uname -a
Darwin mac-osx-x64 11.4.2 Darwin Kernel Version 11.4.2 ...

-- 
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/20130630/97459804/attachment.html>


More information about the llvm-bugs mailing list