X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_cmdline%2Fcmdline.c;h=a9c47be3c9e30426c8069f7ae88582ea8c6627f5;hb=7d1acc9dde93;hp=6a55f1f5d493578b665516e693bdb5bd6571ba0a;hpb=067855e651d6141f01d328a9cb35fd53ba8af000;p=dpdk.git diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index 6a55f1f5d4..a9c47be3c9 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -130,6 +130,7 @@ struct cmdline * cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) { struct cmdline *cl; + int ret; if (!ctx || !prompt) return NULL; @@ -142,8 +143,13 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) cl->s_out = s_out; cl->ctx = ctx; - rdline_init(&cl->rdl, cmdline_write_char, - cmdline_valid_buffer, cmdline_complete_buffer); + ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer, + cmdline_complete_buffer); + if (ret != 0) { + free(cl); + return NULL; + } + cl->rdl.opaque = cl; cmdline_set_prompt(cl, prompt); rdline_newline(&cl->rdl, cl->prompt); @@ -193,8 +199,10 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) va_start(ap, fmt); ret = vsnprintf(buf, BUFSIZ, fmt, ap); va_end(ap); - if (ret < 0) + if (ret < 0) { + free(buf); return; + } if (ret >= BUFSIZ) ret = BUFSIZ - 1; write(cl->s_out, buf, ret);