diff options
author | antirez <antirez@gmail.com> | 2020-01-10 13:02:45 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2020-03-05 16:28:19 +0100 |
commit | d90f599b4d94ee77ad651b5233032f147720c1e6 (patch) | |
tree | f3c48d6b63451dc04fcf2642e656f2e2a292e889 | |
parent | 8ee3bddfc7792a8805a9da9eab9bba848a2b066b (diff) | |
download | redis-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.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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; } } |