[LLVMbugs] [Bug 11425] New: False "potential leak" positive in static analyzer with a typesafe cast function
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Nov 22 20:46:52 PST 2011
http://llvm.org/bugs/show_bug.cgi?id=11425
Bug #: 11425
Summary: False "potential leak" positive in static analyzer
with a typesafe cast function
Product: clang
Version: unspecified
Platform: PC
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: Static Analyzer
AssignedTo: kremenek at apple.com
ReportedBy: nicolasweber at gmx.de
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
$ cat test.mm
#import <Foundation/Foundation.h>
template<class T>
class scoped_nsobject {
public:
scoped_nsobject(T* t) : t_(t) {}
virtual ~scoped_nsobject() { [t_ release]; }
operator T*() { return t_; }
private:
T* t_;
};
#define CF_TO_NS_CAST_DEFN(TypeCF, TypeNS) \
\
TypeNS* CFToNSCast(TypeCF##Ref cf_val) { \
TypeNS* ns_val = \
const_cast<TypeNS*>(reinterpret_cast<const TypeNS*>(cf_val)); \
return ns_val; \
}
CF_TO_NS_CAST_DEFN(CFDictionary, NSDictionary);
int main() {
ProcessSerialNumber psn = { 0, kCurrentProcess };
scoped_nsobject<NSDictionary> process_info(
CFToNSCast(ProcessInformationCopyDictionary(&psn,
// works:
//(NSDictionary*)(ProcessInformationCopyDictionary(&psn,
kProcessDictionaryIncludeAllInformationMask)));
}
$ scan-build clang++ test.mm -framework Foundation -framework
ApplicationServices
scan-build: Using 'clang' from path:
/Users/test/src/chrome-git/src/third_party/llvm-build/Release+Asserts/bin/clang
test.mm:31:18: warning: Potential leak of an object allocated on line 31
CFToNSCast(ProcessInformationCopyDictionary(&psn,
^
1 warning generated.
scan-build: 1 bugs found.
With a c-style cast, the warning goes away.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list