Use the free-trailing-chains function in evbuffer_insert_chain too

This commit is contained in:
Nick Mathewson 2011-11-02 22:50:47 -04:00
parent c37069cd79
commit b18c04dd74

View File

@ -290,21 +290,11 @@ evbuffer_chain_insert(struct evbuffer *buf,
EVUTIL_ASSERT(buf->first == NULL);
buf->first = buf->last = chain;
} else {
struct evbuffer_chain **ch = buf->last_with_datap;
/* Find the first victim chain. It might be *last_with_datap */
while ((*ch) && ((*ch)->off != 0 || CHAIN_PINNED(*ch)))
ch = &(*ch)->next;
if (*ch == NULL) {
/* There is no victim; just append this new chain. */
buf->last->next = chain;
if (chain->off)
buf->last_with_datap = &buf->last->next;
} else {
/* Replace all victim chains with this chain. */
EVUTIL_ASSERT(evbuffer_chains_all_empty(*ch));
evbuffer_free_all_chains(*ch);
*ch = chain;
}
struct evbuffer_chain **chp;
chp = evbuffer_free_trailing_empty_chains(buf);
*chp = chain;
if (chain->off)
buf->last_with_datap = chp;
buf->last = chain;
}
buf->total_len += chain->off;