ref: 2da75260bb9ae1a1ad282b695fd5c9d74a46d41d
parent: 9ee1ee9b78478492f5eaca0ede46bd1b21dca41e
author: Paul Brossier <piem@piem.org>
date: Sun Nov 1 19:18:30 EST 2015
src/io/{sink,source,utils}_apple_audio.c: fix memory leak calling CFRelease (closes #26, closes #27, and closes #28)
--- 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 @@
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 "
--- a/src/io/source_apple_audio.c
+++ b/src/io/source_apple_audio.c
@@ -51,7 +51,7 @@
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 @@
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);
--- a/src/io/utils_apple_audio.c
+++ b/src/io/utils_apple_audio.c
@@ -33,12 +33,14 @@
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)