diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-09-01 15:27:39 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-11-01 22:32:53 +0100 |
commit | d5a9bd404a3ca90a18abeeaaaabdbf5185437ba7 (patch) | |
tree | 5dc82f54f00bc5633e4131d7c77f988367beb425 /src/music | |
parent | 58122983fb1284270a4fd9f420b1c3a3a3605bcb (diff) | |
download | openttd-d5a9bd404a3ca90a18abeeaaaabdbf5185437ba7.tar.xz |
Codechange: [OSX] Use std::unique_ptr with a custom deleter to simply memory management of Core Foundation types.
Diffstat (limited to 'src/music')
-rw-r--r-- | src/music/cocoa_m.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/music/cocoa_m.cpp b/src/music/cocoa_m.cpp index fd3ff295e..53a4b9a4e 100644 --- a/src/music/cocoa_m.cpp +++ b/src/music/cocoa_m.cpp @@ -161,13 +161,12 @@ void MusicDriver_Cocoa::PlaySong(const MusicSongInfo &song) } const char *os_file = OTTD2FS(filename.c_str()); - CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*)os_file, strlen(os_file), false); + CFAutoRelease<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*)os_file, strlen(os_file), false)); #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (MacOSVersionIsAtLeast(10, 5, 0)) { - if (MusicSequenceFileLoad(_sequence, url, kMusicSequenceFile_AnyType, 0) != noErr) { + if (MusicSequenceFileLoad(_sequence, url.get(), kMusicSequenceFile_AnyType, 0) != noErr) { DEBUG(driver, 0, "cocoa_m: Failed to load MIDI file"); - CFRelease(url); return; } } else @@ -175,19 +174,16 @@ void MusicDriver_Cocoa::PlaySong(const MusicSongInfo &song) { #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) FSRef ref_file; - if (!CFURLGetFSRef(url, &ref_file)) { + if (!CFURLGetFSRef(url.get(), &ref_file)) { DEBUG(driver, 0, "cocoa_m: Failed to make FSRef"); - CFRelease(url); return; } if (MusicSequenceLoadSMFWithFlags(_sequence, &ref_file, 0) != noErr) { DEBUG(driver, 0, "cocoa_m: Failed to load MIDI file old style"); - CFRelease(url); return; } #endif } - CFRelease(url); /* Construct audio graph */ AUGraph graph = nullptr; |