summaryrefslogtreecommitdiff
path: root/src/t_string.c
diff options
context:
space:
mode:
authorhwware <wen.hui.ware@gmail.com>2020-06-08 23:48:51 -0400
committerhwware <wen.hui.ware@gmail.com>2020-06-11 09:56:52 -0400
commit7008a0ba66fe13af0d584071eaa5fe3f34c56512 (patch)
treee294e6fb7f3e495cb83711f2ff6ff5597182d042 /src/t_string.c
parent2a05fa0d481d12d3747465c4f14470bdca100c5d (diff)
downloadredis-7008a0ba66fe13af0d584071eaa5fe3f34c56512.tar.gz
fix memory leak
Diffstat (limited to 'src/t_string.c')
-rw-r--r--src/t_string.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/t_string.c b/src/t_string.c
index d1a3e1b96..8e367ec80 100644
--- a/src/t_string.c
+++ b/src/t_string.c
@@ -516,13 +516,13 @@ void stralgoLCS(client *c) {
withmatchlen = 1;
} else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) {
if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL)
- != C_OK) return;
+ != C_OK) goto clean_up_obj;
if (minmatchlen < 0) minmatchlen = 0;
j++;
} else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) {
if (a != NULL) {
addReplyError(c,"Either use STRINGS or KEYS");
- return;
+ goto clean_up_obj;
}
a = c->argv[j+1]->ptr;
b = c->argv[j+2]->ptr;
@@ -530,17 +530,14 @@ void stralgoLCS(client *c) {
} else if (!strcasecmp(opt,"KEYS") && moreargs > 1) {
if (a != NULL) {
addReplyError(c,"Either use STRINGS or KEYS");
- return;
+ goto clean_up_obj;
}
obja = lookupKeyRead(c->db,c->argv[j+1]);
objb = lookupKeyRead(c->db,c->argv[j+2]);
-
if ( !(obja->type == OBJ_STRING) || !(objb->type == OBJ_STRING) ) {
addReplyError(c,"Object associate with KEYS option should only be string type");
- return;
-
+ goto clean_up_obj;
}
-
obja = obja ? getDecodedObject(obja) : createStringObject("",0);
objb = objb ? getDecodedObject(objb) : createStringObject("",0);
a = obja->ptr;
@@ -548,7 +545,7 @@ void stralgoLCS(client *c) {
j += 2;
} else {
addReply(c,shared.syntaxerr);
- return;
+ goto clean_up_obj;
}
}
@@ -556,12 +553,12 @@ void stralgoLCS(client *c) {
if (a == NULL) {
addReplyError(c,"Please specify two strings: "
"STRINGS or KEYS options are mandatory");
- return;
+ goto clean_up_obj;
} else if (getlen && getidx) {
addReplyError(c,
"If you want both the length and indexes, please "
"just use IDX.");
- return;
+ goto clean_up_obj;
}
/* Compute the LCS using the vanilla dynamic programming technique of
@@ -696,10 +693,12 @@ void stralgoLCS(client *c) {
}
/* Cleanup. */
- if (obja) decrRefCount(obja);
- if (objb) decrRefCount(objb);
sdsfree(result);
zfree(lcs);
+
+clean_up_obj:
+ if (obja) decrRefCount(obja);
+ if (objb) decrRefCount(objb);
return;
}