Skip to content

Commit

Permalink
Merge pull request #28 from orgads/realloc-failure
Browse files Browse the repository at this point in the history
Free buffer if realloc fails
  • Loading branch information
dparrish committed Jan 27, 2018
2 parents 447ca52 + ae73c4b commit e114e6c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libcli.c
Expand Up @@ -1993,10 +1993,16 @@ static void _print(struct cli_def *cli, int print_mode, const char *format, va_l

if ((unsigned)n >= cli->buf_size)
{
char *newbuf;
cli->buf_size = n + 1;
cli->buffer = realloc(cli->buffer, cli->buf_size);
if (!cli->buffer)
newbuf = (char*)realloc(cli->buffer, cli->buf_size);
if (!newbuf)
{
free(cli->buffer);
cli->buffer = NULL;
return;
}
cli->buffer = newbuf;
va_end(ap);
va_copy(ap, aq);
continue;
Expand Down

0 comments on commit e114e6c

Please sign in to comment.