Revert "lib: Fix tab completions memleak, memory stats corruption"

This reverts commit 039dc61292.

The patch actually made the situation worse since the return value from
cmd_complete_command_real() was now inconsistently allocated from
different memory stat pools.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2017-03-09 19:23:00 +01:00
parent 72c62cb803
commit 4dcee34bd6

View File

@ -2445,11 +2445,8 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib
/* Only one matched */ /* Only one matched */
if (vector_slot (matchvec, 1) == NULL) if (vector_slot (matchvec, 1) == NULL)
{ {
size_t index_size = matchvec->alloced * sizeof (void *); match_str = (char **) matchvec->index;
match_str = XMALLOC (MTYPE_TMP, index_size); vector_only_wrapper_free (matchvec);
memcpy (match_str, matchvec->index, index_size);
vector_free (matchvec);
*status = CMD_COMPLETE_FULL_MATCH; *status = CMD_COMPLETE_FULL_MATCH;
return match_str; return match_str;
} }
@ -2491,11 +2488,8 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib
/* Make new matchvec. */ /* Make new matchvec. */
matchvec = vector_init (INIT_MATCHVEC_SIZE); matchvec = vector_init (INIT_MATCHVEC_SIZE);
vector_set (matchvec, lcdstr); vector_set (matchvec, lcdstr);
match_str = (char **) matchvec->index;
size_t index_size = matchvec->alloced * sizeof (void *); vector_only_wrapper_free (matchvec);
match_str = XMALLOC (MTYPE_TMP, index_size);
memcpy (match_str, matchvec->index, index_size);
vector_free (matchvec);
*status = CMD_COMPLETE_MATCH; *status = CMD_COMPLETE_MATCH;
return match_str; return match_str;