summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Sundberg <marcus@marcussundberg.com>2016-03-26 20:11:43 +0100
committerMarcus Sundberg <marcus@marcussundberg.com>2016-03-26 20:49:27 +0100
commitb00db82a83a1ee69f9b9371ccdfa715d4b678ba7 (patch)
treec55c81fd5f5c47779148b08932027a80ef77c1d3
parent0e894fb7f383f943f126d2c7d76977c3e09474d2 (diff)
downloadlibevent-b00db82a83a1ee69f9b9371ccdfa715d4b678ba7.tar.gz
evbuffer_add: Use last_with_datap if set, not last.
evbuffer_add() would always put data in the last chain, even if there was available space in a previous chain, and in doing so it also failed to update last_with_datap, causing subsequent calls to other functions that do look at last_with_datap to add data in the middle of the evbuffer instead of at the end. Fixes the evbuffer_add() part of issue #335, and the evbuffer/add2 and evbuffer/add3 tests, and also prevents wasting space available in the chain pointed to by last_with_datap.
-rw-r--r--buffer.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index f615abc1..cda94458 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1548,7 +1548,11 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
goto done;
}
- chain = buf->last;
+ if (*buf->last_with_datap == NULL) {
+ chain = buf->last;
+ } else {
+ chain = *buf->last_with_datap;
+ }
/* If there are no chains allocated for this buffer, allocate one
* big enough to hold all the data. */