From 174e9fe80948f8a7bdd42fe122083d1f1a3f9e0d Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 22 Feb 2019 17:45:50 -0500 Subject: [PATCH] fix corruption in object size optimization --- src/object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/object.c b/src/object.c index 97d4887ae..88efba4d5 100644 --- a/src/object.c +++ b/src/object.c @@ -82,7 +82,10 @@ robj *createRawStringObject(const char *ptr, size_t len) { * an object where the sds string is actually an unmodifiable string * allocated in the same chunk as the object itself. */ robj *createEmbeddedStringObject(const char *ptr, size_t len) { - robj *o = zmalloc(sizeof(robj)+sizeof(struct sdshdr8)+len+1-sizeof(o->m_ptr), MALLOC_SHARED); + size_t alloclen = len; + if (len < sizeof(void*)) + alloclen = sizeof(void*); + robj *o = zmalloc(sizeof(robj)+sizeof(struct sdshdr8)+alloclen+1-sizeof(o->m_ptr), MALLOC_SHARED); struct sdshdr8 *sh = (void*)(&o->m_ptr); o->type = OBJ_STRING;