From 1e64278150150fa5d47cd59e09821914a87c5f11 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 12 Jul 2020 20:58:41 +0200 Subject: [PATCH] macOS fixing potential crash in PasteboardWriter using a pasteboard peeker tool lead to a crash when the drag pasteboard was accessed after our session has long finished. Make sure the writer is working correctly event after the data object is not valid anymore --- src/osx/cocoa/dnd.mm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/osx/cocoa/dnd.mm b/src/osx/cocoa/dnd.mm index 31d3a2cd5b..d4a3305fdd 100644 --- a/src/osx/cocoa/dnd.mm +++ b/src/osx/cocoa/dnd.mm @@ -451,20 +451,29 @@ typedef NSString* NSPasteboardType; return self; } +- (void) clearDataObject +{ + m_data = NULL; +} - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type { - wxDataFormat format((wxDataFormat::NativeFormat) type); - size_t size = m_data->GetDataSize(format); - CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault,size ); - m_data->GetDataHere(format, CFDataGetMutableBytePtr(data)); - CFDataSetLength(data, size); - return (id) data; + if ( m_data ) + { + wxDataFormat format((wxDataFormat::NativeFormat) type); + size_t size = m_data->GetDataSize(format); + CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault,size ); + m_data->GetDataHere(format, CFDataGetMutableBytePtr(data)); + CFDataSetLength(data, size); + return (id) data; + } + return nil; } - (nonnull NSArray *)writableTypesForPasteboard:(nonnull NSPasteboard *)pasteboard { wxCFMutableArrayRef typesarray; - m_data->AddSupportedTypes(typesarray, wxDataObjectBase::Direction::Get); + if ( m_data ) + m_data->AddSupportedTypes(typesarray, wxDataObjectBase::Direction::Get); return (NSArray*) typesarray.autorelease(); } @@ -521,6 +530,8 @@ wxDragResult wxDropSource::DoDragDrop(int flags) result = NSDragOperationToWxDragResult([delegate code]); [delegate release]; [image release]; + [writer clearDataObject]; + [writer release]; wxWindow* mouseUpTarget = wxWindow::GetCapture();