Commit 648558d
committed
ui/cocoa: release filetypes NSArray in non-Metal file-browser open path
ui_browser_window_cocoa_open has two branches for constructing the
allowed-file-types list passed to -[NSOpenPanel setAllowedFileTypes:]:
#ifdef HAVE_COCOA_METAL
[panel setAllowedFileTypes:@[BOXSTRING(...), BOXSTRING(...)]];
#else
NSArray *filetypes = [[NSArray alloc] initWithObjects:..., nil];
[panel setAllowedFileTypes:filetypes];
#endif
The HAVE_COCOA_METAL branch uses @[...] literal syntax, which
creates an autoreleased NSArray - released by the enclosing
autorelease pool. The #else branch uses explicit alloc+init,
which returns +1 retained; setAllowedFileTypes: retains its own
reference, so after the call returns we must release the local
or it leaks.
This file compiles under MRC per Makefile.common ~line 1654
('MRC-written Cocoa code (ui_cocoa.m et al.)'), and the fix macro
RARCH_RELEASE from libretro-common/include/defines/cocoa_defines.h
expands to [(x) release] on MRC and to ((void)0) under ARC, so
adding it is safe for both build matrices even though this file
is MRC-only today.
The leak fires every time the user opens a filtered file dialog
(Load Core, Load Content). NSArray with two BOXSTRING'd
NSStrings is a few dozen bytes per occurrence; not catastrophic,
but a leaks(1) run would flag it every time.
Thread-safety: unchanged. ui_browser_window_cocoa_open runs on
the main AppKit thread.
Scope: the rest of this file's menu-building code (lines 1220+)
is consistent and correctly uses the alloc-then-RARCH_RELEASE
pattern via the cocoa_menu_item_with_action helper and the per-
menu builder functions. cocoa_create_menu_bar's six menubar
items all pair alloc+init with RARCH_RELEASE. The file_browser
open path was the one outlier.1 parent 93cdcb8 commit 648558d
1 file changed
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
175 | 183 | | |
176 | 184 | | |
| 185 | + | |
177 | 186 | | |
178 | 187 | | |
179 | 188 | | |
| |||
0 commit comments