]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
client: Fix memory leak on exit.
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index b6bab088d60da392ff98cc98a77b6dafcc291b0c..5ca1307f680d366c155b2e98257ba807c5a4fb92 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -133,25 +133,25 @@ static int read_int16(struct mp4 *f, uint16_t *result)
 
 /** A macro defining the atoms we care about. It gets expanded twice. */
 #define ATOM_ITEMS \
-       ATOM_ITEM(MOOV, 'm', 'o', 'o', 'v') \
-       ATOM_ITEM(TRAK, 't', 'r', 'a', 'k') \
-       ATOM_ITEM(MDIA, 'm', 'd', 'i', 'a') \
-       ATOM_ITEM(MINF, 'm', 'i', 'n', 'f') \
-       ATOM_ITEM(STBL, 's', 't', 'b', 'l') \
-       ATOM_ITEM(UDTA, 'u', 'd', 't', 'a') \
+       ATOM_ITEM(MOOV, 'm', 'o', 'o', 'v') /* movie (top-level container) */ \
+       ATOM_ITEM(TRAK, 't', 'r', 'a', 'k') /* container for a single track */ \
+       ATOM_ITEM(MDIA, 'm', 'd', 'i', 'a') /* media information */ \
+       ATOM_ITEM(MINF, 'm', 'i', 'n', 'f') /* extends mdia */ \
+       ATOM_ITEM(STBL, 's', 't', 'b', 'l') /* sample table container */ \
+       ATOM_ITEM(UDTA, 'u', 'd', 't', 'a') /* user data */ \
        ATOM_ITEM(ILST, 'i', 'l', 's', 't') /* iTunes Metadata list */ \
-       ATOM_ITEM(ARTIST, 0xa9, 'A', 'R', 'T') \
-       ATOM_ITEM(TITLE, 0xa9, 'n', 'a', 'm') \
-       ATOM_ITEM(ALBUM, 0xa9, 'a', 'l', 'b') \
-       ATOM_ITEM(DATE, 0xa9, 'd', 'a', 'y') \
-       ATOM_ITEM(COMMENT, 0xa9, 'c', 'm', 't') \
+       ATOM_ITEM(ARTIST, 0xa9, 'A', 'R', 'T') /* artist */ \
+       ATOM_ITEM(TITLE, 0xa9, 'n', 'a', 'm') /* title */ \
+       ATOM_ITEM(ALBUM, 0xa9, 'a', 'l', 'b') /* album */ \
+       ATOM_ITEM(DATE, 0xa9, 'd', 'a', 'y') /* date */ \
+       ATOM_ITEM(COMMENT, 0xa9, 'c', 'm', 't') /* comment */ \
        ATOM_ITEM(MDHD, 'm', 'd', 'h', 'd') /* track header */ \
        ATOM_ITEM(STSD, 's', 't', 's', 'd') /* sample description box */ \
        ATOM_ITEM(STTS, 's', 't', 't', 's') /* time to sample box */ \
        ATOM_ITEM(STSZ, 's', 't', 's', 'z') /* sample size box */ \
        ATOM_ITEM(STCO, 's', 't', 'c', 'o') /* chunk offset box */ \
        ATOM_ITEM(STSC, 's', 't', 's', 'c') /* sample to chunk box */ \
-       ATOM_ITEM(MP4A, 'm', 'p', '4', 'a') \
+       ATOM_ITEM(MP4A, 'm', 'p', '4', 'a') /* mp4 audio */ \
        ATOM_ITEM(META, 'm', 'e', 't', 'a') /* iTunes Metadata box */ \
        ATOM_ITEM(DATA, 'd', 'a', 't', 'a') /* iTunes Metadata data box */ \
 
@@ -240,7 +240,7 @@ static int read_stsz(struct mp4 *f)
                return ret;
        if (t->stsz_sample_size != 0)
                return 1;
