From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 69E74A0C52
	for <public@inbox.dpdk.org>; Mon, 16 Aug 2021 10:59:50 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 3FDB14003C;
	Mon, 16 Aug 2021 10:59:50 +0200 (CEST)
Received: from smtp-relay-canonical-1.canonical.com
 (smtp-relay-canonical-1.canonical.com [185.125.188.121])
 by mails.dpdk.org (Postfix) with ESMTP id 977EA4003C
 for <stable@dpdk.org>; Mon, 16 Aug 2021 10:59:49 +0200 (CEST)
Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com
 [209.85.222.197])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPS id 9ECE23FE71
 for <stable@dpdk.org>; Mon, 16 Aug 2021 08:59:48 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com;
 s=20210705; t=1629104388;
 bh=IVJnTs294g5VCR3ohyfjygYXTkyvxPS3i15nKZTjvqA=;
 h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
 To:Cc:Content-Type;
 b=k+ItJc1URPBTCFxHmHfgvzkYKw+/09WVYC8P/EqLlOE8Khev/G4U5DLIitoEIDp9h
 0w/BsIASDgUG83TAJ9U57OsjLeUEXo9fwq6w2yJMZKIWP7TKQsn5EYUSPqkLFgD71a
 G6BbnnfFZwaq6ZERrPyiraGtcB2gpTaZQ4vB/38iCATQ8gLNleVjWECMCObDJS/8pl
 uy8Yoh6K+acb+13EaJhFAAiGCUQmmNN3Oze53hPRdG3VhFsFFMbuhlz4LLSZ12WzVG
 a4z1aWf6tHawRQvvL8B9TMy4jIscwz3gBmApCAN4iPyT20931nB9YNhOw4ry2oLK9N
 NqD1qE8nzP9OA==
Received: by mail-qk1-f197.google.com with SMTP id
 w2-20020a3794020000b02903b54f40b442so12941035qkd.0
 for <stable@dpdk.org>; Mon, 16 Aug 2021 01:59:48 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=IVJnTs294g5VCR3ohyfjygYXTkyvxPS3i15nKZTjvqA=;
 b=qNAW14wz2M/EhRLBTXadHLlCcdy6IhVavSvIXnbgAij8qsc90L/jkAWorQ9owjERVb
 8l+fmJvXeQ7tIDQF0Df2LXNdwPKmSmlvFbfn9o9mKnGlmgwPDzzmZyV6bbmPEuvbqB6E
 BcoHqxDcDH5Ns160tDrlWQSMc1dul37xOmbYMqXn4gwm4UPQfg2cZRzREsYm9dnIhvgj
 z9QBWgHeyaHyAI+R+7DVSoHzltsB3lBfwjxXBt47+swkJwRBTU91Iw7rvAiTHYTnd7IU
 cjcxIm4WIe0k/aaH/N0CuML7C5/F9M5NVtgIWFVosJ1b0+OsfPVPoXaLIztM/Rr/VjQY
 v0sg==
X-Gm-Message-State: AOAM532FK3LhlbNXcSix1pSfTeAzgvMoXH/VYGU+MXu0KLn9pu8nZ0FM
 XS1cazB0FBKudohYNvwqCV65/jPCxLR6K799stXWbkXw9PvTfSLbqMTCwEkLRV2FjIz0/jgHgtu
 MygcYmE9rbRu5JSMwg+rpQFkRPBrwJyWeZwqYl3fL
X-Received: by 2002:a37:bfc6:: with SMTP id p189mr8090483qkf.33.1629104387716; 
 Mon, 16 Aug 2021 01:59:47 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJwvP6L+TGsHZwNGAwoTgGHraIPnGR5ZaoSwCElyP+szS4KM2MU6PHXQEEDqseMYnIpnZJ6f49HeVfUGYqjWHPI=
X-Received: by 2002:a37:bfc6:: with SMTP id p189mr8090480qkf.33.1629104387539; 
 Mon, 16 Aug 2021 01:59:47 -0700 (PDT)
MIME-Version: 1.0
References: <CAHx6DYAmdkXEfTTgT0V4RAtJ4kJfmUvLfNvaGAENuoFo0TPh=g@mail.gmail.com>
 <20210812194411.167539-1-ohilyard@iol.unh.edu>
In-Reply-To: <20210812194411.167539-1-ohilyard@iol.unh.edu>
From: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Date: Mon, 16 Aug 2021 10:59:21 +0200
Message-ID: <CAATJJ0Lxjm8uaF1YWPk9ejW+U3=SLwWLwBx=7h2TUrGAjXORKg@mail.gmail.com>
To: Owen Hilyard <ohilyard@iol.unh.edu>
Cc: dpdk stable <stable@dpdk.org>, David Marchand <david.marchand@redhat.com>
Content-Type: text/plain; charset="UTF-8"
Subject: Re: [dpdk-stable] [PATCH] tests/cmdline: fix memory leaks
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org
Sender: "stable" <stable-bounces@dpdk.org>

On Thu, Aug 12, 2021 at 9:44 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.
>
> 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 | 47 +++++++++++++++++++++++++++----------
>  1 file changed, 34 insertions(+), 13 deletions(-)
>
> diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c
> index a856a9713..7d9009408 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");
> +       if (cl != NULL)
>                 goto error;
> -       if (cmdline_stdin_new(&ctx, NULL) != NULL)
> +    cl = cmdline_stdin_new(&ctx, NULL);
> +       if (cl != NULL)
>                 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,20 @@ static int
>  test_cmdline_fns(void)
>  {
>         cmdline_parse_ctx_t ctx;
> -       struct cmdline cl, *tmp;
> +    struct cmdline cl, *tmp, *tmp2;

Hi,
this still has plenty of whitespace damage converting tabs to spaces
all over the patch.

I've downloaded the raw message again as I wondered if it might be me.
But I clearly see tabs removed and spaces added.

>         memset(&ctx, 0, sizeof(ctx));
>         tmp = cmdline_new(&ctx, "test", -1, -1);
> -       if (tmp == NULL)
> +       if (tmp == NULL) {
> +               tmp2 = 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 +219,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