Skip to content

Commit

Permalink
Fix a few memleaks.
Browse files Browse the repository at this point in the history
git-svn-id: svn://git.mplayerhq.hu/mplayer/trunk@36457 b3059339-0415-0410-9bf9-f77b7e298cf2
  • Loading branch information
reimar committed Sep 22, 2013
1 parent 4e21fcc commit ee3a92b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
9 changes: 5 additions & 4 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2762,10 +2762,11 @@ int run_command(MPContext *mpctx, mp_cmd_t *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;
Expand Down
23 changes: 18 additions & 5 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1411,8 +1413,13 @@ mp_input_get_cmd(int time, int paused, int peek_only) {
}
}

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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libmpcodecs/vd_ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ static mp_image_t *decode(sh_video_t *sh, void *data, int len, int flags){
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.
Expand Down
8 changes: 8 additions & 0 deletions mp_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions mp_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit ee3a92b

Please sign in to comment.