зеркало из https://github.com/microsoft/clang-1.git
[analyzer] Leaks should be uniqued by the allocation point in the
closest function context (RetainCountChecker). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151661 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
c5685438df
Коммит
e7e0168f62
|
@ -2114,14 +2114,16 @@ namespace {
|
|||
};
|
||||
}
|
||||
|
||||
// Find the first node in the current function context that referred to the
|
||||
// tracked symbol and the memory location that value was stored to. Note, the
|
||||
// value is only reported if the allocation occurred in the same function as
|
||||
// the leak.
|
||||
static std::pair<const ExplodedNode*,const MemRegion*>
|
||||
GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N,
|
||||
SymbolRef Sym) {
|
||||
|
||||
// Find both first node that referred to the tracked symbol and the
|
||||
// memory location that value was store to.
|
||||
const ExplodedNode *Last = N;
|
||||
const MemRegion* FirstBinding = 0;
|
||||
const LocationContext *LeakContext = N->getLocationContext();
|
||||
|
||||
while (N) {
|
||||
ProgramStateRef St = N->getState();
|
||||
|
@ -2134,10 +2136,20 @@ GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N,
|
|||
StateMgr.iterBindings(St, FB);
|
||||
if (FB) FirstBinding = FB.getRegion();
|
||||
|
||||
Last = N;
|
||||
// Allocation node, is the last node in the current context in which the
|
||||
// symbol was tracked.
|
||||
if (N->getLocationContext() == LeakContext)
|
||||
Last = N;
|
||||
|
||||
N = N->pred_empty() ? NULL : *(N->pred_begin());
|
||||
}
|
||||
|
||||
// If allocation happened in a function different from the leak node context,
|
||||
// do not report the binding.
|
||||
if (N->getLocationContext() != LeakContext) {
|
||||
FirstBinding = 0;
|
||||
}
|
||||
|
||||
return std::make_pair(Last, FirstBinding);
|
||||
}
|
||||
|
||||
|
|
|
@ -253,6 +253,19 @@ extern CGColorSpaceRef CGColorSpaceCreateDeviceRGB(void);
|
|||
+ (id)array;
|
||||
@end
|
||||
|
||||
enum {
|
||||
NSASCIIStringEncoding = 1,
|
||||
NSNEXTSTEPStringEncoding = 2,
|
||||
NSJapaneseEUCStringEncoding = 3,
|
||||
NSUTF8StringEncoding = 4,
|
||||
NSISOLatin1StringEncoding = 5,
|
||||
NSSymbolStringEncoding = 6,
|
||||
NSNonLossyASCIIStringEncoding = 7,
|
||||
};
|
||||
typedef struct __CFString * CFMutableStringRef;
|
||||
typedef NSUInteger NSStringEncoding;
|
||||
|
||||
extern CFStringRef CFStringCreateWithCStringNoCopy(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding, CFAllocatorRef contentsDeallocator);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Test cases.
|
||||
|
@ -285,13 +298,19 @@ void test_neg() {
|
|||
// Test returning retained and not-retained values.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
id test_return_retained() {
|
||||
return [[NSString alloc] init]; // expected-warning {{leak}}
|
||||
// On return (intraprocedural), assume CF objects are leaked.
|
||||
CFStringRef test_return_ratained_CF(char *bytes) {
|
||||
CFStringRef str;
|
||||
return CFStringCreateWithCStringNoCopy(0, bytes, NSNEXTSTEPStringEncoding, 0); // expected-warning {{leak}}
|
||||
}
|
||||
|
||||
// On return (intraprocedural), assume NSObjects are not leaked.
|
||||
id test_return_retained_NS() {
|
||||
return [[NSString alloc] init]; // no-warning
|
||||
}
|
||||
|
||||
void test_test_return_retained() {
|
||||
id x = test_return_retained();
|
||||
id x = test_return_retained_NS(); // expected-warning {{leak}}
|
||||
[x retain];
|
||||
[x release];
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче