changeset 36361:0caa0bf428b9

Fix a few memleaks.
author reimar
date Sun, 22 Sep 2013 08:34:08 +0000
parents 505fcd136e73
children 99708d402208
files command.c input/input.c libmpcodecs/vd_ffmpeg.c mp_fifo.c mp_fifo.h
diffstat 5 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/command.c	Sun Sep 22 07:31:55 2013 +0000
+++ b/command.c	Sun Sep 22 08:34:08 2013 +0000
@@ -2762,10 +2762,11 @@
             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;
--- a/input/input.c	Sun Sep 22 07:31:55 2013 +0000
+++ b/input/input.c	Sun Sep 22 08:34:08 2013 +0000
@@ -1383,10 +1383,12 @@
 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 @@
     }
   }
 
-  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 @@
 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 @@
     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
--- a/libmpcodecs/vd_ffmpeg.c	Sun Sep 22 07:31:55 2013 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Sun Sep 22 08:34:08 2013 +0000
@@ -922,7 +922,7 @@
     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.
--- a/mp_fifo.c	Sun Sep 22 07:31:55 2013 +0000
+++ b/mp_fifo.c	Sun Sep 22 08:34:08 2013 +0000
@@ -101,3 +101,11 @@
       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;
+}
--- a/mp_fifo.h	Sun Sep 22 07:31:55 2013 +0000
+++ b/mp_fifo.h	Sun Sep 22 08:34:08 2013 +0000
@@ -25,5 +25,6 @@
 
 int mplayer_get_key(int fd);
 void mplayer_put_key(int code);
+void mplayer_key_fifo_uninit(void);
 
 #endif /* MPLAYER_MP_FIFO_H */