diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-09-09 21:58:33 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-09-09 21:58:33 +0000 |
| commit | 039dc61292de5f3ed5f46316b1940ab6bb184c3f (patch) | |
| tree | 5db04ee53a9381411a784c80c9b741f4a72f961d /lib/command.c | |
| parent | edb5b931191729695f681551190ebf77d13f3d46 (diff) | |
lib: Fix tab completions memleak, memory stats corruption
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/command.c b/lib/command.c index f97e37e8c6..e67007ae2f 100644 --- a/lib/command.c +++ b/lib/command.c @@ -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; |
