music4kid / PLeakSniffer

Detect memory leaks for your iOS project automatically.

Home Page:http://mrpeak.cn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

RhettTamp opened this issue · comments

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

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)方法试下