diff --git a/src/aof.c b/src/aof.c index 8dc1dd1881f1f221dd1a777c0eac65424b4d1885..2265222cc6dbf3e592dc810bcdfa2a700745cb82 100644 --- a/src/aof.c +++ b/src/aof.c @@ -456,7 +456,7 @@ struct redisClient *createFakeClient(void) { c->reply_bytes = 0; c->obuf_soft_limit_reached_time = 0; c->watched_keys = listCreate(); - listSetFreeMethod(c->reply,decrRefCount); + listSetFreeMethod(c->reply,decrRefCountVoid); listSetDupMethod(c->reply,dupClientReplyValue); initClientMultiState(c); return c; diff --git a/src/networking.c b/src/networking.c index 6e5d32489861b802643259218061827ab2f0a621..0853ad923001e39d62a412cf0d408cd1ba7326f6 100644 --- a/src/networking.c +++ b/src/networking.c @@ -89,17 +89,17 @@ redisClient *createClient(int fd) { c->reply = listCreate(); c->reply_bytes = 0; c->obuf_soft_limit_reached_time = 0; - listSetFreeMethod(c->reply,decrRefCount); + listSetFreeMethod(c->reply,decrRefCountVoid); listSetDupMethod(c->reply,dupClientReplyValue); c->bpop.keys = dictCreate(&setDictType,NULL); c->bpop.timeout = 0; c->bpop.target = NULL; c->io_keys = listCreate(); c->watched_keys = listCreate(); - listSetFreeMethod(c->io_keys,decrRefCount); + listSetFreeMethod(c->io_keys,decrRefCountVoid); c->pubsub_channels = dictCreate(&setDictType,NULL); c->pubsub_patterns = listCreate(); - listSetFreeMethod(c->pubsub_patterns,decrRefCount); + listSetFreeMethod(c->pubsub_patterns,decrRefCountVoid); listSetMatchMethod(c->pubsub_patterns,listMatchObjects); if (fd != -1) listAddNodeTail(server.clients,c); initClientMultiState(c); diff --git a/src/object.c b/src/object.c index 00cf023b07f9dc91cef6bcca00b3a568ea62a2cc..bb5f6729d80d2029883f2fb1bacf6c44077c01c1 100644 --- a/src/object.c +++ b/src/object.c @@ -215,9 +215,7 @@ void incrRefCount(robj *o) { o->refcount++; } -void decrRefCount(void *obj) { - robj *o = obj; - +void decrRefCount(robj *o) { if (o->refcount <= 0) redisPanic("decrRefCount against refcount <= 0"); if (o->refcount == 1) { switch(o->type) { @@ -234,6 +232,13 @@ void decrRefCount(void *obj) { } } +/* This variant of decrRefCount() gets its argument as void, and is useful + * as free method in data structures that expect a 'void free_object(void*)' + * prototype for the free method. */ +void decrRefCountVoid(void *o) { + decrRefCount(o); +} + /* This function set the ref count to zero without freeing the object. * It is useful in order to pass a new object to functions incrementing * the ref count of the received object. Example: diff --git a/src/redis.h b/src/redis.h index eb70516db938e1312381817f7d822c066932ae99..97d49d51189be8a7c6d369aa52ca32265db9b7da 100644 --- a/src/redis.h +++ b/src/redis.h @@ -989,7 +989,8 @@ void discardTransaction(redisClient *c); void flagTransaction(redisClient *c); /* Redis object implementation */ -void decrRefCount(void *o); +void decrRefCount(robj *o); +void decrRefCountVoid(void *o); void incrRefCount(robj *o); robj *resetRefCount(robj *obj); void freeStringObject(robj *o); diff --git a/src/t_list.c b/src/t_list.c index 16b5e1be52200f3e05c6359c16b53d1ec1294221..d3d3f6c69f5e344c600fa01261d591008e6d5aaf 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -275,7 +275,7 @@ void listTypeConvert(robj *subject, int enc) { if (enc == REDIS_ENCODING_LINKEDLIST) { list *l = listCreate(); - listSetFreeMethod(l,decrRefCount); + listSetFreeMethod(l,decrRefCountVoid); /* listTypeGet returns a robj with incremented refcount */ li = listTypeInitIterator(subject,0,REDIS_TAIL);