Skip to content

Commit

Permalink
Merge pull request ZipArchive#53 from randomsequence/master
Browse files Browse the repository at this point in the history
Fix NSFileManager leak when building without ARC
  • Loading branch information
soffes committed May 3, 2013
2 parents ffbacdb + b078433 commit 481ddf2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions SSZipArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,17 @@ + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths {

+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
BOOL success = NO;

NSFileManager *fileManager = nil;
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];

if ([zipArchive open]) {
// use a local filemanager (queue/thread compatibility)
NSFileManager *fileManager = [[NSFileManager alloc] init];
fileManager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnumerator = [fileManager enumeratorAtPath:directoryPath];

NSString *fileName;
while (fileName = [dirEnumerator nextObject]) {
while ((fileName = [dirEnumerator nextObject])) {
BOOL isDir;
NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:fileName];
[fileManager fileExistsAtPath:fullFilePath isDirectory:&isDir];
Expand All @@ -315,6 +317,7 @@ + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *
}

#if !__has_feature(objc_arc)
[fileManager release];
[zipArchive release];
#endif

Expand Down Expand Up @@ -382,7 +385,7 @@ - (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName {
afileName = [fileName UTF8String];
}

zip_fileinfo zipInfo = {0};
zip_fileinfo zipInfo = {{0}};

NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error: nil];
if( attr )
Expand Down

0 comments on commit 481ddf2

Please sign in to comment.