[MPlayer-cvslog] r32703 - trunk/libmpdemux/demux_mov.c

reimar subversion at mplayerhq.hu
Sun Dec 12 13:13:01 CET 2010


Author: reimar
Date: Sun Dec 12 13:13:01 2010
New Revision: 32703

Log:
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.

Modified:
   trunk/libmpdemux/demux_mov.c

Modified: trunk/libmpdemux/demux_mov.c
==============================================================================
--- trunk/libmpdemux/demux_mov.c	Sun Dec 12 12:45:47 2010	(r32702)
+++ trunk/libmpdemux/demux_mov.c	Sun Dec 12 13:13:01 2010	(r32703)
@@ -247,7 +247,8 @@ static void mov_build_index(mov_track_t*
       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 @@ static int lschunks_intrak(demuxer_t* de
       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 @@ static int lschunks_intrak(demuxer_t* de
              "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 @@ static int lschunks_intrak(demuxer_t* de
       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 @@ static int lschunks_intrak(demuxer_t* de
              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 @@ static int lschunks_intrak(demuxer_t* de
              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 @@ static int lschunks_intrak(demuxer_t* de
       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 @@ static int lschunks_intrak(demuxer_t* de
              "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++) {


More information about the MPlayer-cvslog mailing list