From a6bfa0d20a5d93bd14db48f0d82f7e570cdf834d Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Sat, 8 Nov 2014 18:17:13 +0000 Subject: chan_console: Fix reference leaks to pvt. Fix a bunch of calls to get_active_pvt where the reference is never released. ASTERISK-24504 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/4152/ ........ Merged revisions 427554 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 427555 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@427557 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_console.c | 64 ++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/channels/chan_console.c b/channels/chan_console.c index c34a6c45d..74f2922eb 100644 --- a/channels/chan_console.c +++ b/channels/chan_console.c @@ -712,7 +712,7 @@ static struct console_pvt *get_active_pvt(void) static char *cli_console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; char *res = CLI_SUCCESS; switch (cmd) { @@ -729,6 +729,7 @@ static char *cli_console_autoanswer(struct ast_cli_entry *e, int cmd, return NULL; } + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is set as active.\n"); return CLI_FAILURE; @@ -759,7 +760,7 @@ static char *cli_console_autoanswer(struct ast_cli_entry *e, int cmd, static char *cli_console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; if (cmd == CLI_INIT) { e->command = "console flash"; @@ -767,17 +768,20 @@ static char *cli_console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_ "Usage: console flash\n" " Flashes the call currently placed on the console.\n"; return NULL; - } else if (cmd == CLI_GENERATE) + } else if (cmd == CLI_GENERATE) { return NULL; + } + if (a->argc != e->args) { + return CLI_SHOWUSAGE; + } + + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is set as active\n"); return CLI_FAILURE; } - if (a->argc != e->args) - return CLI_SHOWUSAGE; - if (!pvt->owner) { ast_cli(a->fd, "No call to flash\n"); unref_pvt(pvt); @@ -797,7 +801,7 @@ static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_a { char *s = NULL; const char *mye = NULL, *myc = NULL; - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; if (cmd == CLI_INIT) { e->command = "console dial"; @@ -805,16 +809,19 @@ static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_a "Usage: console dial [extension[@context]]\n" " Dials a given extension (and context if specified)\n"; return NULL; - } else if (cmd == CLI_GENERATE) + } else if (cmd == CLI_GENERATE) { return NULL; + } + + if (a->argc > e->args + 1) { + return CLI_SHOWUSAGE; + } + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is currently set as active\n"); return CLI_FAILURE; } - - if (a->argc > e->args + 1) - return CLI_SHOWUSAGE; if (pvt->owner) { /* already in a call */ int i; @@ -869,7 +876,7 @@ static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_a static char *cli_console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; if (cmd == CLI_INIT) { e->command = "console hangup"; @@ -877,16 +884,19 @@ static char *cli_console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli "Usage: console hangup\n" " Hangs up any call currently placed on the console.\n"; return NULL; - } else if (cmd == CLI_GENERATE) + } else if (cmd == CLI_GENERATE) { return NULL; + } + if (a->argc != e->args) { + return CLI_SHOWUSAGE; + } + + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is set as active\n"); return CLI_FAILURE; } - - if (a->argc != e->args) - return CLI_SHOWUSAGE; if (!pvt->owner && !pvt->hookstate) { ast_cli(a->fd, "No call to hang up\n"); @@ -906,7 +916,7 @@ static char *cli_console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli static char *cli_console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { const char *s; - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; char *res = CLI_SUCCESS; if (cmd == CLI_INIT) { @@ -915,17 +925,20 @@ static char *cli_console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_a "Usage: console {mute|unmute}\n" " Mute/unmute the microphone.\n"; return NULL; - } else if (cmd == CLI_GENERATE) + } else if (cmd == CLI_GENERATE) { return NULL; + } + if (a->argc != e->args) { + return CLI_SHOWUSAGE; + } + + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is set as active\n"); return CLI_FAILURE; } - if (a->argc != e->args) - return CLI_SHOWUSAGE; - s = a->argv[e->args-1]; if (!strcasecmp(s, "mute")) pvt->muted = 1; @@ -1053,7 +1066,7 @@ static char *cli_list_devices(struct ast_cli_entry *e, int cmd, struct ast_cli_a */ static char *cli_console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; switch (cmd) { case CLI_INIT: @@ -1067,6 +1080,7 @@ static char *cli_console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli return NULL; /* no completion */ } + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is set as active\n"); return CLI_FAILURE; @@ -1103,7 +1117,7 @@ static char *cli_console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli static char *cli_console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { char buf[TEXT_SIZE]; - struct console_pvt *pvt = get_active_pvt(); + struct console_pvt *pvt; struct ast_frame f = { .frametype = AST_FRAME_TEXT, .data.ptr = buf, @@ -1117,9 +1131,11 @@ static char *cli_console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_c "Usage: console send text \n" " Sends a text message for display on the remote terminal.\n"; return NULL; - } else if (cmd == CLI_GENERATE) + } else if (cmd == CLI_GENERATE) { return NULL; + } + pvt = get_active_pvt(); if (!pvt) { ast_cli(a->fd, "No console device is set as active\n"); return CLI_FAILURE; -- cgit v1.2.3