changeset 36532:2398517e5bda

film: Fix memory leaks in error cases.
author reimar
date Sun, 19 Jan 2014 11:30:05 +0000
parents 3cd07587a35d
children 80218ddb982f
files libmpdemux/demux_film.c
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_film.c	Sun Jan 19 11:13:04 2014 +0000
+++ b/libmpdemux/demux_film.c	Sun Jan 19 11:30:05 2014 +0000
@@ -108,7 +108,7 @@
   film_data_t *film_data = (film_data_t *)demuxer->priv;
   film_chunk_t film_chunk;
   int length_fix_bytes;
-  demux_packet_t* dp;
+  demux_packet_t* dp = NULL;
 
   // see if the end has been reached
   if (film_data->current_chunk >= film_data->total_chunks)
@@ -128,7 +128,7 @@
     dp = new_demux_packet(film_chunk.chunk_size);
     if (stream_read(demuxer->stream, dp->buffer, film_chunk.chunk_size) !=
       film_chunk.chunk_size)
-      return 0;
+      goto err_out;
     dp->pts = film_chunk.pts;
     dp->pos = film_chunk.chunk_offset;
     dp->flags = 0;
@@ -171,6 +171,7 @@
 
     // append packet to DS stream
     ds_add_packet(demuxer->audio, dp);
+    dp = NULL;
    }
   }
   else
@@ -188,13 +189,13 @@
 
       // these CVID data chunks have a few extra bytes; skip them
       if (stream_read(demuxer->stream, dp->buffer, 10) != 10)
-        return 0;
+        goto err_out;
       stream_skip(demuxer->stream, length_fix_bytes);
 
       if (stream_read(demuxer->stream, dp->buffer + 10,
         film_chunk.chunk_size - (10 + length_fix_bytes)) !=
         (film_chunk.chunk_size - (10 + length_fix_bytes)))
-        return 0;
+        goto err_out;
 
       dp->pts = film_chunk.pts;
       dp->pos = film_chunk.chunk_offset;
@@ -208,6 +209,7 @@
 
       // append packet to DS stream
       ds_add_packet(demuxer->video, dp);
+      dp = NULL;
     }
     else
     {
@@ -219,6 +221,10 @@
   film_data->current_chunk++;
 
   return 1;
+
+err_out:
+  if (dp) free_demux_packet(dp);
+  return NULL;
 }
 
 static demuxer_t* demux_open_film(demuxer_t* demuxer)