music4kid / PLeakSniffer

Detect memory leaks for your iOS project automatically.
http://mrpeak.cn
MIT License
513 stars 63 forks source link

查找property的时候把protocol中的property也带上了 #8

Open RhettTamp opened 5 years ago

RhettTamp commented 5 years ago

在我的项目中使用的时候发现查找property的时候还查找了类实现的protocol的property,导致调用valueForKey的时候crash

PipeDog commented 5 years ago
static BOOL _property_hasGetterOrRetainedIvar(objc_property_t property) {
    if (property == NULL) { return NO; }

    const char *attrs = property_getAttributes(property);
    if (attrs == NULL) { return NO; }

    // Check dynamic
    const char *dynamic = strstr(attrs, ",D");
    if (dynamic != NULL) {
        return NO;
    }

    // Check getter
    const char *getter = strstr(attrs, ",G");
    if (getter != NULL) {
        return YES;
    }

    // Check retained and ivar
    const char *retained = strchr(attrs, '&');
    const char *ivar = strstr(attrs, ",V");

    if (retained != NULL && ivar != NULL) {
        return YES;
    }
    return NO;
}

使用上边这个方法替换bool isStrongProperty(objc_property_t property)方法试下