summaryrefslogtreecommitdiff
path: root/async.c
diff options
context:
space:
mode:
authorJan-Erik Rediger <badboy@archlinux.us>2014-12-09 00:45:56 +0100
committerMatt Stancliff <matt@genges.com>2015-01-05 11:21:38 -0500
commit2a6dbdd2252a038546f1c911957644df2a7d4fba (patch)
tree3de57274c9c6b48f197e95f9ecc08cc9a100549f /async.c
parenta1f6ce019462644c7e68012d70fde9b5ab49687e (diff)
Free string if it is unused
If the string is already in the dict, we need to free this. Original fix by @tt33415366. Fixes #256 Closes #286
Diffstat (limited to 'async.c')
-rw-r--r--async.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/async.c b/async.c
index f7f343b..3aace8f 100644
--- a/async.c
+++ b/async.c
@@ -575,6 +575,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
size_t clen, alen;
char *p;
sds sname;
+ int ret;
/* Don't accept new commands when the connection is about to be closed. */
if (c->flags & (REDIS_DISCONNECTING | REDIS_FREEING)) return REDIS_ERR;
@@ -598,9 +599,11 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
while ((p = nextArgument(p,&astr,&alen)) != NULL) {
sname = sdsnewlen(astr,alen);
if (pvariant)
- dictReplace(ac->sub.patterns,sname,&cb);
+ ret = dictReplace(ac->sub.patterns,sname,&cb);
else
- dictReplace(ac->sub.channels,sname,&cb);
+ ret = dictReplace(ac->sub.channels,sname,&cb);
+
+ if (ret == 0) sdsfree(sname);
}
} else if (strncasecmp(cstr,"unsubscribe\r\n",13) == 0) {
/* It is only useful to call (P)UNSUBSCRIBE when the context is