[MPlayer-cvslog] r36457 - in trunk: command.c input/input.c libmpcodecs/vd_ffmpeg.c mp_fifo.c mp_fifo.h

reimar subversion at mplayerhq.hu
Sun Sep 22 10:34:08 CEST 2013


Author: reimar
Date: Sun Sep 22 10:34:08 2013
New Revision: 36457

Log:
Fix a few memleaks.

Modified:
   trunk/command.c
   trunk/input/input.c
   trunk/libmpcodecs/vd_ffmpeg.c
   trunk/mp_fifo.c
   trunk/mp_fifo.h

Modified: trunk/command.c
==============================================================================
--- trunk/command.c	Sun Sep 22 09:31:55 2013	(r36456)
+++ trunk/command.c	Sun Sep 22 10:34:08 2013	(r36457)
@@ -2762,10 +2762,11 @@ int run_command(MPContext *mpctx, mp_cmd
             file_filter = cmd->args[0].v.i;
             break;
 
-        case MP_CMD_QUIT:
-            exit_player_with_rc(EXIT_QUIT,
-                                (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
-
+        case MP_CMD_QUIT: {
+                int rc = cmd->nargs > 0 ? cmd->args[0].v.i : 0;
+                mp_cmd_free(cmd);
+                exit_player_with_rc(EXIT_QUIT, rc);
+            }
         case MP_CMD_PLAY_TREE_STEP:{
                 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
                 int force = cmd->args[1].v.i;

Modified: trunk/input/input.c
==============================================================================
--- trunk/input/input.c	Sun Sep 22 09:31:55 2013	(r36456)
+++ trunk/input/input.c	Sun Sep 22 10:34:08 2013	(r36457)
@@ -1383,10 +1383,12 @@ mp_cmd_t*
 mp_input_get_cmd(int time, int paused, int peek_only) {
   mp_cmd_t* ret = NULL;
   mp_cmd_filter_t* cf;
-  int from_queue;
+  int from_queue = 0;
 
-  if (async_quit_request)
-    return mp_input_parse_cmd("quit 1");
+  if (async_quit_request) {
+    ret = mp_input_parse_cmd("quit 1");
+    goto end;
+  }
   while(1) {
     from_queue = 1;
     ret = mp_input_get_queued_cmd(peek_only);
@@ -1411,8 +1413,13 @@ mp_input_get_cmd(int time, int paused, i
     }
   }
 
-  if (!from_queue && peek_only)
-    mp_input_queue_cmd(ret);
+end:
+  // enqueue if necessary, if not possible rather drop
+  // command than leak memory
+  if (!from_queue && peek_only && !mp_input_queue_cmd(ret)) {
+    mp_cmd_free(ret);
+    return NULL;
+  }
 
   return ret;
 }
@@ -1820,6 +1827,7 @@ void
 mp_input_uninit(void) {
   unsigned int i;
   mp_cmd_bind_section_t* bind_section;
+  mp_cmd_t *cmd;
 
   for(i=0; i < num_key_fd; i++) {
     if(key_fds[i].close_func)
@@ -1838,6 +1846,11 @@ mp_input_uninit(void) {
     cmd_binds_section=bind_section;
   }
   cmd_binds_section=NULL;
+  // Drop command queue contents to avoid valgrind
+  // warnings
+  while ((cmd = mp_input_get_queued_cmd(0)))
+    mp_cmd_free(cmd);
+  mplayer_key_fifo_uninit();
 }
 
 void

Modified: trunk/libmpcodecs/vd_ffmpeg.c
==============================================================================
--- trunk/libmpcodecs/vd_ffmpeg.c	Sun Sep 22 09:31:55 2013	(r36456)
+++ trunk/libmpcodecs/vd_ffmpeg.c	Sun Sep 22 10:34:08 2013	(r36457)
@@ -922,7 +922,7 @@ static mp_image_t *decode(sh_video_t *sh
     ret = avcodec_decode_video2(avctx, pic, &got_picture, &pkt);
     pkt.data = NULL;
     pkt.size = 0;
-    av_destruct_packet(&pkt);
+    av_packet_free_side_data(&pkt);
 
     // even when we do dr we might actually get a buffer we had
     // FFmpeg allocate - this mostly happens with nonref_dr.

Modified: trunk/mp_fifo.c
==============================================================================
--- trunk/mp_fifo.c	Sun Sep 22 09:31:55 2013	(r36456)
+++ trunk/mp_fifo.c	Sun Sep 22 10:34:08 2013	(r36457)
@@ -101,3 +101,11 @@ void mplayer_put_key(int code) {
       now - last_key_time[1] < doubleclick_time)
     put_double(code);
 }
+
+void mplayer_key_fifo_uninit(void) {
+  free(key_fifo_data);
+  key_fifo_data = NULL;
+  key_fifo_read = 0;
+  key_fifo_write = 0;
+  previous_down_key = 0;
+}

Modified: trunk/mp_fifo.h
==============================================================================
--- trunk/mp_fifo.h	Sun Sep 22 09:31:55 2013	(r36456)
+++ trunk/mp_fifo.h	Sun Sep 22 10:34:08 2013	(r36457)
@@ -25,5 +25,6 @@ extern unsigned doubleclick_time;
 
 int mplayer_get_key(int fd);
 void mplayer_put_key(int code);
+void mplayer_key_fifo_uninit(void);
 
 #endif /* MPLAYER_MP_FIFO_H */


More information about the MPlayer-cvslog mailing list