From 42b11f05e5c087fcc34579f2e8a807fa8330b6ca Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Thu, 14 Feb 2013 18:11:53 +0100 Subject: cli: Fix "show sessions" if no column to display Gracefully handle the case where no column has been selected for the "show sessions" command. Such situation will be possible once the set of default displayed columns will be made configurable from accel-ppp.conf. Signed-off-by: Guillaume Nault --- accel-pppd/cli/show_sessions.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'accel-pppd/cli') diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c index 5bfe09ba..33c8f92c 100644 --- a/accel-pppd/cli/show_sessions.c +++ b/accel-pppd/cli/show_sessions.c @@ -273,11 +273,15 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli) continue; total_width += col->width + 3; } - + + if (total_width < 0) + /* No column to print */ + goto early_out; + buf = _malloc(total_width + 3); if (!buf) goto oom; - + ptr1 = buf; list_for_each_entry(col, &c_list, entry) { if (col->hidden) @@ -356,6 +360,8 @@ out: return CLI_CMD_OK; oom: + cli_send(cli, "out of memory"); +early_out: if (buf) _free(buf); @@ -364,7 +370,6 @@ oom: list_del(&row->entry); free_row(row); } - cli_send(cli, "out of memory"); goto out; } -- cgit v1.2.3