summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2020-01-10 13:02:45 +0100
committerantirez <antirez@gmail.com>2020-03-05 16:28:19 +0100
commitd90f599b4d94ee77ad651b5233032f147720c1e6 (patch)
treef3c48d6b63451dc04fcf2642e656f2e2a292e889
parent8ee3bddfc7792a8805a9da9eab9bba848a2b066b (diff)
downloadredis-d90f599b4d94ee77ad651b5233032f147720c1e6.tar.gz
Free fakeclient argv on AOF error.
We exit later, so no bug fixed, but it is more correct. See #6054, thanks to @ShooterIT for finding the issue.
-rw-r--r--src/aof.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/aof.c b/src/aof.c
index 96add97dd..d9db308bb 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -774,18 +774,24 @@ int loadAppendOnlyFile(char *filename) {
argc = atoi(buf+1);
if (argc < 1) goto fmterr;
+ /* Load the next command in the AOF as our fake client
+ * argv. */
argv = zmalloc(sizeof(robj*)*argc);
fakeClient->argc = argc;
fakeClient->argv = argv;
for (j = 0; j < argc; j++) {
- if (fgets(buf,sizeof(buf),fp) == NULL) {
+ /* Parse the argument len. */
+ if (fgets(buf,sizeof(buf),fp) == NULL ||
+ buf[0] != '$')
+ {
fakeClient->argc = j; /* Free up to j-1. */
freeFakeClientArgv(fakeClient);
goto readerr;
}
- if (buf[0] != '$') goto fmterr;
len = strtol(buf+1,NULL,10);
+
+ /* Read it into a string object. */
argsds = sdsnewlen(SDS_NOINIT,len);
if (len && fread(argsds,len,1,fp) == 0) {
sdsfree(argsds);
@@ -794,10 +800,12 @@ int loadAppendOnlyFile(char *filename) {
goto readerr;
}
argv[j] = createObject(OBJ_STRING,argsds);
+
+ /* Discard CRLF. */
if (fread(buf,2,1,fp) == 0) {
fakeClient->argc = j+1; /* Free up to j. */
freeFakeClientArgv(fakeClient);
- goto readerr; /* discard CRLF */
+ goto readerr;
}
}