diff --git a/src/object.c b/src/object.c index 853e36e5f41..1addb6364bd 100644 --- a/src/object.c +++ b/src/object.c @@ -286,6 +286,11 @@ void freeStringObject(robj *o) { sdsfree(o->ptr); } } +void freeStringObjectDram(robj *o) { + if (o->encoding == OBJ_ENCODING_RAW) { + sdsfreeDram(o->ptr); + } +} void freeListObject(robj *o) { if (o->encoding == OBJ_ENCODING_QUICKLIST) { @@ -356,7 +361,15 @@ void incrRefCount(robj *o) { static void _decrRefCount(robj *o, int on_dram) { if (o->refcount == 1) { switch(o->type) { - case OBJ_STRING: freeStringObject(o); break; + case OBJ_STRING: + if (on_dram == OBJ_MEMORY_GENERAL) { + freeStringObject(o); + } + else { + freeStringObjectDram(o); + } + break; + case OBJ_LIST: freeListObject(o); break; case OBJ_SET: freeSetObject(o); break; case OBJ_ZSET: freeZsetObject(o); break; diff --git a/src/sds.c b/src/sds.c index d7c657268f1..d0ddfe0c812 100644 --- a/src/sds.c +++ b/src/sds.c @@ -185,6 +185,12 @@ void sdsfree(sds s) { s_free((char*)s-sdsHdrSize(s[-1])); } +/* Free an sds string. No operation is performed if 's' is NULL. */ +void sdsfreeDram(sds s) { + if (s == NULL) return; + s_freeDram((char*)s-sdsHdrSize(s[-1])); +} + /* Set the sds string length to the length as obtained with strlen(), so * considering as content only up to the first null term character. * diff --git a/src/sds.h b/src/sds.h index 5bdeedad78c..f667a2b8ee1 100644 --- a/src/sds.h +++ b/src/sds.h @@ -221,6 +221,7 @@ sds sdsempty(void); sds sdsdramempty(void); sds sdsdup(const sds s); void sdsfree(sds s); +void sdsfreeDram(sds s); sds sdsgrowzero(sds s, size_t len); sds sdscatlen(sds s, const void *t, size_t len); sds sdscat(sds s, const char *t); diff --git a/src/sdsalloc.h b/src/sdsalloc.h index 7c7a6a80f09..2a11563669a 100644 --- a/src/sdsalloc.h +++ b/src/sdsalloc.h @@ -43,6 +43,7 @@ #define s_malloc zmalloc #define s_realloc zrealloc #define s_free zfree +#define s_freeDram zfree_dram #define s_dram_malloc zmalloc_dram #endif diff --git a/src/server.h b/src/server.h index f54cdc630a0..063b0d817aa 100644 --- a/src/server.h +++ b/src/server.h @@ -1724,6 +1724,7 @@ void incrRefCount(robj *o); robj *makeObjectShared(robj *o); robj *resetRefCount(robj *obj); void freeStringObject(robj *o); +void freeStringObjectDram(robj *o); void freeListObject(robj *o); void freeSetObject(robj *o); void freeZsetObject(robj *o);