-       t->stsz_table = para_malloc(t->stsz_sample_count * sizeof(int32_t));
+       t->stsz_table = arr_alloc(t->stsz_sample_count, sizeof(int32_t));
        for (uint32_t n = 0; n < t->stsz_sample_count; n++) {
                ret = read_int32(f, &t->stsz_table[n]);
                if (ret <= 0)
@@ -260,8 +260,7 @@ static int read_stts(struct mp4 *f)
        ret = read_int32(f, &t->stts_entry_count);
        if (ret <= 0)
                return ret;
-       t->stts_sample_count = para_malloc(t->stts_entry_count
-               * sizeof(int32_t));
+       t->stts_sample_count = arr_alloc(t->stts_entry_count, sizeof(int32_t));
        for (uint32_t n = 0; n < t->stts_entry_count; n++) {
                ret = read_int32(f, &t->stts_sample_count[n]);
                if (ret <= 0)
@@ -284,9 +283,9 @@ static int read_stsc(struct mp4 *f)
        ret = read_int32(f, &t->stsc_entry_count);
        if (ret <= 0)
                return ret;
-       t->stsc_first_chunk = para_malloc(t->stsc_entry_count * sizeof(int32_t));
-       t->stsc_samples_per_chunk = para_malloc(t->stsc_entry_count
-               sizeof (int32_t));
+       t->stsc_first_chunk = arr_alloc(t->stsc_entry_count, sizeof(int32_t));
+       t->stsc_samples_per_chunk = arr_alloc(t->stsc_entry_count,
+               sizeof (int32_t));
        for (uint32_t n = 0; n < t->stsc_entry_count; n++) {
                ret = read_int32(f, &t->stsc_first_chunk[n]);
                if (ret <= 0)
@@ -310,8 +309,7 @@ static int read_stco(struct mp4 *f)
        ret = read_int32(f, &t->stco_entry_count);
        if (ret <= 0)
                return ret;
-       t->stco_chunk_offset = para_malloc(t->stco_entry_count
-               * sizeof(int32_t));
+       t->stco_chunk_offset = arr_alloc(t->stco_entry_count, sizeof(int32_t));
        for (uint32_t n = 0; n < t->stco_entry_count; n++) {
                ret = read_int32(f, &t->stco_chunk_offset[n]);
                if (ret <= 0)
@@ -396,7 +394,7 @@ static int parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
                        goto fail;
                len = subsize - (header_size + 8);
                free(value);
-               value = para_malloc(len + 1);
+               value = alloc(len + 1);
                ret = read_data(f, value, len);
                if (ret <= 0)
                        goto fail;
@@ -609,7 +607,7 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
        int ret;
        uint64_t size;
        uint8_t atom_type, header_size;
-       struct mp4 *f = para_calloc(sizeof(*f));
+       struct mp4 *f = zalloc(sizeof(*f));
 
        f->cb = cb;
        while ((ret = atom_read_header(f, &atom_type, &header_size, &size)) > 0) {
@@ -918,7 +916,7 @@ static void *modify_moov(struct mp4 *f, uint32_t *out_size)
                new_ilst_size += TAG_LEN(strlen(f->meta.tags[n].value));
        size_delta = new_ilst_size - (f->ilst_size - 8);
        *out_size = total_size + size_delta;
-       out_buffer = para_malloc(*out_size);
+       out_buffer = alloc(*out_size);
        p_out = out_buffer;
        set_position(f, total_base);
        ret = read_data(f, p_out, f->udta_offset - total_base);
@@ -1046,7 +1044,7 @@ free_moov:
  * function also returns NULL. Otherwise a copy of the tag value is returned
  * and the caller should free this memory when it is no longer needed.
  */
-char *mp4_get_tag_value(const struct mp4 *f, const char *item)
+__malloc char *mp4_get_tag_value(const struct mp4 *f, const char *item)
 {
        for (unsigned n = 0; n < f->meta.count; n++)
                if (!strcasecmp(f->meta.tags[n].item, item))