Mercurial > dropbear
changeset 709:abd99ecd7ec2
use an empty writebuf rather than a NULL one
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 20 Mar 2013 22:31:07 +0800 |
parents | b207d5183bb7 |
children | 91dd8328a3ff |
files | circbuffer.c common-channel.c |
diffstat | 2 files changed, 10 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/circbuffer.c Wed Mar 20 00:05:19 2013 +0800 +++ b/circbuffer.c Wed Mar 20 22:31:07 2013 +0800 @@ -37,7 +37,9 @@ } cbuf = (circbuffer*)m_malloc(sizeof(circbuffer)); - cbuf->data = (unsigned char*)m_malloc(size); + if (size > 0) { + cbuf->data = (unsigned char*)m_malloc(size); + } cbuf->used = 0; cbuf->readpos = 0; cbuf->writepos = 0;
--- a/common-channel.c Wed Mar 20 00:05:19 2013 +0800 +++ b/common-channel.c Wed Mar 20 22:31:07 2013 +0800 @@ -95,7 +95,8 @@ static void chan_initwritebuf(struct Channel *channel) { - dropbear_assert(channel->writebuf == NULL && channel->recvwindow == 0); + dropbear_assert(channel->writebuf->size == 0 && channel->recvwindow == 0); + cbuf_free(channel->writebuf); channel->writebuf = cbuf_new(opts.recv_window); channel->recvwindow = opts.recv_window; } @@ -159,7 +160,7 @@ newchan->await_open = 0; newchan->flushing = 0; - newchan->writebuf = NULL; + newchan->writebuf = cbuf_new(0); /* resized later by chan_initwritebuf */ newchan->recvwindow = 0; newchan->extrabuf = NULL; /* The user code can set it up */ @@ -233,7 +234,6 @@ continue; /* Important not to use the channel after check_in_progress(), as it may be NULL */ } - dropbear_assert(channel->writebuf); writechannel(channel, channel->writefd, channel->writebuf); } @@ -259,9 +259,7 @@ * stderr of a channel's endpoint. */ static unsigned int write_pending(struct Channel * channel) { - if (channel->writefd >= 0 - && channel->writebuf - && cbuf_getused(channel->writebuf) > 0) { + if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) { return 1; } else if (channel->errfd >= 0 && channel->extrabuf && cbuf_getused(channel->extrabuf) > 0) { @@ -452,8 +450,7 @@ } dropbear_assert(channel->recvwindow <= opts.recv_window); - dropbear_assert(channel->writebuf == NULL || - channel->recvwindow <= cbuf_getavail(channel->writebuf)); + dropbear_assert(channel->recvwindow <= cbuf_getavail(channel->writebuf)); dropbear_assert(channel->extrabuf == NULL || channel->recvwindow <= cbuf_getavail(channel->extrabuf)); @@ -546,10 +543,8 @@ TRACE(("enter remove_channel")) TRACE(("channel index is %d", channel->index)) - if (channel->writebuf) { - cbuf_free(channel->writebuf); - channel->writebuf = NULL; - } + cbuf_free(channel->writebuf); + channel->writebuf = NULL; if (channel->extrabuf) { cbuf_free(channel->extrabuf);