[llvm-bugs] [Bug 33540] New: Analyzer reports seemingly trivially-false leak of memory

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 21 00:31:54 PDT 2017


            Bug ID: 33540
           Summary: Analyzer reports seemingly trivially-false leak of
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: george.burgess.iv at gmail.com
                CC: llvm-bugs at lists.llvm.org

Repro on trunk:

int *foo(unsigned long bar, bool baz) {
  int *i = reinterpret_cast<int *>(bar);
  if (!i)
    i = new int;
  if (baz)
    return i;
  if (!bar)
    delete i;
  return 0;

Command: $clang --analyze foo.cpp
foo.cpp:9:10: warning: Potential leak of memory pointed to by 'i'
  return 0;

If I change the `if (!i)` to `if (!bar)`, the warning disappears.

Warning does not disappear if I use `uintptr_t` instead of `unsigned long`.

Thank you!

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/20170621/0c4585aa/attachment.html>

More information about the llvm-bugs mailing list