Do not use evbuffer_expand() to add the first chain to a buffer

(It's a big function, and using it this way is overkill.)
This commit is contained in:
Nick Mathewson 2010-03-26 14:50:45 -04:00
parent 2014ae4ac6
commit 5c0ebb33f4

View File

@ -1310,9 +1310,10 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
/* If there are no chains allocated for this buffer, allocate one /* If there are no chains allocated for this buffer, allocate one
* big enough to hold all the data. */ * big enough to hold all the data. */
if (chain == NULL) { if (chain == NULL) {
if (evbuffer_expand(buf, datlen) == -1) chain = evbuffer_chain_new(datlen);
if (!chain)
goto done; goto done;
chain = buf->last; evbuffer_chain_insert(buf, chain);
} }
if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) {
@ -1389,10 +1390,10 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen)
chain = buf->first; chain = buf->first;
if (chain == NULL) { if (chain == NULL) {
if (evbuffer_expand(buf, datlen) == -1) chain = evbuffer_chain_new(datlen);
if (!chain)
goto done; goto done;
chain = buf->first; evbuffer_chain_insert(buf, chain);
chain->misalign = chain->buffer_len;
} }
/* we cannot touch immutable buffers */ /* we cannot touch immutable buffers */