dparrish / libcli

Libcli provides a shared library for including a Cisco-like command-line interface into other software. It's a telnet interface which supports command-line editing, history, authentication and callbacks for a user-definable function tree.
https://dparrish.com/link/libcli
GNU Lesser General Public License v2.1
289 stars 144 forks source link

Constant Memory leak found at this trace #22

Open kaprakashr opened 8 years ago

kaprakashr commented 8 years ago

Constant Memory leak found at this trace. Every time we try to search in CLI,

==7781== LEAK SUMMARY:

==7781== definitely lost: 114 bytes in 20 blocks ==7781== 114 bytes in 20 blocks are definitely lost in loss record 85 of 90

Trace

==7781== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==7781== by 0x4E3971F: cli_parse_line.constprop.5 (libcli.c:670) ==7781== by 0x4E3CD13: cli_loop (libcli.c:989) ==7781== by 0x4010A1: main (in /home/kalyan/cloutra/src/cli/a.out)

kaprakashr commented 8 years ago

Function to be fixed

cli_parse_inline

Snap

while (nwords < max_words - 1)
{
    if (!*p || *p == inquote || (word_start && !inquote && (isspace(*p) || *p == '|')))
    {
        if (word_start)
        {
            int len = p - word_start;

            memcpy(words[nwords] = malloc(len + 1), word_start, len); <== later, this is not freed properly
            words[nwords++][len] = 0;
        }