From: Christian Ehrhardt <christian.ehrhardt@canonical.com>
To: Owen Hilyard <ohilyard@iol.unh.edu>
Cc: dpdk stable <stable@dpdk.org>,
David Marchand <david.marchand@redhat.com>
Subject: Re: [dpdk-stable] [PATCH 19.11] tests/cmdline: fix memory leaks
Date: Wed, 11 Aug 2021 13:17:38 +0200 [thread overview]
Message-ID: <CAATJJ0K3Wvikyp1hB8SfUznu1kHPAk9a6f1BgLce5Kg_=YCeYQ@mail.gmail.com> (raw)
In-Reply-To: <CAATJJ0+feE66sGPQ_0mvDmrZg-yuzGUbDqMSS2k96G_htF_zFw@mail.gmail.com>
On Wed, Aug 11, 2021 at 11:45 AM Christian Ehrhardt
<christian.ehrhardt@canonical.com> wrote:
>
> On Wed, Aug 11, 2021 at 8:43 AM Christian Ehrhardt
> <christian.ehrhardt@canonical.com> wrote:
> >
> > On Tue, Aug 10, 2021 at 7:40 PM <ohilyard@iol.unh.edu> wrote:
> > >
> > > From: Owen Hilyard <ohilyard@iol.unh.edu>
> > >
> > > [ upstream commit ca7204b921c2f328ab1222772af40922970e7c4b ]
> > >
> > > Fixes for a few memory leaks in the cmdline_autotest unit test.
> >
> > Thank you for the backport - applied to the preliminary 19.11 branch
> > for 19.11.10
>
> Actually this causes
> ../app/test/test_cmdline_lib.c: In function ‘test_cmdline_socket_fns’:
> ../app/test/test_cmdline_lib.c:138:8: warning: assignment to ‘struct
> cmdline *’ from ‘int’ makes pointer from integer without a cast
> [-Wint-conversion]
> 138 | cl = cmdline_stdin_new(NULL, "prompt") != NULL);
> | ^
> ../app/test/test_cmdline_lib.c:138:51: error: expected ‘;’ before ‘)’ token
> 138 | cl = cmdline_stdin_new(NULL, "prompt") != NULL);
> | ^
> ../app/test/test_cmdline_lib.c:138:51: error: expected statement
> before ‘)’ token
>
> It has various issues, see below:
>
> > > All of the leaks were related to not freeing the commandline struct
> > > after testing had completed.
> > >
> > > Fixes: dbb860e03e ("cmdline: tests")
> > >
> > > Signed-off-by: Owen Hilyard <ohilyard@iol.unh.edu>
> > > Reviewed-by: David Marchand <david.marchand@redhat.com>
> > > ---
> > > app/test/test_cmdline_lib.c | 43 ++++++++++++++++++++++++++-----------
> > > 1 file changed, 31 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c
> > > index a856a9713..c7ada9ddd 100644
> > > --- a/app/test/test_cmdline_lib.c
> > > +++ b/app/test/test_cmdline_lib.c
> > > @@ -62,10 +62,12 @@ test_cmdline_parse_fns(void)
> > > if (cmdline_complete(&cl, "buffer", &i, NULL, sizeof(dst)) >= 0)
> > > goto error;
> > >
> > > + cmdline_free(&cl);
> > > return 0;
> > >
> > > error:
> > > printf("Error: function accepted null parameter!\n");
> > > + cmdline_free(&cl);
> > > return -1;
> > > }
> > >
> > > @@ -131,32 +133,43 @@ static int
> > > test_cmdline_socket_fns(void)
> > > {
> > > cmdline_parse_ctx_t ctx;
> > > + struct cmdline* cl;
> > >
> > > - if (cmdline_stdin_new(NULL, "prompt") != NULL)
> > > + cl = cmdline_stdin_new(NULL, "prompt") != NULL);
>
> Changed to an assignment but kept the comparison of the if => failing.
>
> > > + if (cl != NULL)
> > > goto error;
> > > - if (cmdline_stdin_new(&ctx, NULL) != NULL)
> > > + cl = cmdline_stdin_new(&ctx, NULL);
> > > + if (cl != NULL)
>
> ^^ all those add whitespace damage replacing a tab with spaces
>
>
> I have fixed all those into
> https://github.com/cpaelzer/dpdk-stable-queue/commit/4c36f7b56fb4bc12b9d19ca21db4207298afead0
Even with that if fails like
[ 1044s] ../app/test/test_cmdline_lib.c: In function ‘test_cmdline_fns’:
[ 1044s] ../app/test/test_cmdline_lib.c:227:2: error: ‘tmp2’ may be
used uninitialized in this function [-Werror=maybe-uninitialized]
[ 1044s] 227 | cmdline_free(tmp2);
[ 1044s] | ^~~~~~~~~~~~~~~~~~
I'll de-queue it from 19.11 for now and would appreciate it if you
could check it more thoroughly than I did.
> But please give all of it a second look
>
> > > goto error;
> > > - if (cmdline_file_new(NULL, "prompt", "/dev/null") != NULL)
> > > + cl = cmdline_file_new(NULL, "prompt", "/dev/null");
> > > + if (cl != NULL)
> > > goto error;
> > > - if (cmdline_file_new(&ctx, NULL, "/dev/null") != NULL)
> > > + cl = cmdline_file_new(&ctx, NULL, "/dev/null");
> > > + if (cl != NULL)
> > > goto error;
> > > - if (cmdline_file_new(&ctx, "prompt", NULL) != NULL)
> > > + cl = cmdline_file_new(&ctx, "prompt", NULL);
> > > + if (cl != NULL)
> > > goto error;
> > > - if (cmdline_file_new(&ctx, "prompt", "-/invalid/~/path") != NULL) {
> > > + cl = cmdline_file_new(&ctx, "prompt", "-/invalid/~/path");
> > > + if (cl != NULL) {
> > > printf("Error: succeeded in opening invalid file for reading!");
> > > + cmdline_free(cl);
> > > return -1;
> > > }
> > > - if (cmdline_file_new(&ctx, "prompt", "/dev/null") == NULL) {
> > > + cl = cmdline_file_new(&ctx, "prompt", "/dev/null");
> > > + if (cl == NULL) {
> > > printf("Error: failed to open /dev/null for reading!");
> > > + cmdline_free(cl);
> > > return -1;
> > > }
> > >
> > > /* void functions */
> > > cmdline_stdin_exit(NULL);
> > > -
> > > + cmdline_free(cl);
> > > return 0;
> > > error:
> > > printf("Error: function accepted null parameter!\n");
> > > + cmdline_free(cl);
> > > return -1;
> > > }
> > >
> > > @@ -164,16 +177,18 @@ static int
> > > test_cmdline_fns(void)
> > > {
> > > cmdline_parse_ctx_t ctx;
> > > - struct cmdline cl, *tmp;
> > > + struct cmdline cl, *tmp, *tmp2;
> > >
> > > memset(&ctx, 0, sizeof(ctx));
> > > tmp = cmdline_new(&ctx, "test", -1, -1);
> > > if (tmp == NULL)
> > > goto error;
> > >
> > > - if (cmdline_new(NULL, "prompt", 0, 0) != NULL)
> > > + tmp2 = cmdline_new(NULL, "prompt", 0, 0);
> > > + if (tmp2 != NULL)
> > > goto error;
> > > - if (cmdline_new(&ctx, NULL, 0, 0) != NULL)
> > > + tmp2 = cmdline_new(&ctx, NULL, 0, 0);
> > > + if (tmp2 != NULL)
> > > goto error;
> > > if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >= 0)
> > > goto error;
> > > @@ -202,14 +217,18 @@ test_cmdline_fns(void)
> > > if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch;
> > >
> > > cmdline_free(tmp);
> > > -
> > > + cmdline_free(tmp2);
> > > return 0;
> > >
> > > error:
> > > printf("Error: function accepted null parameter!\n");
> > > + cmdline_free(tmp);
> > > + cmdline_free(tmp2);
> > > return -1;
> > > mismatch:
> > > printf("Error: data changed!\n");
> > > + cmdline_free(tmp);
> > > + cmdline_free(tmp2);
> > > return -1;
> > > }
> > >
> > > --
> > > 2.30.2
> > >
> >
> >
> > --
> > Christian Ehrhardt
> > Staff Engineer, Ubuntu Server
> > Canonical Ltd
>
>
>
> --
> Christian Ehrhardt
> Staff Engineer, Ubuntu Server
> Canonical Ltd
--
Christian Ehrhardt
Staff Engineer, Ubuntu Server
Canonical Ltd
next prev parent reply other threads:[~2021-08-11 11:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-10 17:39 ohilyard
2021-08-11 6:43 ` Christian Ehrhardt
2021-08-11 9:45 ` Christian Ehrhardt
2021-08-11 11:17 ` Christian Ehrhardt [this message]
2021-08-11 12:55 ` Owen Hilyard
2021-08-12 19:44 ` [dpdk-stable] [PATCH] " ohilyard
2021-08-16 8:59 ` Christian Ehrhardt
2021-08-16 12:05 ` ohilyard
2021-08-16 12:06 ` Owen Hilyard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAATJJ0K3Wvikyp1hB8SfUznu1kHPAk9a6f1BgLce5Kg_=YCeYQ@mail.gmail.com' \
--to=christian.ehrhardt@canonical.com \
--cc=david.marchand@redhat.com \
--cc=ohilyard@iol.unh.edu \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).