From 2da75260bb9ae1a1ad282b695fd5c9d74a46d41d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 2 Nov 2015 00:18:30 +0100 Subject: [PATCH] src/io/{sink,source,utils}_apple_audio.c: fix memory leak calling CFRelease (closes #26, closes #27, and closes #28) --- src/io/sink_apple_audio.c | 5 +++-- src/io/source_apple_audio.c | 5 +++-- src/io/utils_apple_audio.c | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/io/sink_apple_audio.c b/src/io/sink_apple_audio.c index f4e55e02..d4929520 100644 --- a/src/io/sink_apple_audio.c +++ b/src/io/sink_apple_audio.c @@ -36,7 +36,7 @@ extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); extern void freeAudioBufferList(AudioBufferList *bufferList); -extern CFURLRef getURLFromPath(const char * path); +extern CFURLRef createURLFromPath(const char * path); char_t *getPrintableOSStatusError(char_t *str, OSStatus error); uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s); @@ -137,11 +137,12 @@ uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s) { clientFormat.mReserved = 0; AudioFileTypeID fileType = kAudioFileWAVEType; - CFURLRef fileURL = getURLFromPath(s->path); + CFURLRef fileURL = createURLFromPath(s->path); bool overwrite = true; OSStatus err = noErr; err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL, overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile); + CFRelease(fileURL); if (err) { char_t errorstr[20]; AUBIO_ERR("sink_apple_audio: error when trying to create %s with " diff --git a/src/io/source_apple_audio.c b/src/io/source_apple_audio.c index ddf4ab67..0cf7d44b 100644 --- a/src/io/source_apple_audio.c +++ b/src/io/source_apple_audio.c @@ -51,7 +51,7 @@ struct _aubio_source_apple_audio_t { extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples); extern void freeAudioBufferList(AudioBufferList *bufferList); -extern CFURLRef getURLFromPath(const char * path); +extern CFURLRef createURLFromPath(const char * path); char_t *getPrintableOSStatusError(char_t *str, OSStatus error); uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path); @@ -98,8 +98,9 @@ uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * pa s->path = path; // open the resource url - CFURLRef fileURL = getURLFromPath(path); + CFURLRef fileURL = createURLFromPath(path); err = ExtAudioFileOpenURL(fileURL, &s->audioFile); + CFRelease(fileURL); if (err == -43) { AUBIO_ERR("source_apple_audio: Failed opening %s, " "file not found, or no read access\n", s->path); diff --git a/src/io/utils_apple_audio.c b/src/io/utils_apple_audio.c index d66b2d52..2e651d50 100644 --- a/src/io/utils_apple_audio.c +++ b/src/io/utils_apple_audio.c @@ -33,12 +33,14 @@ void freeAudioBufferList(AudioBufferList *bufferList) { bufferList = NULL; } -CFURLRef getURLFromPath(const char * path) { +CFURLRef createURLFromPath(const char * path) { CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault, path, kCFStringEncodingUTF8); - return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath, + CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath, kCFURLPOSIXPathStyle, false); + CFRelease(cfTotalPath); + return url; } char_t *getPrintableOSStatusError(char_t *str, OSStatus error) -- 2.11.0