Skip to content

Commit 648558d

Browse files
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

File tree

ui/drivers/ui_cocoa.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,17 @@ static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state)
172172
#ifdef HAVE_COCOA_METAL
173173
[panel setAllowedFileTypes:@[BOXSTRING(state->filters), BOXSTRING(state->filters_title)]];
174174
#else
175+
/* Under MRC (ui_cocoa.m is built without -fobjc-arc per the
176+
* top-level Makefile; see Makefile.common ~line 1654), the
177+
* local 'filetypes' is +1 from alloc+initWithObjects.
178+
* setAllowedFileTypes: retains its own reference, so after
179+
* the call returns we must release the local +1 or it leaks
180+
* every time the file picker opens with a filter. The
181+
* HAVE_COCOA_METAL branch above uses @[...] literal syntax
182+
* which is already autoreleased. */
175183
NSArray *filetypes = [[NSArray alloc] initWithObjects:BOXSTRING(state->filters), BOXSTRING(state->filters_title), nil];
176184
[panel setAllowedFileTypes:filetypes];
185+
RARCH_RELEASE(filetypes);
177186
#endif
178187
}
179188

0 commit comments

Comments
 (0)