diff options
author | dormando <dormando@rydia.net> | 2020-12-08 00:02:41 -0800 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2020-12-11 13:55:21 -0800 |
commit | 585d03f198c5907c9a07f97fa89bb7b9851a874e (patch) | |
tree | 1a4abcf44c5e698e41a65dc155dda45db8ab4ae8 /memcached.c | |
parent | c472369fed5981ba8c004d426cee62d5165c47ca (diff) | |
download | memcached-585d03f198c5907c9a07f97fa89bb7b9851a874e.tar.gz |
core: support malloc'ed blobs for body read
conn_nread state handles c->item like an item, but allow it to be a
temporary malloced blob via setting c->item_malloced = true.
to be used for buffering value reads in the proxy code.
Diffstat (limited to 'memcached.c')
-rw-r--r-- | memcached.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/memcached.c b/memcached.c index b4bac62..d4e1f0c 100644 --- a/memcached.c +++ b/memcached.c @@ -704,6 +704,7 @@ conn *conn_new(const int sfd, enum conn_states init_state, c->rcurr = c->rbuf; c->ritem = 0; c->rbuf_malloced = false; + c->item_malloced = false; c->sasl_started = false; c->set_stale = false; c->mset_res = false; @@ -783,7 +784,12 @@ void conn_release_items(conn *c) { assert(c != NULL); if (c->item) { - item_remove(c->item); + if (c->item_malloced) { + free(c->item); + c->item_malloced = false; + } else { + item_remove(c->item); + } c->item = 0; } @@ -1344,7 +1350,12 @@ static void reset_cmd_handler(conn *c) { if (c->item != NULL) { // TODO: Any other way to get here? // SASL auth was mistakenly using it. Nothing else should? - item_remove(c->item); + if (c->item_malloced) { + free(c->item); + c->item_malloced = false; + } else { + item_remove(c->item); + } c->item = NULL; } if (c->rbytes > 0) { @@ -3070,7 +3081,7 @@ static void drive_machine(conn *c) { break; } - if ((((item *)c->item)->it_flags & ITEM_CHUNKED) == 0) { + if (c->item_malloced || ((((item *)c->item)->it_flags & ITEM_CHUNKED) == 0) ) { /* first check if we have leftovers in the conn_read buffer */ if (c->rbytes > 0) { int tocopy = c->rbytes > c->rlbytes ? c->rlbytes : c->rbytes; |