X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/7c0e1b53c4c4f646c788fcd09666e1c321c1d134..4ff34b6adb9f5f9daad1f27e3aac8e016554b86c:/src/object.c diff --git a/src/object.c b/src/object.c index c7c90c54..20e7f57a 100644 --- a/src/object.c +++ b/src/object.c @@ -180,7 +180,7 @@ void decrRefCount(void *obj) { robj *o = obj; if (o->refcount <= 0) redisPanic("decrRefCount against refcount <= 0"); - if (--(o->refcount) == 0) { + if (o->refcount == 1) { switch(o->type) { case REDIS_STRING: freeStringObject(o); break; case REDIS_LIST: freeListObject(o); break; @@ -189,8 +189,9 @@ void decrRefCount(void *obj) { case REDIS_HASH: freeHashObject(o); break; default: redisPanic("Unknown object type"); break; } - o->ptr = NULL; /* defensive programming. We'll see NULL in traces. */ zfree(o); + } else { + o->refcount--; } } @@ -202,6 +203,16 @@ int checkType(redisClient *c, robj *o, int type) { return 0; } +int isObjectRepresentableAsLongLong(robj *o, long long *llval) { + redisAssert(o->type == REDIS_STRING); + if (o->encoding == REDIS_ENCODING_INT) { + if (llval) *llval = (long) o->ptr; + return REDIS_OK; + } else { + return string2ll(o->ptr,sdslen(o->ptr),llval) ? REDIS_OK : REDIS_ERR; + } +} + /* Try to encode a string object in order to save space */ robj *tryObjectEncoding(robj *o) { long value; @@ -219,7 +230,7 @@ robj *tryObjectEncoding(robj *o) { redisAssert(o->type == REDIS_STRING); /* Check if we can represent this string as a long integer */ - if (isStringRepresentableAsLong(s,&value) == REDIS_ERR) return o; + if (!string2l(s,sdslen(s),&value)) return o; /* Ok, this object can be encoded... *