mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 12:28:19 -04:00
Remove one last bug in last_with_datap logic. Found with valgrind
This commit is contained in:
parent
9d8edf2ff5
commit
d49b92a835
5
buffer.c
5
buffer.c
@ -1010,7 +1010,7 @@ done:
|
|||||||
unsigned char *
|
unsigned char *
|
||||||
evbuffer_pullup(struct evbuffer *buf, ev_ssize_t size)
|
evbuffer_pullup(struct evbuffer *buf, ev_ssize_t size)
|
||||||
{
|
{
|
||||||
struct evbuffer_chain *chain, *next, *tmp;
|
struct evbuffer_chain *chain, *next, *tmp, *last_with_data;
|
||||||
unsigned char *buffer, *result = NULL;
|
unsigned char *buffer, *result = NULL;
|
||||||
ev_ssize_t remaining;
|
ev_ssize_t remaining;
|
||||||
int removed_last_with_data = 0;
|
int removed_last_with_data = 0;
|
||||||
@ -1078,13 +1078,14 @@ evbuffer_pullup(struct evbuffer *buf, ev_ssize_t size)
|
|||||||
/* TODO(niels): deal with buffers that point to NULL like sendfile */
|
/* TODO(niels): deal with buffers that point to NULL like sendfile */
|
||||||
|
|
||||||
/* Copy and free every chunk that will be entirely pulled into tmp */
|
/* Copy and free every chunk that will be entirely pulled into tmp */
|
||||||
|
last_with_data = *buf->last_with_datap;
|
||||||
for (; chain != NULL && (size_t)size >= chain->off; chain = next) {
|
for (; chain != NULL && (size_t)size >= chain->off; chain = next) {
|
||||||
next = chain->next;
|
next = chain->next;
|
||||||
|
|
||||||
memcpy(buffer, chain->buffer + chain->misalign, chain->off);
|
memcpy(buffer, chain->buffer + chain->misalign, chain->off);
|
||||||
size -= chain->off;
|
size -= chain->off;
|
||||||
buffer += chain->off;
|
buffer += chain->off;
|
||||||
if (chain == *buf->last_with_datap)
|
if (chain == last_with_data)
|
||||||
removed_last_with_data = 1;
|
removed_last_with_data = 1;
|
||||||
if (&chain->next == buf->last_with_datap)
|
if (&chain->next == buf->last_with_datap)
|
||||||
removed_last_with_datap = 1;
|
removed_last_with_datap = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user