# HG changeset patch # User reimar # Date 1292155981 0 # Node ID f023e5d1a0fd507e7ac7e74890fb1f631e759c6a # Parent 1bede0ded07ecd21d9b2d631757fa40a700ddaa3 Fix allocations: always free before overwriting a pointer with a newly allocated one, always use calloc instead of realloc when the previous data is not needed. diff -r 1bede0ded07e -r f023e5d1a0fd libmpdemux/demux_mov.c --- a/libmpdemux/demux_mov.c Sun Dec 12 11:45:47 2010 +0000 +++ b/libmpdemux/demux_mov.c Sun Dec 12 12:13:01 2010 +0000 @@ -247,7 +247,8 @@ mp_msg(MSGT_DEMUX, MSGL_WARN, "MOV: durmap or chunkmap bigger than sample count (%i vs %i)\n", s, trak->samples_size); - trak->samples = realloc_struct(trak->samples, s, sizeof(mov_sample_t)); + free(trak->samples); + trak->samples = calloc(s, sizeof(mov_sample_t)); trak->samples_size = trak->samples ? s : 0; } @@ -1767,6 +1768,7 @@ mp_msg(MSGT_DEMUX, MSGL_V, "MOV: %*sSample duration table! (%d blocks)\n", level, "", len); + free(trak->durmap); trak->durmap = calloc(len, sizeof(mov_durmap_t)); trak->durmap_size = trak->durmap ? len : 0; for (i = 0; i < trak->durmap_size; i++) { @@ -1789,6 +1791,7 @@ "MOV: %*sSample->Chunk mapping table! (%d blocks) (ver:%d,flags:%d)\n", level, "", len, ver, flags); // read data: + free(trak->chunkmap); trak->chunkmap = calloc(len, sizeof(mov_chunkmap_t)); trak->chunkmap_size = trak->chunkmap ? len : 0; for (i = 0; i < trak->chunkmap_size; i++) { @@ -1811,8 +1814,9 @@ trak->samplesize = ss; if (!ss) { // variable samplesize - trak->samples = realloc_struct(trak->samples, entries, sizeof(mov_sample_t)); - trak->samples_size = entries; + free(trak->samples); + trak->samples = calloc(entries, sizeof(mov_sample_t)); + trak->samples_size = trak->samples ? entries : 0; for (i = 0; i < trak->samples_size; i++) trak->samples[i].size = stream_read_dword(demuxer->stream); } @@ -1827,7 +1831,8 @@ len); // extend array if needed: if (len > trak->chunks_size) { - trak->chunks = realloc_struct(trak->chunks, len, sizeof(mov_chunk_t)); + free(trak->chunks); + trak->chunks = calloc(len, sizeof(mov_chunk_t)); trak->chunks_size = trak->chunks ? len : 0; } // read elements: @@ -1844,7 +1849,8 @@ len); // extend array if needed: if (len > trak->chunks_size) { - trak->chunks = realloc_struct(trak->chunks, len, sizeof(mov_chunk_t)); + free(trak->chunks); + trak->chunks = calloc(len, sizeof(mov_chunk_t)); trak->chunks_size = trak->chunks ? len : 0; } // read elements: @@ -1868,6 +1874,7 @@ mp_msg(MSGT_DEMUX, MSGL_V, "MOV: %*sSyncing samples (keyframes) table! (%d entries) (ver:%d,flags:%d)\n", level, "", entries, ver, flags); + free(trak->keyframes); trak->keyframes = calloc(entries, sizeof(unsigned int)); trak->keyframes_size = trak->keyframes ? entries : 0; for (i = 0; i < trak->keyframes_size; i++) @@ -1904,6 +1911,7 @@ "MOV: %*sEdit list table (%d entries) (ver:%d,flags:%d)\n", level, "", entries, ver, flags); #if 1 + free(trak->editlist); trak->editlist = calloc(entries, sizeof(mov_editlist_t)); trak->editlist_size = trak->editlist ? entries : 0; for (i = 0; i < trak->editlist_size; i++) {