}
const IdentifierInfo *II = FD->getIdentifier();
- if (!II)
- return getDefaultSummary();
- StringRef FName = II->getName();
+ StringRef FName = II ? II->getName() : "";
// Strip away preceding '_'. Doing this here will effect all the checks
// down below.
if (FName == "retain")
return getOSSummaryRetainRule(FD);
+
+ if (MD->getOverloadedOperator() == OO_New)
+ return getOSSummaryCreateRule(MD);
}
}
case CE_CXXConstructor:
Summ = getFunctionSummary(cast<CXXConstructorCall>(Call).getDecl());
break;
+ case CE_CXXAllocator:
+ Summ = getFunctionSummary(cast<CXXAllocatorCall>(Call).getDecl());
+ break;
case CE_Block:
case CE_CXXDestructor:
- case CE_CXXAllocator:
// FIXME: These calls are currently unsupported.
return getPersistentStopSummary();
case CE_ObjCMessage: {
static OSObject *getObject();
static OSObject *GetObject();
+
+ static void * operator new(unsigned long size);
+
static const OSMetaClass * const metaClass;
};
static OSObject *safeMetaCast(const OSObject *inst, const OSMetaClass *meta);
};
+unsigned int check_leak_explicit_new() {
+ OSArray *arr = new OSArray; // expected-note{{Operator new returns an OSObject of type struct OSArray * with a +1 retain count}}
+ return arr->getCount(); // expected-note{{Object leaked: allocated object of type struct OSArray * is not referenced later in this execution path and has a retain count of +1}}
+ // expected-warning@-1{{Potential leak of an object of type struct OSArray *}}
+}
+
+unsigned int check_leak_factory() {
+ OSArray *arr = OSArray::withCapacity(10); // expected-note{{Call to function 'OSArray::withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}}
+ return arr->getCount(); // expected-note{{Object leaked: object allocated and stored into 'arr' is not referenced later in this execution path and has a retain count of +1}}
+ // expected-warning@-1{{Potential leak of an object stored into 'arr'}}
+}
+
void check_get_object() {
OSObject::getObject();
}