src/io/{sink,source,utils}_apple_audio.c: fix memory leak calling CFRelease (closes...
authorPaul Brossier <piem@piem.org>
Sun, 1 Nov 2015 23:18:30 +0000 (00:18 +0100)
committerPaul Brossier <piem@piem.org>
Sun, 1 Nov 2015 23:18:30 +0000 (00:18 +0100)
src/io/sink_apple_audio.c
src/io/source_apple_audio.c
src/io/utils_apple_audio.c

index f4e55e0..d492952 100644 (file)
@@ -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 "
index ddf4ab6..0cf7d44 100644 (file)
@@ -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);
index d66b2d5..2e651d5 100644 (file)
@@ -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)