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 F3012A0C47 for ; Tue, 10 Aug 2021 19:40:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C440F4014F; Tue, 10 Aug 2021 19:40:03 +0200 (CEST) Received: from mail-ot1-f98.google.com (mail-ot1-f98.google.com [209.85.210.98]) by mails.dpdk.org (Postfix) with ESMTP id 186B34014F for ; Tue, 10 Aug 2021 19:40:03 +0200 (CEST) Received: by mail-ot1-f98.google.com with SMTP id 61-20020a9d0d430000b02903eabfc221a9so82207oti.0 for ; Tue, 10 Aug 2021 10:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MGgaKO9cicBLnuK707Ib9fsWF9MNQmpIiEM4+nsa//0=; b=OlOKoyUaxHzK60/MjJHBjAUBP3CB6MN33xIgSMkQE6xBXIUEfZfXD8CLduqokGF8gC QeEJAjj/myJsIbaUhWP5EDIkCBVHD0NaJQ5XdR7VP1/mUTSTODE1tgC6mVrGBzaTDnGJ 2GwyR9a9mmASFCTqoL/JwsxMfXdfOyyYr6mI8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MGgaKO9cicBLnuK707Ib9fsWF9MNQmpIiEM4+nsa//0=; b=qsODtW5jrMSLVikU7KA9uyQyZ26VeV2DSoCsJ5koIQeuTlNxTMU3S0P5/nJ7H6cac/ ejpTmGkzxGDKabP20hjdno5A9iKVRpOnPlAZlFQY9YvRRrObVR/uYhA/ZitLUoo/c+nh p6beFbUzyPJSw0IAuIHEWL+leD/nrgPAf5zLiG3xb1fdRzQ5UFCUGsrg2oq/CDqL0myv KUdE9rIDEai15eJRO38fzIZ7/1sCLb1OfVbA1DoeAlPE3sc0xPGL6y5/d3mRvE/anxLn ef2RLaMtCfEUENNlvf+nqybgQWMvy/znL3tRfPsTO7S6f+e6r7FK0ihLrIaJ46vtzOwq DPMA== X-Gm-Message-State: AOAM533+PO/E77aWsYMXh3zjOSIG5Jp+XW4+LjLjxxHyVlRUi1+mkOCT XqNKdksg4lRlg3wS7wfQoEWilSWxbfm+sBQy9kV5kVsTXFFIN9znuiQ1aHZIUMnQIg== X-Google-Smtp-Source: ABdhPJxteENOMKJrR5dcLhWCOMbCz1EU3YIgbT/R7pLjPrWYoikBaXV4bEMAMcUDvtPNmpcNn35A3yRblCLw X-Received: by 2002:a9d:4817:: with SMTP id c23mr20750367otf.98.1628617202302; Tue, 10 Aug 2021 10:40:02 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id a2sm3699359otv.6.2021.08.10.10.40.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 10:40:02 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1220:8503:7da1:f94b:932]) by postal.iol.unh.edu (Postfix) with ESMTP id B961F605248B; Tue, 10 Aug 2021 13:40:01 -0400 (EDT) From: ohilyard@iol.unh.edu To: stable@dpdk.org Cc: christian.ehrhardt@canonical.com, Owen Hilyard , David Marchand Date: Tue, 10 Aug 2021 13:39:51 -0400 Message-Id: <20210810173950.98785-1-ohilyard@iol.unh.edu> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [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" From: Owen Hilyard [ 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 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)) >= 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); + 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,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