shithub: aubio

Download patch

ref: eba24c59a94e7d53e118f744a18002c38ae6563a
parent: 09b4be98f30664d46209e80cebd2b9b8c15496a4
author: Paul Brossier <piem@piem.org>
date: Wed Dec 19 10:47:25 EST 2018

[io] sink_flac to dynamically allocate metadata

--- a/src/io/sink_flac.c
+++ b/src/io/sink_flac.c
@@ -63,7 +63,7 @@
   FILE *fid;            // file id
   FLAC__StreamEncoder* encoder;
   FLAC__int32 *buffer;
-  FLAC__StreamMetadata *metadata[2];
+  FLAC__StreamMetadata **metadata;
 };
 
 typedef struct _aubio_sink_flac_t aubio_sink_flac_t;
@@ -167,6 +167,12 @@
     goto failure;
   }
 
+  s->metadata = AUBIO_ARRAY(FLAC__StreamMetadata*, 2);
+  if (!s->metadata) {
+    AUBIO_ERR("sink_flac: failed allocating memory for %s\n", s->path);
+    goto failure;
+  }
+
   s->metadata[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
   if (!s->metadata[0]) {
     AUBIO_ERR("sink_flac: failed allocating vorbis comment %s\n", s->path);
@@ -323,8 +329,11 @@
 
   if (s->metadata) {
     // clean up metadata after stream finished
-    FLAC__metadata_object_delete(s->metadata[0]);
-    FLAC__metadata_object_delete(s->metadata[1]);
+    if (s->metadata[0])
+      FLAC__metadata_object_delete(s->metadata[0]);
+    if (s->metadata[1])
+      FLAC__metadata_object_delete(s->metadata[1]);
+    AUBIO_FREE(s->metadata);
   }
 
   if (s->fid && fclose(s->fid)) {