From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 76C90A034F for ; Wed, 11 Aug 2021 11:46:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 41F8D40040; Wed, 11 Aug 2021 11:46:28 +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 9403740040 for ; Wed, 11 Aug 2021 11:46:26 +0200 (CEST) Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (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 597CE3F070 for ; Wed, 11 Aug 2021 09:46:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1628675186; bh=tnCENTFaDxlIXdVS7LyajRKH/24BE0mIcYM2APy87ow=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Dn6oqBfBI86IBz8n17DsukeCsOlR2bUDxwUCX9Z76TWwlMvKH5mglh5hiM90k+o3Y pbjPhsDWTX+rQhEjRwAd9Ojwv+v4gLgf6cUm0whUhYrCTixg1nMKXo6rzWzSq6TeKv CxwfDhYR6I5KH3/ZXpnnWxluPQwJEvXqz7pYmPV2dP8oRQz7iXLmW6AZaqHnIsqp4T 6KTVLnEn+7iCsQh+hz6JqNbP8Iacjvi5kdJhjrCN57TORlBXdTVDlCaOETstg2Tr/T jV9nHm/tWbpxVKEZWJX9AJ1QtJlwDd233zc14q7JlpUNv6o9H3D/BrL/mOPY49Zcew GflPSvo8i0omw== Received: by mail-qk1-f198.google.com with SMTP id p16-20020a05620a22b0b02903ca40d6cc81so907617qkh.13 for ; Wed, 11 Aug 2021 02:46:26 -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:content-transfer-encoding; bh=tnCENTFaDxlIXdVS7LyajRKH/24BE0mIcYM2APy87ow=; b=LjiPAFZ089J2vB+IhWtPQ/jqscGx62ius3fpIIeo2+X/sFiuw5ZxFB0YqfGX5d9JBh i+qpF+EH9aBxGxJrzYx4DSbADzPdbyH38no6x7c0GfL1qtxVCFkRw4/ajhskbEZEv3Et MZKAK9Fzhuo2NSTh9kN6sxq2c9j79nq2T0702L+Gv2XPuSoC4L7h7M96xEKuNeQh5z1z PT3PhdbypVl1m0vNESEO3WZmUkfJBbChFvNf3SuNeCjNznGIPUTkl7DEXoACS69uemsh moqy5/OyNRDv18uAzCnN4cqsL8oxuPe6yPFfqgfxRJajGETOzfQGz4FYyJUO4TrjJDbB 74jA== X-Gm-Message-State: AOAM532/iMElM8k3cqfvezvvOQdQoE/BqwhZLEuuKtd8Xt3DdRNJFb5S 8tP8EWB+ocSSE0SKQ2eZrgKmfFXwrgrag8zBU3QJJ9CIxaGZlDrZZE7l+PDkiYV905cQCmOivHU VuqrZ64fvcOgjzSdpBqEBTTKB43OqLmUebHl27ZXJ X-Received: by 2002:a05:620a:1007:: with SMTP id z7mr20210817qkj.462.1628675185403; Wed, 11 Aug 2021 02:46:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA9pc4tA14m4jOfO89fDdMAkVxQ52RC5cl6PQzFIVJi3nTM9OrcvOI1F/yDlVRcCs1Kp3PLEmblVqnd+2PL6A= X-Received: by 2002:a05:620a:1007:: with SMTP id z7mr20210806qkj.462.1628675185223; Wed, 11 Aug 2021 02:46:25 -0700 (PDT) MIME-Version: 1.0 References: <20210810173950.98785-1-ohilyard@iol.unh.edu> In-Reply-To: From: Christian Ehrhardt Date: Wed, 11 Aug 2021 11:45:59 +0200 Message-ID: To: Owen Hilyard Cc: dpdk stable , David Marchand Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-stable] [PATCH 19.11] 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" On Wed, Aug 11, 2021 at 8:43 AM Christian Ehrhardt wrote: > > On Tue, Aug 10, 2021 at 7:40 PM wrote: > > > > From: Owen Hilyard > > > > [ 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 =E2=80=98test_cmdline_socket_fn= s=E2=80=99: ../app/test/test_cmdline_lib.c:138:8: warning: assignment to =E2=80=98struc= t cmdline *=E2=80=99 from =E2=80=98int=E2=80=99 makes pointer from integer wi= thout a cast [-Wint-conversion] 138 | cl =3D cmdline_stdin_new(NULL, "prompt") !=3D NULL); | ^ ../app/test/test_cmdline_lib.c:138:51: error: expected =E2=80=98;=E2=80=99 = before =E2=80=98)=E2=80=99 token 138 | cl =3D cmdline_stdin_new(NULL, "prompt") !=3D NULL); | ^ ../app/test/test_cmdline_lib.c:138:51: error: expected statement before =E2=80=98)=E2=80=99 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 > > Reviewed-by: David Marchand > > --- > > 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)) >=3D= 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") !=3D NULL) > > + cl =3D cmdline_stdin_new(NULL, "prompt") !=3D NULL); Changed to an assignment but kept the comparison of the if =3D> failing. > > + if (cl !=3D NULL) > > goto error; > > - if (cmdline_stdin_new(&ctx, NULL) !=3D NULL) > > + cl =3D cmdline_stdin_new(&ctx, NULL); > > + if (cl !=3D 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/4c36f7b56fb4bc12b9d19c= a21db4207298afead0 But please give all of it a second look > > goto error; > > - if (cmdline_file_new(NULL, "prompt", "/dev/null") !=3D NULL) > > + cl =3D cmdline_file_new(NULL, "prompt", "/dev/null"); > > + if (cl !=3D NULL) > > goto error; > > - if (cmdline_file_new(&ctx, NULL, "/dev/null") !=3D NULL) > > + cl =3D cmdline_file_new(&ctx, NULL, "/dev/null"); > > + if (cl !=3D NULL) > > goto error; > > - if (cmdline_file_new(&ctx, "prompt", NULL) !=3D NULL) > > + cl =3D cmdline_file_new(&ctx, "prompt", NULL); > > + if (cl !=3D NULL) > > goto error; > > - if (cmdline_file_new(&ctx, "prompt", "-/invalid/~/path") !=3D N= ULL) { > > + cl =3D cmdline_file_new(&ctx, "prompt", "-/invalid/~/path"); > > + if (cl !=3D NULL) { > > printf("Error: succeeded in opening invalid file for re= ading!"); > > + cmdline_free(cl); > > return -1; > > } > > - if (cmdline_file_new(&ctx, "prompt", "/dev/null") =3D=3D NULL) = { > > + cl =3D cmdline_file_new(&ctx, "prompt", "/dev/null"); > > + if (cl =3D=3D 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 =3D cmdline_new(&ctx, "test", -1, -1); > > if (tmp =3D=3D NULL) > > goto error; > > > > - if (cmdline_new(NULL, "prompt", 0, 0) !=3D NULL) > > + tmp2 =3D cmdline_new(NULL, "prompt", 0, 0); > > + if (tmp2 !=3D NULL) > > goto error; > > - if (cmdline_new(&ctx, NULL, 0, 0) !=3D NULL) > > + tmp2 =3D cmdline_new(&ctx, NULL, 0, 0); > > + if (tmp2 !=3D NULL) > > goto error; > > if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >=3D 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 --=20 Christian Ehrhardt Staff Engineer, Ubuntu Server Canonical Ltd