]> granicus.if.org Git - clang/commitdiff
Fix crasher in CFRefCount.cpp reported by Nikita Zhuk due to recently added autorelea...
authorTed Kremenek <kremenek@apple.com>
Wed, 13 May 2009 07:12:33 +0000 (07:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 13 May 2009 07:12:33 +0000 (07:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71647 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp
test/Analysis/NSString.m

index fc6de6003219c5863f8f19cdc3db6b6d660ac975..c31a8cd53d9fe8346d8dae2e5581c0f9d0f6a9ea 100644 (file)
@@ -2154,6 +2154,9 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N,
                                             const ExplodedNode<GRState>* PrevN,
                                             BugReporterContext& BRC) {
   
+  if (!isa<PostStmt>(N->getLocation()))
+    return NULL;
+  
   // Check if the type state has changed.
   GRStateManager &StMgr = BRC.getStateManager();
   GRStateRef PrevSt(PrevN->getState(), StMgr);
@@ -2373,8 +2376,8 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N,
   
   if (os.str().empty())
     return 0; // We have nothing to say!
-  
-  Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();    
+
+  Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
   PathDiagnosticLocation Pos(S, BRC.getSourceManager());
   PathDiagnosticPiece* P = new PathDiagnosticEventPiece(Pos, os.str());
   
index d5a7870a99338aa0e6281165a65bc86a5815d9b8..44d0a5d962df67ff2458b95e3f70e26c402169a9 100644 (file)
@@ -183,6 +183,33 @@ void f13(void) {
   NSString *str = [[NSString alloc] init];
   return [str autorelease]; // no-warning
 }
+- (void)m1
+{
+ NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
+ [s retain];
+ [s autorelease];
+}
+- (void)m2
+{
+ NSString *s = [[[NSString alloc] init] autorelease]; // expected-warning{{leak}}
+ [s retain];
+}
+- (void)m3
+{
+ NSString *s = [[[NSString alloc] init] autorelease];
+ [s retain];
+ [s autorelease];
+}
+- (void)m4
+{
+ NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
+ [s retain];
+}
+- (void)m5
+{
+ NSString *s = [[NSString alloc] init];
+ [s autorelease];
+}
 @end
 
 @interface C1 : NSObject {}
@@ -298,8 +325,6 @@ void test_isTrackedObjectType(void) {
   return CFStringCreateWithFormat(kCFAllocatorDefault, ((void*)0), ((CFStringRef) __builtin___CFStringMakeConstantString ("" "%d" "")), 100); // expected-warning{{leak}}
 }
 
-
-
 // Test @synchronized
 void test_synchronized(id x) {
   @synchronized(x) {
@@ -307,4 +332,4 @@ void test_synchronized(id x) {
   }
 }
 
-// Test return from method starting with 'new' or 'copy'
+