summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-04-03 18:04:15 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-04-03 18:04:15 +0200
commit421eec9a4dc6bb6b6fc17b9f6a923963f7623850 (patch)
tree0529a6627497dd667e0e333ced460140ea284d11
parent921150fc8a94276cb9a8d76d80f82a5872e29139 (diff)
Lazily destroy protocol reader buffer
-rw-r--r--hiredis.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/hiredis.c b/hiredis.c
index 7bbede6..f2135ba 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -520,6 +520,13 @@ void redisReplyReaderFeed(void *reader, const char *buf, size_t len) {
/* Copy the provided buffer. */
if (buf != NULL && len >= 1) {
+ /* Destroy internal buffer when it is empty and is quite large. */
+ if (r->len == 0 && sdsavail(r->buf) > 16*1024) {
+ sdsfree(r->buf);
+ r->buf = sdsempty();
+ r->pos = 0;
+ }
+
r->buf = sdscatlen(r->buf,buf,len);
r->len = sdslen(r->buf);
}
@@ -562,13 +569,6 @@ int redisReplyReaderGetReply(void *reader, void **reply) {
void *aux = r->reply;
r->reply = NULL;
- /* Destroy the buffer when it is empty and is quite large. */
- if (r->len == 0 && sdsavail(r->buf) > 16*1024) {
- sdsfree(r->buf);
- r->buf = sdsempty();
- r->pos = 0;
- }
-
/* Check if there actually *is* a reply. */
if (r->error != NULL) {
return REDIS_ERR;