summaryrefslogtreecommitdiff
path: root/src/sds.c
diff options
context:
space:
mode:
authorGuy Benoish <guy.benoish@redislabs.com>2019-02-12 14:21:21 +0100
committerGuy Benoish <guy.benoish@redislabs.com>2019-02-12 14:21:21 +0100
commitbdd9a8002a6fcc93135eb4125da703b87a1959fa (patch)
tree3efcf98a9a0f1e435b84efe0a88d2bcdaafcb34d /src/sds.c
parenta22815b4e9cfaf607378596d1ed715f71d6762c2 (diff)
downloadredis-bdd9a8002a6fcc93135eb4125da703b87a1959fa.tar.gz
Trim SDS free space of retained module strings
In some cases processMultibulkBuffer uses sdsMakeRoomFor to expand the querybuf, but later in some cases it uses that query buffer as is for an argv element (see "Optimization"), which means that the sds in argv may have a lot of wasted space, and then in case modules keep that argv RedisString inside their data structure, this space waste will remain for long (until restarted from rdb).
Diffstat (limited to 'src/sds.c')
-rw-r--r--src/sds.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/sds.c b/src/sds.c
index 330c955e8..cd60946bd 100644
--- a/src/sds.c
+++ b/src/sds.c
@@ -257,8 +257,12 @@ sds sdsRemoveFreeSpace(sds s) {
char type, oldtype = s[-1] & SDS_TYPE_MASK;
int hdrlen, oldhdrlen = sdsHdrSize(oldtype);
size_t len = sdslen(s);
+ size_t avail = sdsavail(s);
sh = (char*)s-oldhdrlen;
+ /* Return ASAP if there is no space left. */
+ if (avail == 0) return s;
+
/* Check what would be the minimum SDS header that is just good enough to
* fit this string. */
type = sdsReqType(len);