]> granicus.if.org Git - clang/commitdiff
initXXX methods can return owned objects
authorTed Kremenek <kremenek@apple.com>
Wed, 5 Nov 2008 16:54:44 +0000 (16:54 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 5 Nov 2008 16:54:44 +0000 (16:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58758 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp

index 80c6bf9532473163346794ce0a23ac78564d0a45..1a38d957eb1124fc007b224d2956c6000a832b24 100644 (file)
@@ -57,7 +57,12 @@ static bool followsFundamentalRule(const char* s) {
   while (*s == '_') ++s;  
   return CStrInCStrNoCase(s, "create") || CStrInCStrNoCase(s, "copy")  || 
   CStrInCStrNoCase(s, "new") == s || CStrInCStrNoCase(s, "alloc") == s;
-}  
+}
+
+static bool followsReturnRule(const char* s) {
+  while (*s == '_') ++s;  
+  return followsFundamentalRule(s) || CStrInCStrNoCase(s, "init") == s;
+}
 
 //===----------------------------------------------------------------------===//
 // Selector creation functions.
@@ -1878,7 +1883,7 @@ CFRefCount::HandleSymbolDeath(GRStateManager& VMgr,
   if (V.isReturnedOwned() && V.getCount() == 0)
     if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(CD)) {
       std::string s = MD->getSelector().getName();
-      if (!followsFundamentalRule(s.c_str())) {
+      if (!followsReturnRule(s.c_str())) {
         hasLeak = true;
         state = state.set<RefBindings>(sid, V ^ RefVal::ErrorLeakReturned);
         return std::make_pair(state, true);