summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2020-01-10 13:02:45 +0100
committerantirez <antirez@gmail.com>2020-01-10 13:02:45 +0100
commit9466dae4e5377056cd27fcdb0f4b47a5497bb08d (patch)
tree6257a2b9629c06a243f5371a3e053f8b7d306d93
parent5234bff5790581c7d52e668e65b87a5beac1863e (diff)
downloadredis-9466dae4e5377056cd27fcdb0f4b47a5497bb08d.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 0ef59cfb6..9c2fa838b 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -781,18 +781,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);
@@ -801,10 +807,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;
}
}