[LLVMbugs] [Bug 15715] New: False positive in interprocedural analysis of C++ destructors

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Apr 10 02:26:40 PDT 2013


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

            Bug ID: 15715
           Summary: False positive in interprocedural analysis of C++
                    destructors
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: timac at timac.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 10331
  --> http://llvm.org/bugs/attachment.cgi?id=10331&action=edit
Xcode project

The Clang Static Analyzer (checker-273 and Xcode 4.6.1) reports a memory leak
for the following source code.

Steps to reproduce:
1- On 10.8.3 with Xcode 4.6.1, create a new CoreFoundation project with ARC
disabled.
2- Download the attached Xcode project or replace the main.c with a main.cpp
containing the following:


#include <CoreFoundation/CoreFoundation.h>

//
// MyCFString is a wrapper around CFStringRef.
//
class MyCFString
{
public:
    static CFStringRef EmptyCFString()
    {
        static CFStringRef kEmptyCFString = CFSTR("Empty");
        return kEmptyCFString;
    }

    MyCFString()
    {
        mRef = CFStringRef(CFRetain(EmptyCFString()));
    }

    ~MyCFString()
    {
        if(mRef != NULL)
            CFRelease(mRef);
    }

    // Adopt doesn't retain the passed CFStringRef
    void Adopt(CFStringRef s)
    {
        if (s != mRef)
        {
            if(mRef != NULL)
                CFRelease(mRef);
            mRef = s;
        }
    }

private:
    CFStringRef mRef;
};


int main(int argc, const char * argv[])
{
    MyCFString theString;

    // Create a CFStringRef
    CFStringRef adoptedString = CFStringCreateCopy(kCFAllocatorDefault,
CFSTR("This is not a leak"));

    // adoptedString is not retained by Adopt() but the MyCFString destructor
will release adoptedString
    theString.Adopt(adoptedString);

    return 0;
}


3- Run scan-build /usr/bin/xcodebuild -project InterproceduralBug.xcodeproj
-target "InterproceduralBug" build

Result:
The Clang static analyzer reports a memory leak.

-- 
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/20130410/057c5814/attachment.html>


More information about the llvm-bugs mailing list