[llvm-bugs] [Bug 38068] New: warning: Attempt to free released memory that can't be freed

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 5 07:18:32 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38068

            Bug ID: 38068
           Summary: warning: Attempt to free released memory that can't be
                    freed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: vcato1701 at yahoo.com
                CC: llvm-bugs at lists.llvm.org

The following code produces a warning 

class test {
  public:
    test()
    : allocated(new int),
      x(1)
    {
    }

    ~test()
    {
      if (x==0) {
        delete allocated;
      }
    }

    test f() const
    {
      test t1(*this);
      {
        test t2(*this);
      }
      return t1;
    }

  private:
    int *allocated;
    const int x;
};


<source>:12:9: warning: Attempt to free released memory

        delete allocated;

The analyzer believes that the memory will be released twice even though it can
 never be released even once.  The analyzer doesn't seem to recognize that a
const member that can only be initialized to 1 can never be 0.

-- 
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/20180705/d459a2c7/attachment.html>


More information about the llvm-bugs mailing list