From 76305b53ada9eb8dcfc731596cdee47c8a3ea8eb Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 7 Jun 2017 17:50:17 +0200 Subject: [PATCH] fixing possible null ptr access or memory leaks according to analyzer --- src/osx/cocoa/filedlg.mm | 2 +- src/osx/cocoa/mediactrl.mm | 2 +- src/osx/cocoa/msgdlg.mm | 4 ++-- src/osx/cocoa/textctrl.mm | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index 29ef2e531b..634df40c0c 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -314,7 +314,7 @@ void wxFileDialog::ShowWindowModal() if (GetParent()) parentWindow = dynamic_cast(wxGetTopLevelParent(GetParent())); - wxASSERT_MSG(parentWindow, "Window modal display requires parent."); + wxCHECK_RET(parentWindow, "Window modal display requires parent."); wxGCC_WARNING_SUPPRESS(deprecated-declarations) diff --git a/src/osx/cocoa/mediactrl.mm b/src/osx/cocoa/mediactrl.mm index db53f99778..255b991247 100644 --- a/src/osx/cocoa/mediactrl.mm +++ b/src/osx/cocoa/mediactrl.mm @@ -335,7 +335,7 @@ private: if ( self = [super initWithFrame:rect] ) { [self setWantsLayer:YES]; - AVPlayerLayer* playerlayer = [[AVPlayerLayer playerLayerWithPlayer: player] retain]; + AVPlayerLayer* playerlayer = [AVPlayerLayer playerLayerWithPlayer: player]; [player setPlayerLayer:playerlayer]; [playerlayer setFrame:[[self layer] bounds]]; diff --git a/src/osx/cocoa/msgdlg.mm b/src/osx/cocoa/msgdlg.mm index aca46d1541..8dda8e1fd9 100644 --- a/src/osx/cocoa/msgdlg.mm +++ b/src/osx/cocoa/msgdlg.mm @@ -173,8 +173,6 @@ int wxMessageDialog::ShowModal() void wxMessageDialog::ShowWindowModal() { - NSAlert* alert = (NSAlert*)ConstructNSAlert(); - wxNonOwnedWindow* parentWindow = NULL; m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; @@ -186,6 +184,8 @@ void wxMessageDialog::ShowWindowModal() if (parentWindow) { + NSAlert* alert = (NSAlert*)ConstructNSAlert(); + NSWindow* nativeParent = parentWindow->GetWXWindow(); [alert beginSheetModalForWindow: nativeParent modalDelegate: m_sheetDelegate didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 4f288f2375..ab72396964 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -856,16 +856,16 @@ bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style) if (position < (long) [[m_textView string] length]) { NSTextStorage* storage = [m_textView textStorage]; - font = [[storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL] autorelease]; - bgcolor = [[storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease]; - fgcolor = [[storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease]; + font = [storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL]; + bgcolor = [storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL]; + fgcolor = [storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL]; } else { NSDictionary* attrs = [m_textView typingAttributes]; - font = [[attrs objectForKey:NSFontAttributeName] autorelease]; - bgcolor = [[attrs objectForKey:NSBackgroundColorAttributeName] autorelease]; - fgcolor = [[attrs objectForKey:NSForegroundColorAttributeName] autorelease]; + font = [attrs objectForKey:NSFontAttributeName]; + bgcolor = [attrs objectForKey:NSBackgroundColorAttributeName]; + fgcolor = [attrs objectForKey:NSForegroundColorAttributeName]; } if (font)