From 9b9cb791f818faee0cd9af8e89ee4bd28a60ca24 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 15 Nov 2010 01:25:38 +0000 Subject: - Switch to explicit memory management of strings in the QuickLook plugin when viewing SQL files - this fixes certain crashers, addressing Issue 896. - Tweak a misspelling in the templates --- .../SPQLPluginConnectionBundleTemplate.html | 2 +- Resources/English.lproj/SPQLPluginSQLTemplate.html | 2 +- Source/GeneratePreviewForURL.m | 23 ++++++++++++++-------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html b/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html index 02e5601d..c97fb4bc 100644 --- a/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html +++ b/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/English.lproj/SPQLPluginSQLTemplate.html b/Resources/English.lproj/SPQLPluginSQLTemplate.html index d9f55c09..65ba2a3c 100644 --- a/Resources/English.lproj/SPQLPluginSQLTemplate.html +++ b/Resources/English.lproj/SPQLPluginSQLTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Source/GeneratePreviewForURL.m b/Source/GeneratePreviewForURL.m index 841fca8d..0fd6514d 100644 --- a/Source/GeneratePreviewForURL.m +++ b/Source/GeneratePreviewForURL.m @@ -394,17 +394,17 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, // compose the html and perform syntax highlighting // read the file and try to get a proper encoding - NSString *sqlText = [NSString stringWithContentsOfFile:[myURL path] encoding:sqlEncoding error:&readError]; - NSMutableString *sqlHTML = [NSMutableString string]; - NSString *truncatedString = @""; + NSString *sqlText = [[NSString alloc] initWithContentsOfFile:[myURL path] encoding:sqlEncoding error:&readError]; + NSMutableString *sqlHTML = [[NSMutableString alloc] init]; + NSString *truncatedString = [[NSString alloc] init]; if(readError != nil) { // cocoa tries to detect the encoding - sqlText = [NSString stringWithContentsOfFile:[myURL path] usedEncoding:&sqlEncoding error:&readError]; + sqlText = [[NSString alloc] initWithContentsOfFile:[myURL path] usedEncoding:&sqlEncoding error:&readError]; // fall back to latin1 if no sqlText couldn't read if(sqlText == nil) { sqlEncoding = NSISOLatin1StringEncoding; - sqlText = [NSString stringWithContentsOfFile:[myURL path] encoding:sqlEncoding error:&readError]; + sqlText = [[NSString alloc] initWithContentsOfFile:[myURL path] encoding:sqlEncoding error:&readError]; } } @@ -415,8 +415,12 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, // truncate large files since Finder blocks if([filesize unsignedLongValue] > kMaxSQLFileSize) { - sqlText = [sqlText substringToIndex:kMaxSQLFileSize-1]; - truncatedString = @"\n ✂ ..."; + NSString *truncatedSqlText = [[NSString alloc] initWithString:[sqlText substringToIndex:kMaxSQLFileSize-1]]; + [sqlText release]; + sqlText = [[NSString alloc] initWithString:truncatedSqlText]; + [truncatedSqlText release]; + [truncatedString release]; + truncatedString = [[NSString alloc] initWithString:@"\n ✂ ..."]; } NSRange textRange = NSMakeRange(0, [sqlText length]); @@ -467,6 +471,8 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, } [sqlHTML appendString:truncatedString]; + [sqlText release]; + [truncatedString release]; } html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template, @@ -475,7 +481,8 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, sqlHTML ]]; - previewHeight = 495; + previewHeight = 495; + [sqlHTML release]; } else { -- cgit v1.2.3