Hi Guys,

I was looking into an older project which does not use ARC and I noticed new 
static code analysis issues with leaks. Here is a little sample code of the 
object in question.


@interface TempConfig : NSObject


@property (assign) NSMutableArray* contents;


+(id)newTempConfigWithSource:(NSString*)source;


@end


+ (id) newTempConfigWithSource:(NSString*)source

{

    ScanConfig* config = [[[self class] alloc] init];



    // Read contens from file

    NSError *errorDesc = nil;

    NSPropertyListFormat format;

    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:source];


    if( plistXML == nil ) {

        [config release];

        return nil;

    }

    // Serialize to array

    [config setContents:(NSMutableArray *)[[NSPropertyListSerialization

                                          propertyListWithData:plistXML

                                          options:0

                                          format:&format

                                          error:&errorDesc] retain]];

    if( [config contents] == nil ) {    <-------Static analysis points out to 
potential leak of object.

        [config release];

        return nil;

    }

    return config;

}


The way I use the code.

TempConfig* innerPList = [TempConfig newTempConfigWithSource:fullPath ];

[innerPList release];


Interestingly, the static code analysis find the call of "retain" as a leak. 
How do I address this issue? What is correct way to rewrite this code to make 
static analyser understand that I will be releasing the resource? If I removed 
the retain count, the warning goes away but it contents is freed and I crash.


Regards,

Varun

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to