cmdline: check initialization error
The value returned by rdline_init() was not checked in cmdline_new(). On error, free the allocated memory and return NULL. This condition should not happen today, but it's safer to do the check in case rdline_init() is updated. Coverity issue: 13204 Fixes: af75078fece3 ("first public release") Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
parent
e114696200
commit
661d97ba0b
@ -130,6 +130,7 @@ struct cmdline *
|
|||||||
cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
|
cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
|
||||||
{
|
{
|
||||||
struct cmdline *cl;
|
struct cmdline *cl;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!ctx || !prompt)
|
if (!ctx || !prompt)
|
||||||
return NULL;
|
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->s_out = s_out;
|
||||||
cl->ctx = ctx;
|
cl->ctx = ctx;
|
||||||
|
|
||||||
rdline_init(&cl->rdl, cmdline_write_char,
|
ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
|
||||||
cmdline_valid_buffer, cmdline_complete_buffer);
|
cmdline_complete_buffer);
|
||||||
|
if (ret != 0) {
|
||||||
|
free(cl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cl->rdl.opaque = cl;
|
cl->rdl.opaque = cl;
|
||||||
cmdline_set_prompt(cl, prompt);
|
cmdline_set_prompt(cl, prompt);
|
||||||
rdline_newline(&cl->rdl, cl->prompt);
|
rdline_newline(&cl->rdl, cl->prompt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user