]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Fix tab completions memleak, memory stats corruption
authorQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 9 Sep 2016 21:58:33 +0000 (21:58 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 9 Sep 2016 21:58:33 +0000 (21:58 +0000)
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command.c
vtysh/vtysh.c

index f97e37e8c645636be3275a6f6a626f99f62e8a6f..e67007ae2f95236bf099e89f0e8255d3b5380c49 100644 (file)
@@ -2416,8 +2416,11 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib
   /* Only one matched */
   if (vector_slot (matchvec, 1) == NULL)
     {
-      match_str = (char **) matchvec->index;
-      vector_only_wrapper_free (matchvec);
+      size_t index_size = matchvec->alloced * sizeof (void *);
+      match_str = XMALLOC (MTYPE_TMP, index_size);
+      memcpy (match_str, matchvec->index, index_size);
+      vector_free (matchvec);
+
       *status = CMD_COMPLETE_FULL_MATCH;
       return match_str;
     }
@@ -2459,8 +2462,11 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib
              /* Make new matchvec. */
              matchvec = vector_init (INIT_MATCHVEC_SIZE);
              vector_set (matchvec, lcdstr);
-             match_str = (char **) matchvec->index;
-             vector_only_wrapper_free (matchvec);
+
+              size_t index_size = matchvec->alloced * sizeof (void *);
+              match_str = XMALLOC (MTYPE_TMP, index_size);
+              memcpy (match_str, matchvec->index, index_size);
+              vector_free (matchvec);
 
              *status = CMD_COMPLETE_MATCH;
              return match_str;
index 2436c6182dc1c629ade6fa614e75479a08e961e4..d01a1bcebbd9428d1f1e7c1387d4312d2ae94f92 100644 (file)
@@ -885,7 +885,10 @@ command_generator (const char *text, int state)
       if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
        vector_set (vline, NULL);
 
+      if (matched)
+        XFREE (MTYPE_TMP, matched);
       matched = cmd_complete_command (vline, vty, &complete_status);
+      cmd_free_strvec (vline);
     }
 
   if (matched && matched[index])