changeset 35291:ef57345fe3e8

Fix memleaks on error and EOF.
author reimar
date Sat, 10 Nov 2012 12:29:42 +0000
parents 17a449bc5106
children 29be73f9a8ea
files libmpdemux/demux_y4m.c
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_y4m.c	Sat Nov 10 12:27:26 2012 +0000
+++ b/libmpdemux/demux_y4m.c	Sat Nov 10 12:29:42 2012 +0000
@@ -83,7 +83,7 @@
 //     1 = successfully read a packet
 static int demux_y4m_fill_buffer(demuxer_t *demux, demux_stream_t *dsds) {
   demux_stream_t *ds=demux->video;
-  demux_packet_t *dp;
+  demux_packet_t *dp = NULL;
   y4m_priv_t *priv=demux->priv;
   y4m_frame_info_t fi;
   unsigned char *buf[3];
@@ -114,11 +114,11 @@
   {
     int c = stream_read_char(demux->stream); /* F */
     if (c == -256)
-	return 0; /* EOF */
+	goto err_out; /* EOF */
     if (c != 'F')
     {
 	mp_msg(MSGT_DEMUX, MSGL_V, "Bad frame at %d\n", (int)stream_tell(demux->stream)-1);
-	return 0;
+	goto err_out;
     }
     stream_skip(demux->stream, 5); /* RAME\n */
     stream_read(demux->stream, buf[0], size);
@@ -130,7 +130,7 @@
     int err = y4m_read_frame(demux->stream, priv->si, &fi, buf);
     if (err != Y4M_OK) {
       mp_msg(MSGT_DEMUX, MSGL_ERR, "error reading frame %s\n", y4m_strerr(err));
-      return 0;
+      goto err_out;
     }
   }
 
@@ -142,6 +142,11 @@
   ds_add_packet(ds, dp);
 
   return 1;
+
+err_out:
+  if (dp)
+    free_demux_packet(dp);
+  return 0;
 }
 
 static void read_streaminfo(demuxer_t *demuxer)