OSDN Git Service

Mac: use NSSound's initWithData
authorEric Branlund <ebranlund@fastmail.com>
Sat, 22 Apr 2023 19:52:58 +0000 (13:52 -0600)
committerEric Branlund <ebranlund@fastmail.com>
Sat, 22 Apr 2023 20:10:52 +0000 (14:10 -0600)
Avoids a file descriptor leak seen with initWithContentsOfFile since macOS 10.15 (Catalina).

src/main-cocoa.m

index 573a814..be92e2e 100644 (file)
@@ -262,9 +262,8 @@ static wchar_t convert_two_byte_eucjp_to_utf32_native(const char *cp);
                        struct stat stb;
                        if (stat(path, &stb) == 0) {
                            /* Load the sound into memory */
-                           sound = [[NSSound alloc]
-                                        initWithContentsOfFile:[NSString stringWithUTF8String:path]
-                                        byReference:YES];
+                           NSData *fileData = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:path]];
+                           sound = [[NSSound alloc] initWithData:fileData];
                            if (sound) {
                                [self->soundsByPath setObject:sound
                                            forKey:token_string];