summaryrefslogtreecommitdiff
path: root/src/redis-cli.c
diff options
context:
space:
mode:
authorWuYunlong <xzsyeb@126.com>2021-02-09 18:36:09 +0800
committerGitHub <noreply@github.com>2021-02-09 12:36:09 +0200
commit203f357c32f82b0e10c3e55721fccd07bc2bed39 (patch)
tree01aab0b8d7cc2794a2daf4937b599258ae45b8fe /src/redis-cli.c
parent8f9958dc24fa5992d3d10f6b9caf999e1beee4e5 (diff)
downloadredis-203f357c32f82b0e10c3e55721fccd07bc2bed39.tar.gz
Cleanup in redis-cli and tests: release memory on exit, change dup test name (#8475)
1. Rename 18-cluster-nodes-slots.tcl to 19-cluster-nodes-slots.tcl. it was conflicting with another test prefixed by 18 2. Release memory on exit in redis-cli.c. 3. Fix freeConvertedSds indentation.
Diffstat (limited to 'src/redis-cli.c')
-rw-r--r--src/redis-cli.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index ab30edc75..ef1d49e3e 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -1929,13 +1929,20 @@ static int confirmWithYes(char *msg, int ignore_force) {
/* Turn the plain C strings into Sds strings */
static char **convertToSds(int count, char** args) {
- int j;
- char **sds = zmalloc(sizeof(char*)*count);
+ int j;
+ char **sds = zmalloc(sizeof(char*)*count);
- for(j = 0; j < count; j++)
- sds[j] = sdsnew(args[j]);
+ for(j = 0; j < count; j++)
+ sds[j] = sdsnew(args[j]);
- return sds;
+ return sds;
+}
+
+static void freeConvertedSds(int count, char **sds) {
+ int j;
+ for (j = 0; j < count; j++)
+ sdsfree(sds[j]);
+ zfree(sds);
}
static int issueCommandRepeat(int argc, char **argv, long repeat) {
@@ -2168,13 +2175,17 @@ static void repl(void) {
static int noninteractive(int argc, char **argv) {
int retval = 0;
+
+ argv = convertToSds(argc, argv);
if (config.stdinarg) {
argv = zrealloc(argv, (argc+1)*sizeof(char*));
argv[argc] = readArgFromStdin();
retval = issueCommand(argc+1, argv);
+ sdsfree(argv[argc]);
} else {
retval = issueCommand(argc, argv);
}
+ freeConvertedSds(argc, argv);
return retval;
}
@@ -8331,6 +8342,6 @@ int main(int argc, char **argv) {
if (config.eval) {
return evalMode(argc,argv);
} else {
- return noninteractive(argc,convertToSds(argc,argv));
+ return noninteractive(argc,argv);
}
}