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 D0672A0C57 for ; Thu, 12 Aug 2021 21:44:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ABABF40042; Thu, 12 Aug 2021 21:44:31 +0200 (CEST) Received: from mail-oi1-f226.google.com (mail-oi1-f226.google.com [209.85.167.226]) by mails.dpdk.org (Postfix) with ESMTP id E3F2540042 for ; Thu, 12 Aug 2021 21:44:29 +0200 (CEST) Received: by mail-oi1-f226.google.com with SMTP id w6so12061633oiv.11 for ; Thu, 12 Aug 2021 12:44:29 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=YDXSsMw/Nnp5HAzL0e7UVplKiNMWOCw8b02UDz5biT8=; b=dnX9zfgfEw4kSEHjlTX2bSWKRX14WJkfPPAujWv2AuzJeBFiE6Wi5iAzR8tul9vhZw R93RnmJGl3AnfLwoBrDoTijukHH5fj3NdjqqzfCjQHRf3tFQwliXYbmq3LZ+u/tiK354 NivXC0Tqk2Dx+vuzs20i/xQP+EbF5tnbNUhR0= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=YDXSsMw/Nnp5HAzL0e7UVplKiNMWOCw8b02UDz5biT8=; b=VIF1OcCM7LuAe8qTamTUL+NL9Cmi/wpqtYqzmP460b+7BCwTnaGscTYW/Gw7jBe2JV k8mbJ/Fbhu7jsRTyRQaBxAJGHetgDisRoaHclD2QO6buSPAPBPXcmI0ttNFkSjrOjH2r dUlIuijMcOCa0MRnuARdL16wedBE4mP5j81r9bzyEiAMvGEVulyKx59lrqdfPChZaR8n 2COVkfHvQkv4y63wzj1CQYmFpbP6LgyxU+RG4A7uk3a9CKRIZrGUUYMOmeQcmZxTFMtU 7wdmSqnwLkfPtJBjW+7c422E0hMwK6m8T1lBj7+gisdfMyVdxpcD2YC1sWryN5UrG4On aDDQ== X-Gm-Message-State: AOAM532JeBSWbPVUPfiTrHQqgRnnPLghVQ5GfP7LqdUXb6CpDx9mwHsf z9si9+LfI/4FJ0NtEqdYgPXH2e++WeXMsN/J2VKd4GQLHN8DDvR107XB9m3uzt8GvA== X-Google-Smtp-Source: ABdhPJx5yVW+IiYOpYA8J3OmyhvsHUWDsQhzEIC3AJE5A9hOHAVSyii3mC6HBK87aGJmSoXcrC2M46+fAPMk X-Received: by 2002:a05:6808:1494:: with SMTP id e20mr4595044oiw.111.1628797469324; Thu, 12 Aug 2021 12:44:29 -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 o7sm814785oou.21.2021.08.12.12.44.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Aug 2021 12:44:29 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::105d]) by postal.iol.unh.edu (Postfix) with ESMTP id 6D2AA605248B; Thu, 12 Aug 2021 15:44:28 -0400 (EDT) From: ohilyard@iol.unh.edu To: stable@dpdk.org Cc: christian.ehrhardt@canonical.com, Owen Hilyard , David Marchand Date: Thu, 12 Aug 2021 15:44:12 -0400 Message-Id: <20210812194411.167539-1-ohilyard@iol.unh.edu> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [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 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 | 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; 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