From 915b4fb171afec486a386b7098f6ccfe59058f4f Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 14 Dec 2014 17:19:50 +0100 Subject: Fix crash on export with "overwrite existing files" This should fix #2010. A required object was not retained long enough. --- Source/SPExportFileUtilities.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/SPExportFileUtilities.m b/Source/SPExportFileUtilities.m index aafea54d..778deb3e 100644 --- a/Source/SPExportFileUtilities.m +++ b/Source/SPExportFileUtilities.m @@ -31,10 +31,11 @@ #import "SPExportFileUtilities.h" #import "SPExportInitializer.h" #import "SPExporter.h" -#import "SPAlertSheets.h" #import "SPExportFile.h" #import "SPDatabaseDocument.h" #import "SPCustomQuery.h" +#import "SPTableContent.h" +#import "SPTableContentDelegate.h" #import @@ -53,7 +54,7 @@ SPExportErrorChoice; @end -@implementation SPExportController (SPExportFileUtilities) +@implementation SPExportController (SPExportFileUtilitiesPrivateAPI) /** * Writes the CSV file header to the supplied export file. @@ -115,7 +116,7 @@ SPExportErrorChoice; if ([exportXMLFormatPopUpButton indexOfSelectedItem] == SPXMLExportMySQLFormat) { - NSString *tag = @""; + NSString *tag; if (exportSource == SPTableExport) { tag = [NSString stringWithFormat:@"\n\n\n", [tableDocumentInstance database]]; @@ -141,6 +142,11 @@ SPExportErrorChoice; */ - (void)errorCreatingExportFileHandles:(NSArray *)files { + // We don't know where "files" came from, but we know 2 things: + // - NSAlert will NOT retain it as contextInfo + // - This method continues execution after [alert beginSheet:...], thus even if files was retained before, it could be released before the alert ends + [files retain]; + // Get the number of files that already exist as well as couldn't be created because of other reasons NSUInteger filesAlreadyExisting = 0; NSUInteger parentFoldersMissing = 0; @@ -270,6 +276,7 @@ SPExportErrorChoice; [exportProgressWindow orderOut:self]; [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:files]; + [alert autorelease]; } /** -- cgit v1.2.3