From: Paul Brossier Date: Thu, 21 Apr 2016 17:01:50 +0000 (+0200) Subject: src/io/*.c: take a copy of const char* path X-Git-Tag: 0.4.4~300^2~298 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=b643a33823c19608bcf924edf18ba048dd3198a4 src/io/*.c: take a copy of const char* path --- diff --git a/src/io/sink_apple_audio.c b/src/io/sink_apple_audio.c index 313dbf2b..6f3f3588 100644 --- a/src/io/sink_apple_audio.c +++ b/src/io/sink_apple_audio.c @@ -59,7 +59,6 @@ struct _aubio_sink_apple_audio_t { 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_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t 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 @@ uint_t aubio_sink_apple_audio_close(aubio_sink_apple_audio_t * s) { 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; diff --git a/src/io/sink_sndfile.c b/src/io/sink_sndfile.c index 4cef5790..c43fbc3c 100644 --- a/src/io/sink_sndfile.c +++ b/src/io/sink_sndfile.c @@ -56,13 +56,16 @@ uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s); 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"); 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 @@ uint_t aubio_sink_sndfile_close (aubio_sink_sndfile_t *s) { 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); diff --git a/src/io/sink_wavwrite.c b/src/io/sink_wavwrite.c index 890a838f..d99c1628 100644 --- a/src/io/sink_wavwrite.c +++ b/src/io/sink_wavwrite.c @@ -89,7 +89,10 @@ aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * path, uint_t samp 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 @@ uint_t aubio_sink_wavwrite_close(aubio_sink_wavwrite_t * s) { 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); } diff --git a/src/io/source_apple_audio.c b/src/io/source_apple_audio.c index 077df18c..97d5b998 100644 --- a/src/io/source_apple_audio.c +++ b/src/io/source_apple_audio.c @@ -79,7 +79,6 @@ aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * path, u 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 @@ uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_ { 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 @@ uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s) 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; diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c index db1b3b98..9bf9098d 100644 --- a/src/io/source_avcodec.c +++ b/src/io/source_avcodec.c @@ -84,7 +84,10 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t sa 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 @@ void del_aubio_source_avcodec(aubio_source_avcodec_t * s){ if (s->avFrame != NULL) { av_frame_free( &(s->avFrame) ); } + if (s->path) AUBIO_FREE(s->path); s->avFrame = NULL; AUBIO_FREE(s); } diff --git a/src/io/source_sndfile.c b/src/io/source_sndfile.c index 2a1772c0..34804e15 100644 --- a/src/io/source_sndfile.c +++ b/src/io/source_sndfile.c @@ -86,7 +86,10 @@ aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t sa 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)); @@ -305,6 +308,7 @@ void del_aubio_source_sndfile(aubio_source_sndfile_t * s){ del_fvec(s->input_data); } #endif /* HAVE_SAMPLERATE */ + if (s->path) AUBIO_FREE(s->path); AUBIO_FREE(s->scratch_data); AUBIO_FREE(s); } diff --git a/src/io/source_wavread.c b/src/io/source_wavread.c index d3230807..3dc3813c 100644 --- a/src/io/source_wavread.c +++ b/src/io/source_wavread.c @@ -86,7 +86,10 @@ aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t sa 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 @@ void del_aubio_source_wavread(aubio_source_wavread_t * s) { 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); }