shithub: aubio

Download patch

ref: b643a33823c19608bcf924edf18ba048dd3198a4
parent: ae5d58a7ec6083e54c14da6dd2ac8d755a0e9224
author: Paul Brossier <piem@piem.org>
date: Thu Apr 21 15:01:50 EDT 2016

src/io/*.c: take a copy of const char* path

--- a/src/io/sink_apple_audio.c
+++ b/src/io/sink_apple_audio.c
@@ -59,7 +59,6 @@
 
 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) {
   aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t);
-  s->path = uri;
   s->max_frames = MAX_SIZE;
   s->async = false;
 
@@ -67,6 +66,9 @@
     AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
     goto beach;
   }
+  if (s->path != NULL) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX));
+  strncpy(s->path, uri, strnlen(uri, PATH_MAX));
 
   s->samplerate = 0;
   s->channels = 0;
@@ -249,6 +251,7 @@
 
 void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
   if (s->audioFile) aubio_sink_apple_audio_close (s);
+  if (s->path) AUBIO_FREE(s->path);
   freeAudioBufferList(&s->bufferList);
   AUBIO_FREE(s);
   return;
--- a/src/io/sink_sndfile.c
+++ b/src/io/sink_sndfile.c
@@ -56,7 +56,6 @@
 aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) {
   aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
   s->max_size = MAX_SIZE;
-  s->path = path;
 
   if (path == NULL) {
     AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
@@ -63,6 +62,10 @@
     return NULL;
   }
 
+  if (s->path) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
+  strncpy(s->path, path, strnlen(path, PATH_MAX));
+
   s->samplerate = 0;
   s->channels = 0;
 
@@ -219,6 +222,7 @@
 
 void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
   if (!s) return;
+  if (s->path) AUBIO_FREE(s->path);
   aubio_sink_sndfile_close(s);
   AUBIO_FREE(s->scratch_data);
   AUBIO_FREE(s);
--- a/src/io/sink_wavwrite.c
+++ b/src/io/sink_wavwrite.c
@@ -89,7 +89,10 @@
     goto beach;
   }
 
-  s->path = path;
+  if (s->path) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
+  strncpy(s->path, path, strnlen(path, PATH_MAX));
+
   s->max_size = MAX_SIZE;
   s->bitspersample = 16;
   s->total_frames_written = 0;
@@ -287,6 +290,7 @@
 void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){
   if (!s) return;
   aubio_sink_wavwrite_close(s);
+  if (s->path) AUBIO_FREE(s->path);
   AUBIO_FREE(s->scratch_data);
   AUBIO_FREE(s);
 }
--- a/src/io/source_apple_audio.c
+++ b/src/io/source_apple_audio.c
@@ -79,7 +79,6 @@
 
   s->block_size = block_size;
   s->samplerate = samplerate;
-  s->path = path;
 
   if ( aubio_source_apple_audio_open ( s, path ) ) {
     goto beach;
@@ -95,10 +94,13 @@
 {
   OSStatus err = noErr;
   UInt32 propSize;
-  s->path = path;
 
+  if (s->path) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
+  strncpy(s->path, path, strnlen(path, PATH_MAX));
+
   // open the resource url
-  CFURLRef fileURL = createURLFromPath(path);
+  CFURLRef fileURL = createURLFromPath(s->path);
   err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
   CFRelease(fileURL);
   if (err == -43) {
@@ -293,6 +295,7 @@
 
 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
   aubio_source_apple_audio_close (s);
+  if (s->path) AUBIO_FREE(s->path);
   freeAudioBufferList(&s->bufferList);
   AUBIO_FREE(s);
   return;
--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -84,8 +84,11 @@
 
   s->hop_size = hop_size;
   s->channels = 1;
-  s->path = path;
 
+  if (s->path) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
+  strncpy(s->path, path, strnlen(path, PATH_MAX));
+
   // register all formats and codecs
   av_register_all();
 
@@ -424,6 +427,7 @@
   if (s->avFrame != NULL) {
     av_frame_free( &(s->avFrame) );
   }
+  if (s->path) AUBIO_FREE(s->path);
   s->avFrame = NULL;
   AUBIO_FREE(s);
 }
--- a/src/io/source_sndfile.c
+++ b/src/io/source_sndfile.c
@@ -86,8 +86,11 @@
 
   s->hop_size = hop_size;
   s->channels = 1;
-  s->path = path;
 
+  if (s->path) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
+  strncpy(s->path, path, strnlen(path, PATH_MAX));
+
   // try opening the file, getting the info in sfinfo
   AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
   s->handle = sf_open (s->path, SFM_READ, &sfinfo);
@@ -305,6 +308,7 @@
     del_fvec(s->input_data);
   }
 #endif /* HAVE_SAMPLERATE */
+  if (s->path) AUBIO_FREE(s->path);
   AUBIO_FREE(s->scratch_data);
   AUBIO_FREE(s);
 }
--- a/src/io/source_wavread.c
+++ b/src/io/source_wavread.c
@@ -86,7 +86,10 @@
     goto beach;
   }
 
-  s->path = path;
+  if (s->path) AUBIO_FREE(s->path);
+  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
+  strncpy(s->path, path, strnlen(path, PATH_MAX));
+
   s->samplerate = samplerate;
   s->hop_size = hop_size;
 
@@ -388,6 +391,7 @@
   aubio_source_wavread_close(s);
   if (s->short_output) AUBIO_FREE(s->short_output);
   if (s->output) del_fmat(s->output);
+  if (s->path) AUBIO_FREE(s->path);
   AUBIO_FREE(s);
 }