]> git.saurik.com Git - redis.git/blobdiff - src/sds.c
Free the sds in addReplySds when it cannot be added to the reply
[redis.git] / src / sds.c
index 4878f8a625714ce4190555953954f5e24fbcd2af..a0ebb0591ee17ac9c181a5a89db1a920753227b0 100644 (file)
--- a/src/sds.c
+++ b/src/sds.c
@@ -407,7 +407,7 @@ sds *sdssplitargs(char *line, int *argc) {
         if (*p) {
             /* get a token */
             int inq=0; /* set to 1 if we are in "quotes" */
-            int done = 0;
+            int done=0;
 
             if (current == NULL) current = sdsempty();
             while(!done) {
@@ -426,7 +426,12 @@ sds *sdssplitargs(char *line, int *argc) {
                         }
                         current = sdscatlen(current,&c,1);
                     } else if (*p == '"') {
-                        done = 1;
+                        /* closing quote must be followed by a space */
+                        if (*(p+1) && !isspace(*(p+1))) goto err;
+                        done=1;
+                    } else if (!*p) {
+                        /* unterminated quotes */
+                        goto err;
                     } else {
                         current = sdscatlen(current,p,1);
                     }
@@ -458,4 +463,11 @@ sds *sdssplitargs(char *line, int *argc) {
             return vector;
         }
     }
+
+err:
+    while((*argc)--)
+        sdsfree(vector[*argc]);
+    zfree(vector);
+    if (current) sdsfree(current);
+    return NULL;
 }